X-Git-Url: https://code.grnet.gr/git/pithos/blobdiff_plain/a4c10cbcfd73fed26004cd2fe9c0665782f18297..611001c27fe1edb42b1cf3a7ddee4928df1e97a2:/tools/store?ds=sidebyside diff --git a/tools/store b/tools/store index 2fa6873..0cd55df 100755 --- a/tools/store +++ b/tools/store @@ -63,8 +63,8 @@ def class_for_cli_command(name): 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', @@ -166,7 +166,10 @@ class List(Command): 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') @@ -314,20 +317,28 @@ class PutObject(Command): 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'] @@ -409,7 +420,7 @@ class UpdateObject(Command): 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', @@ -422,12 +433,22 @@ class UpdateObject(Command): 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') @@ -446,11 +467,15 @@ class UpdateObject(Command): 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): @@ -467,7 +492,7 @@ 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 = '/' description = 'trashes an object' @@ -494,7 +519,7 @@ class TrashObject(Command): 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) @@ -510,6 +535,23 @@ class TrashObject(Command): 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 @@ -568,17 +610,14 @@ def main(): 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)