diff options
| author | Jenkins <jenkins@review.openstack.org> | 2016-08-24 23:59:34 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2016-08-24 23:59:34 +0000 |
| commit | b57044a85301ac5a5fbfb119968aee8d78b6b7bf (patch) | |
| tree | ef15ce4525ce7d572cead919841053a18d02235a /examples/copy.py | |
| parent | b1539d9c0feaaf26783e7cab3962219e036994ba (diff) | |
| parent | 4a2465fb12ff7287b62b6941fb8ae43e100adc25 (diff) | |
| download | python-swiftclient-b57044a85301ac5a5fbfb119968aee8d78b6b7bf.tar.gz | |
Merge "Add copy object method"
Diffstat (limited to 'examples/copy.py')
| -rw-r--r-- | examples/copy.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/examples/copy.py b/examples/copy.py new file mode 100644 index 0000000..e928db4 --- /dev/null +++ b/examples/copy.py @@ -0,0 +1,30 @@ +import logging + +from swiftclient.service import SwiftService, SwiftCopyObject, SwiftError + +logging.basicConfig(level=logging.ERROR) +logging.getLogger("requests").setLevel(logging.CRITICAL) +logging.getLogger("swiftclient").setLevel(logging.CRITICAL) +logger = logging.getLogger(__name__) + +with SwiftService() as swift: + try: + obj = SwiftCopyObject("c", {"Destination": "/cont/d"}) + for i in swift.copy( + "cont", ["a", "b", obj], + {"meta": ["foo:bar"], "Destination": "/cc"}): + if i["success"]: + if i["action"] == "copy_object": + print( + "object %s copied from /%s/%s" % + (i["destination"], i["container"], i["object"]) + ) + if i["action"] == "create_container": + print( + "container %s created" % i["container"] + ) + else: + if "error" in i and isinstance(i["error"], Exception): + raise i["error"] + except SwiftError as e: + logger.error(e.value) |
