summaryrefslogtreecommitdiff
path: root/examples/stat.py
diff options
context:
space:
mode:
Diffstat (limited to 'examples/stat.py')
-rw-r--r--examples/stat.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/examples/stat.py b/examples/stat.py
new file mode 100644
index 0000000..0905d1b
--- /dev/null
+++ b/examples/stat.py
@@ -0,0 +1,25 @@
+import logging
+import pprint
+
+from swiftclient.service import SwiftService
+from sys import argv
+
+logging.basicConfig(level=logging.ERROR)
+logging.getLogger("requests").setLevel(logging.CRITICAL)
+logging.getLogger("swiftclient").setLevel(logging.CRITICAL)
+logger = logging.getLogger(__name__)
+
+_opts = {'object_dd_threads': 20}
+with SwiftService(options=_opts) as swift:
+ container = argv[1]
+ objects = argv[2:]
+ header_data = {}
+ stats_it = swift.stat(container=container, objects=objects)
+ for stat_res in stats_it:
+ if stat_res['success']:
+ header_data[stat_res['object']] = stat_res['headers']
+ else:
+ logger.error(
+ 'Failed to retrieve stats for %s' % stat_res['object']
+ )
+ pprint.pprint(header_data)