summaryrefslogtreecommitdiff
path: root/examples/stat.py
diff options
context:
space:
mode:
authorJoel Wright <joel.wright@sohonet.com>2016-03-03 17:22:33 +0000
committerJoel Wright <joel.wright@sohonet.com>2016-04-29 19:21:36 +0100
commit3a5a25fe981817ba0e550d39d6e9863fa1539588 (patch)
tree085839c930892e79142595eb2e6f8b42263cafd2 /examples/stat.py
parentf86b2d8138f5c366d0f8ab8e8cb2492d9cd07ca4 (diff)
downloadpython-swiftclient-3a5a25fe981817ba0e550d39d6e9863fa1539588.tar.gz
Add new doc structure and contents for swiftclient
As a result of the Hackathon we have produced a new documentation structure for the python-swiftclient. This patch introduces the new structure and adds the required content. The intention is to document the CLI, the SwiftService and Connection API. Importantly, we also provide guidance on important considerations when using a swift object store, such as which aspect of the python-swiftclient to use for various use cases, common authentication patterns and some useful examples. Co-Authored-By: Alexandra Settle <alexandra.settle@rackspace.com> Co-Authored-By: Mohit Motiani <mohit.motiani@intel.com> Co-Authored-By: Hisashi Osanai <osanai.hisashi@jp.fujitsu.com> Change-Id: I9eb41f8e9137efa66cead67dc264a76a3c03fbda
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)