Add full pithos+ move in client.pithos
authorStavros Sachtouris <saxtouri@admin.grnet.gr>
Thu, 23 Aug 2012 08:33:03 +0000 (11:33 +0300)
committerStavros Sachtouris <saxtouri@admin.grnet.gr>
Thu, 23 Aug 2012 08:33:03 +0000 (11:33 +0300)
kamaki/clients/pithos.py
kamaki/clients/pithos_cli.py

index 360bb6f..6d556ca 100644 (file)
@@ -895,3 +895,13 @@ class PithosClient(StorageClient):
         self.object_put(dst_object, success=201, copy_from=src_path, content_length=0,
             source_version=source_version, public=public, content_type=content_type,
             delimiter=delimiter)
+
+    def move_object(self, src_container, src_object, dst_container, dst_object=False,
+        source_version = None, public=False, content_type=None, delimiter=None):
+        self.assert_account()
+        self.container = dst_container
+        dst_object = dst_object or src_object
+        src_path = path4url(src_container, src_object)
+        self.object_put(dst_object, success=201, move_from=src_path, content_length=0,
+            source_version=source_version, public=public, content_type=content_type,
+            delimiter=delimiter)
index 8b5b35b..fb0a838 100644 (file)
@@ -339,7 +339,25 @@ class store_copy(_store_container_command):
 
 @command()
 class store_move(_store_container_command):
-    """Move an object"""
+    """Copy an object"""
+
+    def update_parser(self, parser):
+        super(store_move, self).update_parser(parser)
+        parser.add_argument('--source-version', action='store', dest='source_version', default=None,
+            help='copy specific version')
+        parser.add_argument('--public', action='store_true', dest='public', default=False,
+            help='make object publicly accessible')
+        parser.add_argument('--content-type', action='store', dest='content_type', default=None,
+            help='change object\'s content type')
+        parser.add_argument('--delimiter', action='store', dest='delimiter', default=None,
+            help=u'mass copy objects with path staring with src_object + delimiter')
+        parser.add_argument('-r', action='store_true', dest='recursive', default=False,
+            help='mass copy with delimiter /')
+
+    def getdelimiter(self):
+        if getattr(self.args, 'recursive'):
+            return '/'
+        return getattr(self.args, 'delimiter')
 
     def main(self, source_container___path, destination_container____path__):
         super(self.__class__, self).main(source_container___path, path_is_optional=False)
@@ -348,7 +366,10 @@ class store_move(_store_container_command):
             dst_cont = dst[0]
             dst_path = dst[1] if len(dst) > 1 else False
             self.client.move_object(src_container = self.container, src_object = self.path,
-                dst_container = dst_cont, dst_object = dst_path)
+                dst_container = dst_cont, dst_object = dst_path,
+                source_version=getattr(self.args, 'source_version'),
+                public=getattr(self.args, 'public'),
+                content_type=getattr(self.args,'content_type'), delimiter=self.getdelimiter())
         except ClientError as err:
             raiseCLIError(err)