summaryrefslogtreecommitdiff
path: root/swiftclient/command_helpers.py
diff options
context:
space:
mode:
authorClay Gerrard <clay.gerrard@gmail.com>2013-10-09 12:03:50 -0700
committerClay Gerrard <clay.gerrard@gmail.com>2013-10-09 14:31:47 -0700
commitd687060a44763cfe944343bc2c8b2d2d543eb26f (patch)
treecda056285723d35ac14dfd2ed1f6b0b5f5bacdc5 /swiftclient/command_helpers.py
parent0cded7cfed9c2840b8a9538b03ccb2b72065aafc (diff)
downloadpython-swiftclient-d687060a44763cfe944343bc2c8b2d2d543eb26f.tar.gz
Add verbose output to all stat commands
When you stat a container or object with the verbose flag the full path of the reousrce will be displayed with the token similarlly to how an account stat displays the auth url and token. * move some logic out of bin/swift.st_stat to test it * new module swiftclient.commnad_helpers for code you want to test * moved prt_bytes into swiftclient.utils to test it * fixed IndexError with prt_bytes on sizes >= 1024Y Change-Id: Iaaa96e0308b08c554205b0055b8a04de581fefa4
Diffstat (limited to 'swiftclient/command_helpers.py')
-rw-r--r--swiftclient/command_helpers.py91
1 files changed, 91 insertions, 0 deletions
diff --git a/swiftclient/command_helpers.py b/swiftclient/command_helpers.py
new file mode 100644
index 0000000..4e9c664
--- /dev/null
+++ b/swiftclient/command_helpers.py
@@ -0,0 +1,91 @@
+from swiftclient.utils import prt_bytes
+
+
+def stat_account(conn, options, thread_manager):
+ headers = conn.head_account()
+ if options.verbose > 1:
+ thread_manager.print_items((
+ ('StorageURL', conn.url),
+ ('Auth Token', conn.token),
+ ))
+ container_count = int(headers.get('x-account-container-count', 0))
+ object_count = prt_bytes(headers.get('x-account-object-count', 0),
+ options.human).lstrip()
+ bytes_used = prt_bytes(headers.get('x-account-bytes-used', 0),
+ options.human).lstrip()
+ thread_manager.print_items((
+ ('Account', conn.url.rsplit('/', 1)[-1]),
+ ('Containers', container_count),
+ ('Objects', object_count),
+ ('Bytes', bytes_used),
+ ))
+ thread_manager.print_headers(headers,
+ meta_prefix='x-account-meta-',
+ exclude_headers=(
+ 'content-length', 'date',
+ 'x-account-container-count',
+ 'x-account-object-count',
+ 'x-account-bytes-used'))
+
+
+def stat_container(conn, options, args, thread_manager):
+ headers = conn.head_container(args[0])
+ if options.verbose > 1:
+ path = '%s/%s' % (conn.url, args[0])
+ thread_manager.print_items((
+ ('URL', path),
+ ('Auth Token', conn.token),
+ ))
+ object_count = prt_bytes(
+ headers.get('x-container-object-count', 0),
+ options.human).lstrip()
+ bytes_used = prt_bytes(headers.get('x-container-bytes-used', 0),
+ options.human).lstrip()
+ thread_manager.print_items((
+ ('Account', conn.url.rsplit('/', 1)[-1]),
+ ('Container', args[0]),
+ ('Objects', object_count),
+ ('Bytes', bytes_used),
+ ('Read ACL', headers.get('x-container-read', '')),
+ ('Write ACL', headers.get('x-container-write', '')),
+ ('Sync To', headers.get('x-container-sync-to', '')),
+ ('Sync Key', headers.get('x-container-sync-key', '')),
+ ))
+ thread_manager.print_headers(headers,
+ meta_prefix='x-container-meta-',
+ exclude_headers=(
+ 'content-length', 'date',
+ 'x-container-object-count',
+ 'x-container-bytes-used',
+ 'x-container-read',
+ 'x-container-write',
+ 'x-container-sync-to',
+ 'x-container-sync-key'))
+
+
+def stat_object(conn, options, args, thread_manager):
+ headers = conn.head_object(args[0], args[1])
+ if options.verbose > 1:
+ path = '%s/%s/%s' % (conn.url, args[0], args[1])
+ thread_manager.print_items((
+ ('URL', path),
+ ('Auth Token', conn.token),
+ ))
+ content_length = prt_bytes(headers.get('content-length', 0),
+ options.human).lstrip()
+ thread_manager.print_items((
+ ('Account', conn.url.rsplit('/', 1)[-1]),
+ ('Container', args[0]),
+ ('Object', args[1]),
+ ('Content Type', headers.get('content-type')),
+ ('Content Length', content_length),
+ ('Last Modified', headers.get('last-modified')),
+ ('ETag', headers.get('etag')),
+ ('Manifest', headers.get('x-object-manifest')),
+ ), skip_missing=True)
+ thread_manager.print_headers(headers,
+ meta_prefix='x-object-meta-',
+ exclude_headers=(
+ 'content-type', 'content-length',
+ 'last-modified', 'etag', 'date',
+ 'x-object-manifest'))