diff options
author | Marek Kaleta <Marek.Kaleta@firma.seznam.cz> | 2016-02-15 12:14:17 +0100 |
---|---|---|
committer | Tim Burke <tim.burke@gmail.com> | 2016-08-23 14:37:11 -0700 |
commit | 4a2465fb12ff7287b62b6941fb8ae43e100adc25 (patch) | |
tree | 1b01f6d6bd044019f671fea1808e87b3646982d9 /examples/copy.py | |
parent | e05464fbfa03ee6d938c145ede111f4b1e828d58 (diff) | |
download | python-swiftclient-4a2465fb12ff7287b62b6941fb8ae43e100adc25.tar.gz |
Add copy object method
Implement copy object method in swiftclient Connection, Service and CLI.
Although COPY functionality can be accomplished with 'X-Copy-From'
header in PUT request, using copy is more convenient especially when
using copy for updating object metadata non-destructively.
Closes-Bug: 1474939
Change-Id: I1338ac411f418f4adb3d06753d044a484a7f32a4
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) |