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
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"""
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 = {}
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
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"""
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('/')
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):
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('/')
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):
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