command line client:
authorSofia Papagiannaki <papagian@gmail.com>
Fri, 9 Sep 2011 12:56:22 +0000 (15:56 +0300)
committerSofia Papagiannaki <papagian@gmail.com>
Fri, 9 Sep 2011 12:56:22 +0000 (15:56 +0300)
- remove trash/restore commands
- copy and move can change object content-type
- provide command for listing the accounts sharing objects with the user

tools/lib/client.py
tools/store

index ba8c257..0ce375f 100644 (file)
@@ -409,7 +409,7 @@ class OOS_Client(Client):
     
     def _change_obj_location(self, src_container, src_object, dst_container,
                              dst_object, remove=False, meta={}, account=None,
-                             **headers):
+                             content_type=None, **headers):
         account = account or self.account
         path = '/%s/%s/%s' % (account, dst_container, dst_object)
         headers = {} if not headers else headers
@@ -420,25 +420,29 @@ class OOS_Client(Client):
         else:
             headers['x-copy-from'] = '/%s/%s' % (src_container, src_object)
         headers['content_length'] = 0
+        if content_type:
+            headers['content_type'] = content_type 
         return self.put(path, headers=headers)
     
     def copy_object(self, src_container, src_object, dst_container, dst_object,
-                   meta={}, account=None, **headers):
+                   meta={}, account=None, content_type=None, **headers):
         """copies an object"""
         account = account or self.account
         return self._change_obj_location(src_container, src_object,
                                    dst_container, dst_object, account=account,
-                                   remove=False, meta=meta, **headers)
+                                   remove=False, meta=meta,
+                                   content_type=content_type, **headers)
     
     def move_object(self, src_container, src_object, dst_container,
                              dst_object, meta={}, account=None,
-                             **headers):
+                             content_type=None, **headers):
         """moves an object"""
         account = account or self.account
         return self._change_obj_location(src_container, src_object,
                                          dst_container, dst_object,
                                          account=account, remove=True,
-                                         meta=meta, **headers)
+                                         meta=meta, content_type=content_type,
+                                         **headers)
     
     def delete_object(self, container, object, params={}, account=None):
         """deletes an object"""
@@ -897,23 +901,9 @@ class Pithos_Client(OOS_Client):
         params = {'update':None}
         return self.post(path, headers=headers, params=params)
     
-    def _change_obj_location(self, src_container, src_object, dst_container,
-                             dst_object, remove=False,
-                             meta={}, account=None, **headers):
-        account = account or self.account
-        path = '/%s/%s/%s' % (account, dst_container, dst_object)
-        headers = {} if not headers else headers
-        for k, v in meta.items():
-            headers['x-object-meta-%s' % k] = v
-        if remove:
-            headers['x-move-from'] = '/%s/%s' % (src_container, src_object)
-        else:
-            headers['x-copy-from'] = '/%s/%s' % (src_container, src_object)
-        headers['content_length'] = 0
-        return self.put(path, headers=headers)
-    
     def copy_object(self, src_container, src_object, dst_container, dst_object,
-                    meta={}, public=False, version=None, account=None):
+                    meta={}, public=False, version=None, account=None,
+                    content_type=None):
         """copies an object"""
         account = account or self.account
         headers = {}
@@ -922,11 +912,12 @@ class Pithos_Client(OOS_Client):
             headers['x_object_version'] = version
         return OOS_Client.copy_object(self, src_container, src_object,
                                       dst_container, dst_object, meta=meta,
-                                      account=account,**headers)
+                                      account=account, content_type=content_type,
+                                      **headers)
     
     def move_object(self, src_container, src_object, dst_container,
                              dst_object, meta={}, public=False, version=None,
-                             account=None):
+                             account=None, content_type=None):
         """moves an object"""
         headers = {}
         headers['x_object_public'] = public
@@ -934,7 +925,8 @@ class Pithos_Client(OOS_Client):
             headers['x_object_version'] = version
         return OOS_Client.move_object(self, src_container, src_object,
                                       dst_container, dst_object, meta=meta,
-                                      account=account, **headers)
+                                      account=account, content_type=content_type,
+                                      **headers)
     
     def list_shared_by_others(self, limit=None, marker=None, format='text'):
         """lists other accounts that share objects to the user"""
index 75a62f4..e2afc8e 100755 (executable)
@@ -423,6 +423,9 @@ class CopyObject(Command):
         parser.add_option('--public', action='store_true',
                           dest='public', default=False,
                           help='make object publicly accessible')
+        parser.add_option('--content-type', action='store',
+                          dest='content_type', default=None,
+                          help='change object\'s content type')
     
     def execute(self, src, dst, *args):
         src_container, sep, src_object = src.partition('/')
@@ -438,8 +441,10 @@ class CopyObject(Command):
             dst_container = src_container
             dst_object = dst
         
+        args = {'content_type':self.content_type} if self.content_type else {}
         self.client.copy_object(src_container, src_object, dst_container,
-                                dst_object, meta, self.public, self.version, **meta)
+                                dst_object, meta, self.public, self.version,
+                                **args)
 
 @cli_command('set')
 class SetMeta(Command):
@@ -545,6 +550,9 @@ class MoveObject(Command):
         parser.add_option('--public', action='store_true',
                           dest='public', default=False,
                           help='make object publicly accessible')
+        parser.add_option('--content-type', action='store',
+                          dest='content_type', default=None,
+                          help='change object\'s content type')
     
     def execute(self, src, dst, *args):
         src_container, sep, src_object = src.partition('/')
@@ -559,28 +567,9 @@ class MoveObject(Command):
             key, sep, val = arg.partition('=')
             meta[key] = val
         
+        args = {'content_type':self.content_type} if self.content_type else {}
         self.client.move_object(src_container, src_object, dst_container,
-                                dst_object, meta, self.public, self.version)
-
-@cli_command('remove')
-class TrashObject(Command):
-    syntax = '<container>/<object>'
-    description = 'trash an object'
-    
-    def execute(self, src):
-        src_container, sep, src_object = src.partition('/')
-        
-        self.client.trash_object(src_container, src_object)
-
-@cli_command('restore')
-class RestoreObject(Command):
-    syntax = '<container>/<object>'
-    description = 'restore a trashed object'
-    
-    def execute(self, src):
-        src_container, sep, src_object = src.partition('/')
-        
-        self.client.restore_object(src_container, src_object)
+                                dst_object, meta, self.public, self.version, **args)
 
 @cli_command('unset')
 class UnsetObject(Command):
@@ -669,6 +658,28 @@ class UnpublishObject(Command):
         
         self.client.unpublish_object(src_container, src_object)
 
+@cli_command('sharing')
+class SharingObject(Command):
+    syntax = 'list users sharing objects with the user'
+    description = 'list user accounts sharing objects with the user'
+    
+    def add_options(self, parser):
+        parser.add_option('-l', action='store_true', dest='detail',
+                          default=False, help='show detailed output')
+        parser.add_option('-n', action='store', type='int', dest='limit',
+                          default=10000, help='show limited output')
+        parser.add_option('--marker', action='store', type='str',
+                          dest='marker', default=None,
+                          help='show output greater then marker')
+        
+    
+    def execute(self):
+        attrs = ['limit', 'marker']
+        args = self._build_args(attrs)
+        args['format'] = 'json' if self.detail else 'text'
+        
+        print_list(self.client.list_shared_by_others(**args))
+
 def print_usage():
     cmd = Command('', [])
     parser = cmd.parser