return _cli_commands[name]
class Command(object):
- def __init__(self, argv):
- parser = OptionParser()
+ def __init__(self, name, argv):
+ parser = OptionParser('%%prog %s [options] %s' % (name, self.syntax))
parser.add_option('--host', dest='host', metavar='HOST',
default=DEFAULT_HOST, help='use server HOST')
parser.add_option('--user', dest='user', metavar='USERNAME',
params['until'] = int(_time.mktime(t))
detail = 'json'
- l = self.client.list_objects(container, detail, params, headers)
+ #if request with meta quering disable trash filtering
+ show_trashed = True if self.meta else False
+ l = self.client.list_objects(container, detail, params, headers,
+ include_trashed = show_trashed)
print_list(l, detail=self.detail)
@cli_command('meta')
parser.add_option('--content-disposition', action='store', type='str',
dest='content-disposition', default=None,
help='provide the presentation style of the object')
- parser.add_option('--manifest', action='store', type='str',
- dest='manifest', default=None,
+ parser.add_option('-S', action='store',
+ dest='segment-size', default=False,
help='use for large file support')
+ parser.add_option('--manifest', action='store_true',
+ dest='manifest', default=None,
+ help='upload a manifestation file')
parser.add_option('--type', action='store',
dest='content-type', default=False,
help='create object with specific content type')
parser.add_option('--touch', action='store_true',
dest='touch', default=False,
help='create object with zero data')
-
+ parser.add_option('--sharing', action='store',
+ dest='sharing', default=None,
+ help='define sharing object policy')
+
def execute(self, path, srcpath='-', *args):
headers = {}
if self.manifest:
headers['X_OBJECT_MANIFEST'] = self.manifest
+ if self.sharing:
+ headers['X_OBJECT_SHARING'] = self.sharing
attrs = ['etag', 'content-encoding', 'content-disposition',
'content-type']
default=True, help='append data')
parser.add_option('--start', action='store',
dest='start',
- default=None, help='range of data to be updated')
+ default=None, help='starting offest to be updated')
parser.add_option('--range', action='store', dest='content-range',
default=None, help='range of data to be updated')
parser.add_option('--chunked', action='store_true', dest='chunked',
help='provide the presentation style of the object')
parser.add_option('--manifest', action='store', type='str',
dest='manifest', default=None,
- help='use for large file support')
+ help='use for large file support')
+ parser.add_option('--sharing', action='store',
+ dest='sharing', default=None,
+ help='define sharing object policy')
+ parser.add_option('--touch', action='store_true',
+ dest='touch', default=False,
+ help='change file properties')
+
+
def execute(self, path, srcpath='-', *args):
headers = {}
if self.manifest:
headers['X_OBJECT_MANIFEST'] = self.manifest
+ if self.sharing:
+ headers['X_OBJECT_SHARING'] = self.sharing
if getattr(self, 'start'):
headers['CONTENT_RANGE'] = 'bytes %s-/*' % getattr(self, 'start')
container, sep, object = path.partition('/')
- f = srcpath != '-' and open(srcpath) or stdin
- chunked = (self.chunked or f == stdin) and True or False
+ f = None
+ chunked = False
+ if not self.touch:
+ f = srcpath != '-' and open(srcpath) or stdin
+ chunked = (self.chunked or f == stdin) and True or False
self.client.update_object(container, object, f, chunked=chunked,
headers=headers)
- f.close()
+ if f:
+ f.close()
@cli_command('move', 'mv')
class MoveObject(Command):
self.client.move_object(src_container, src_object, dst_container,
dst_object, headers)
-@cli_command('remove', 'rm')
+@cli_command('remove')
class TrashObject(Command):
syntax = '<container>/<object>'
description = 'trashes an object'
def execute(self, path, *args):
#in case of account fix the args
- if path.find('=') != -1:
+ if len(args) == 0:
args = list(args)
args.append(path)
args = tuple(args)
else:
self.client.delete_account_metadata(meta)
+@cli_command('group')
+class SetGroup(Command):
+ syntax = 'key=val [key=val] [...]'
+ description = 'sets group account info'
+
+ def execute(self, path='', **args):
+ if len(args) == 0:
+ args = list(args)
+ args.append(path)
+ args = tuple(args)
+ path = ''
+ groups = {}
+ for arg in args:
+ key, sep, val = arg.partition('=')
+ groups[key] = val
+ self.client.set_account_groups(groups)
+
def print_usage():
cmd = Command([])
parser = cmd.parser
print_usage()
exit(1)
- cmd = cls(argv[2:])
+ cmd = cls(name, argv[2:])
try:
cmd.execute(*cmd.args)
except TypeError, e:
- print e
- cmd.parser.usage = '%%prog %s [options] %s' % (name, cmd.syntax)
cmd.parser.print_help()
exit(1)
except Fault, f:
- print f.status, f.data
status = f.status and '%s ' % f.status or ''
print '%s%s' % (status, f.data)