command line client:
[pithos] / tools / store
index 4c35262..e2afc8e 100755 (executable)
@@ -1,20 +1,52 @@
 #!/usr/bin/env python
 
+# Copyright 2011 GRNET S.A. All rights reserved.
+# 
+# Redistribution and use in source and binary forms, with or
+# without modification, are permitted provided that the following
+# conditions are met:
+# 
+#   1. Redistributions of source code must retain the above
+#      copyright notice, this list of conditions and the following
+#      disclaimer.
+# 
+#   2. Redistributions in binary form must reproduce the above
+#      copyright notice, this list of conditions and the following
+#      disclaimer in the documentation and/or other materials
+#      provided with the distribution.
+# 
+# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+# 
+# The views and conclusions contained in the software and
+# documentation are those of the authors and should not be
+# interpreted as representing official policies, either expressed
+# or implied, of GRNET S.A.
+
 from getpass import getuser
 from optparse import OptionParser
-from os.path import basename
+from os import environ
 from sys import argv, exit, stdin, stdout
-from pithos.lib.client import Client, Fault
 from datetime import datetime
+from lib.client import Pithos_Client, Fault
+from lib.util import get_user, get_auth, get_server, get_api
 
 import json
 import logging
 import types
 import re
 import time as _time
-
-DEFAULT_HOST = 'pithos.dev.grnet.gr'
-DEFAULT_API = 'v1'
+import os
 
 _cli_commands = {}
 
@@ -30,14 +62,20 @@ def class_for_cli_command(name):
     return _cli_commands[name]
 
 class Command(object):
-    def __init__(self, argv):
-        parser = OptionParser()
+    syntax = ''
+    
+    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')
+                          default=get_server(), help='use server HOST')
         parser.add_option('--user', dest='user', metavar='USERNAME',
-                          default=getuser(), help='use account USERNAME')
+                          default=get_user(),
+                          help='use account USERNAME')
+        parser.add_option('--token', dest='token', metavar='AUTH',
+                          default=get_auth(),
+                          help='use account AUTH')
         parser.add_option('--api', dest='api', metavar='API',
-                          default=DEFAULT_API, help='use api API')
+                          default=get_api(), help='use api API')
         parser.add_option('-v', action='store_true', dest='verbose',
                           default=False, help='use verbose output')
         parser.add_option('-d', action='store_true', dest='debug',
@@ -52,12 +90,18 @@ class Command(object):
                 val = getattr(options, key)
                 setattr(self, key, val)
         
-        self.client = Client(self.host, self.user, self.api, self.verbose,
+        self.client = Pithos_Client(self.host, self.token, self.user, self.api, self.verbose,
                              self.debug)
         
         self.parser = parser
         self.args = args
-        
+    
+    def _build_args(self, attrs):
+        args = {}
+        for a in [a for a in attrs if getattr(self, a)]:
+            args[a] = getattr(self, a)
+        return args
+
     def add_options(self, parser):
         pass
     
@@ -73,7 +117,7 @@ class List(Command):
         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=1000, help='show limited output')
+                          default=10000, help='show limited output')
         parser.add_option('--marker', action='store', type='str',
                           dest='marker', default=None,
                           help='show output greater then marker')
@@ -96,7 +140,7 @@ class List(Command):
                           dest='if_unmodified_since', default=None,
                           help='show output if not modified since then')
         parser.add_option('--until', action='store', dest='until',
-                          default=False, help='show metadata until that date')
+                          default=None, help='show metadata until that date')
         parser.add_option('--format', action='store', dest='format',
                           default='%d/%m/%Y', help='format to parse until date')
     
@@ -107,44 +151,50 @@ class List(Command):
             self.list_containers()
     
     def list_containers(self):
-        params = {'limit':self.limit, 'marker':self.marker}
-        headers = {'IF_MODIFIED_SINCE':self.if_modified_since,
-                   'IF_UNMODIFIED_SINCE':self.if_unmodified_since}
+        attrs = ['limit', 'marker', 'if_modified_since',
+                 'if_unmodified_since']
+        args = self._build_args(attrs)
+        args['format'] = 'json' if self.detail else 'text'
         
-        if self.until:
+        if getattr(self, 'until'):
             t = _time.strptime(self.until, self.format)
-            params['until'] = int(_time.mktime(t))
+            args['until'] = int(_time.mktime(t))
         
-        l = self.client.list_containers(self.detail, params, headers)
+        l = self.client.list_containers(**args)
         print_list(l)
     
     def list_objects(self, container):
-        params = {'limit':self.limit, 'marker':self.marker,
-                  'prefix':self.prefix, 'delimiter':self.delimiter,
-                  'path':self.path, 'meta':self.meta}
-        headers = {'IF_MODIFIED_SINCE':self.if_modified_since,
-                   'IF_UNMODIFIED_SINCE':self.if_unmodified_since}
-        container, sep, object = container.partition('/')
-        if object:
-            return
+        #prepate params
+        params = {}
+        attrs = ['limit', 'marker', 'prefix', 'delimiter', 'path',
+                 'meta', 'if_modified_since', 'if_unmodified_since']
+        args = self._build_args(attrs)
+        args['format'] = 'json' if self.detail else 'text'
         
         if self.until:
             t = _time.strptime(self.until, self.format)
-            params['until'] = int(_time.mktime(t))
+            args['until'] = int(_time.mktime(t))
         
-        l = self.client.list_objects(container, self.detail, params, headers)
-        print_list(l)
+        container, sep, object = container.partition('/')
+        if object:
+            return
+        
+        detail = 'json'
+        #if request with meta quering disable trash filtering
+        show_trashed = True if self.meta else False
+        l = self.client.list_objects(container, **args)
+        print_list(l, detail=self.detail)
 
 @cli_command('meta')
 class Meta(Command):
     syntax = '[<container>[/<object>]]'
-    description = 'get the metadata of an account, a container or an object'
+    description = 'get account/container/object metadata'
     
     def add_options(self, parser):
         parser.add_option('-r', action='store_true', dest='restricted',
                           default=False, help='show only user defined metadata')
         parser.add_option('--until', action='store', dest='until',
-                          default=False, help='show metadata until that date')
+                          default=None, help='show metadata until that date')
         parser.add_option('--format', action='store', dest='format',
                           default='%d/%m/%Y', help='format to parse until date')
         parser.add_option('--version', action='store', dest='version',
@@ -153,19 +203,19 @@ class Meta(Command):
     
     def execute(self, path=''):
         container, sep, object = path.partition('/')
-        if self.until:
+        args = {'restricted':self.restricted}
+        if getattr(self, 'until'):
             t = _time.strptime(self.until, self.format)
-            self.until = int(_time.mktime(t))
+            args['until'] = int(_time.mktime(t))
+        
         if object:
             meta = self.client.retrieve_object_metadata(container, object,
                                                         self.restricted,
                                                         self.version)
         elif container:
-            meta = self.client.retrieve_container_metadata(container,
-                                                           self.restricted,
-                                                           self.until)
+            meta = self.client.retrieve_container_metadata(container, **args)
         else:
-            meta = self.client.account_metadata(self.restricted, self.until)
+            meta = self.client.retrieve_account_metadata(**args)
         if meta == None:
             print 'Entity does not exist'
         else:
@@ -177,11 +227,11 @@ class CreateContainer(Command):
     description = 'create a container'
     
     def execute(self, container, *args):
-        headers = {}
+        meta = {}
         for arg in args:
             key, sep, val = arg.partition('=')
-            headers['X_CONTAINER_META_%s' %key.strip().upper()] = val.strip()
-        ret = self.client.create_container(container, headers)
+            meta[key] = val
+        ret = self.client.create_container(container, **meta)
         if not ret:
             print 'Container already exists'
 
@@ -190,12 +240,23 @@ class Delete(Command):
     syntax = '<container>[/<object>]'
     description = 'delete a container or an object'
     
+    def add_options(self, parser):
+        parser.add_option('--until', action='store', dest='until',
+                          default=None, help='remove history until that date')
+        parser.add_option('--format', action='store', dest='format',
+                          default='%d/%m/%Y', help='format to parse until date')
+    
     def execute(self, path):
         container, sep, object = path.partition('/')
+        until = None
+        if getattr(self, 'until'):
+            t = _time.strptime(self.until, self.format)
+            until = int(_time.mktime(t))
+        
         if object:
-            self.client.delete_object(container, object)
+            self.client.delete_object(container, object, until)
         else:
-            self.client.delete_container(container)
+            self.client.delete_container(container, until)
 
 @cli_command('get')
 class GetObject(Command):
@@ -207,18 +268,20 @@ class GetObject(Command):
                           default=False, help='show detailed output')
         parser.add_option('--range', action='store', dest='range',
                           default=None, help='show range of data')
-        parser.add_option('--if-match', action='store', dest='if-match',
+        parser.add_option('--if-range', action='store', dest='if_range',
+                          default=None, help='show range of data')
+        parser.add_option('--if-match', action='store', dest='if_match',
                           default=None, help='show output if ETags match')
         parser.add_option('--if-none-match', action='store',
-                          dest='if-none-match', default=None,
+                          dest='if_none_match', default=None,
                           help='show output if ETags don\'t match')
         parser.add_option('--if-modified-since', action='store', type='str',
-                          dest='if-modified-since', default=None,
+                          dest='if_modified_since', default=None,
                           help='show output if modified since then')
         parser.add_option('--if-unmodified-since', action='store', type='str',
-                          dest='if-unmodified-since', default=None,
+                          dest='if_unmodified_since', default=None,
                           help='show output if not modified since then')
-        parser.add_option('-f', action='store', type='str',
+        parser.add_option('-o', action='store', type='str',
                           dest='file', default=None,
                           help='save output in file')
         parser.add_option('--version', action='store', type='str',
@@ -230,23 +293,31 @@ class GetObject(Command):
                           help='get the full object version list')
     
     def execute(self, path):
-        headers = {}
+        attrs = ['if_match', 'if_none_match', 'if_modified_since',
+                 'if_unmodified_since']
+        args = self._build_args(attrs)
+        args['format'] = 'json' if self.detail else 'text'
         if self.range:
-            headers['RANGE'] = 'bytes=%s' %self.range
-        attrs = ['if-match', 'if-none-match', 'if-modified-since',
-                 'if-unmodified-since']
-        attrs = [a for a in attrs if getattr(self, a)]
-        for a in attrs:
-            headers[a.replace('-', '_').upper()] = getattr(self, a)
+            args['range'] = 'bytes=%s' %self.range
+        if getattr(self, 'if_range'):
+            args['if-range'] = 'If-Range:%s' % getattr(self, 'if_range')
+        
         container, sep, object = path.partition('/')
+        data = None
         if self.versionlist:
-            self.version = 'list'
+            if 'detail' in args.keys():
+                args.pop('detail')
+            args.pop('format')
             self.detail = True
-        data = self.client.retrieve_object(container, object, self.detail,
-                                          headers, self.version)
+            data = self.client.retrieve_object_versionlist(container, object, **args)
+        elif self.version:
+            data = self.client.retrieve_object_version(container, object,
+                                                       self.version, **args)
+        else:
+            data = self.client.retrieve_object(container, object, **args)    
+        
         f = self.file and open(self.file, 'w') or stdout
         if self.detail:
-            data = json.loads(data)
             if self.versionlist:
                 print_versions(data, f=f)
             else:
@@ -266,87 +337,119 @@ class PutMarker(Command):
 
 @cli_command('put')
 class PutObject(Command):
-    syntax = '<container>/<object> <path> [key=val] [...]'
-    description = 'create/override object with path contents or standard input'
+    syntax = '<container>/<object> [key=val] [...]'
+    description = 'create/override object'
     
     def add_options(self, parser):
+        parser.add_option('--use_hashes', action='store_true', dest='use_hashes',
+                          default=False, help='provide hashmap instead of data')
         parser.add_option('--chunked', action='store_true', dest='chunked',
                           default=False, help='set chunked transfer mode')
         parser.add_option('--etag', action='store', dest='etag',
                           default=None, help='check written data')
         parser.add_option('--content-encoding', action='store',
-                          dest='content-encoding', default=None,
+                          dest='content_encoding', default=None,
                           help='provide the object MIME content type')
         parser.add_option('--content-disposition', action='store', type='str',
-                          dest='content-disposition', default=None,
+                          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,
-                          help='use for large file support')
-        parser.add_option('--type', action='store',
-                          dest='content-type', default=False,
+        #parser.add_option('-S', action='store',
+        #                  dest='segment_size', default=False,
+        #                  help='use for large file support')
+        parser.add_option('--manifest', action='store',
+                          dest='x_object_manifest', default=None,
+                          help='upload a manifestation file')
+        parser.add_option('--content-type', action='store',
+                          dest='content_type', default=None,
                           help='create object with specific content type')
-        parser.add_option('--touch', action='store_true',
-                          dest='touch', default=False,
-                          help='create object with zero data')
-    
-    def execute(self, path, srcpath='-', *args):
-        headers = {}
-        if self.manifest:
-            headers['X_OBJECT_MANIFEST'] = self.manifest
-            
-        attrs = ['etag', 'content-encoding', 'content-disposition']
-        
-        attrs = ['etag', 'content-encoding', 'content-disposition',
-                 'content-type']
-        attrs = [a for a in attrs if getattr(self, a)]
-        for a in attrs:
-            headers[a.replace('-', '_').upper()] = getattr(self, a)
+        parser.add_option('--sharing', action='store',
+                          dest='x_object_sharing', default=None,
+                          help='define sharing object policy')
+        parser.add_option('-f', action='store',
+                          dest='srcpath', default=None,
+                          help='file descriptor to read from (pass - for standard input)')
+        parser.add_option('--public', action='store_true',
+                          dest='x_object_public', default=False,
+                          help='make object publicly accessible')
+    
+    def execute(self, path, *args):
+        if path.find('=') != -1:
+            raise Fault('Missing path argument')
         
         #prepare user defined meta
+        meta = {}
         for arg in args:
             key, sep, val = arg.partition('=')
-            headers['X_OBJECT_META_%s' %key.strip().upper()] = val.strip()
+            meta[key] = val
+        
+        attrs = ['etag', 'content_encoding', 'content_disposition',
+                 'content_type', 'x_object_sharing', 'x_object_public']
+        args = self._build_args(attrs)
         
         container, sep, object = path.partition('/')
         
         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.create_object(container, object, f, chunked=chunked,
-                                  headers=headers)
+        if self.srcpath:
+            f = open(self.srcpath) if self.srcpath != '-' else stdin
+        
+        if self.use_hashes and not f:
+            raise Fault('Illegal option combination')
+        
+        if self.chunked:
+            self.client.create_object_using_chunks(container, object, f,
+                                                    meta=meta, **args)
+        elif self.use_hashes:
+            format = 'json' if detail else 'text'
+            self.client.create_object_by_hashmap(container, object, f, format,
+                                 meta=meta, **args)
+        elif self.x_object_manifest:
+            self.client.create_manifestation(container, object, self.x_object_manifest)
+        elif not f:
+            self.client.create_zero_length_object(container, object, meta=meta, **args)
+        else:
+            self.client.create_object(container, object, f, meta=meta, **args)
         if f:
             f.close()
 
 @cli_command('copy', 'cp')
 class CopyObject(Command):
-    syntax = '<src container>/<src object> [<dst container>/]<dst object>'
-    description = 'copies an object to a different location'
+    syntax = '<src container>/<src object> [<dst container>/]<dst object> [key=val] [...]'
+    description = 'copy an object to a different location'
     
     def add_options(self, parser):
         parser.add_option('--version', action='store',
                           dest='version', default=False,
                           help='copy specific version')
+        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):
+    def execute(self, src, dst, *args):
         src_container, sep, src_object = src.partition('/')
         dst_container, sep, dst_object = dst.partition('/')
+        
+        #prepare user defined meta
+        meta = {}
+        for arg in args:
+            key, sep, val = arg.partition('=')
+            meta[key] = val
+        
         if not sep:
             dst_container = src_container
             dst_object = dst
-        version = getattr(self, 'version')
-        if version:
-            headers = {}
-            headers['X_SOURCE_VERSION'] = version
+        
+        args = {'content_type':self.content_type} if self.content_type else {}
         self.client.copy_object(src_container, src_object, dst_container,
-                                dst_object, headers)
+                                dst_object, meta, self.public, self.version,
+                                **args)
 
 @cli_command('set')
 class SetMeta(Command):
     syntax = '[<container>[/<object>]] key=val [key=val] [...]'
-    description = 'set metadata'
+    description = 'set account/container/object metadata'
     
     def execute(self, path, *args):
         #in case of account fix the args
@@ -375,103 +478,107 @@ class UpdateObject(Command):
     def add_options(self, parser):
         parser.add_option('-a', action='store_true', dest='append',
                           default=True, help='append data')
-        parser.add_option('--start', action='store',
-                          dest='start',
-                          default=None, help='range of data to be updated')
+        parser.add_option('--offset', action='store',
+                          dest='offset',
+                          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',
                           default=False, help='set chunked transfer mode')
         parser.add_option('--content-encoding', action='store',
-                          dest='content-encoding', default=None,
+                          dest='content_encoding', default=None,
                           help='provide the object MIME content type')
         parser.add_option('--content-disposition', action='store', type='str',
-                          dest='content-disposition', default=None,
+                          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,
-                          help='use for large file support')
+                          dest='x_object_manifest', default=None,
+                          help='use for large file support')        
+        parser.add_option('--sharing', action='store',
+                          dest='x_object_sharing', default=None,
+                          help='define sharing object policy')
+        parser.add_option('--nosharing', action='store_true',
+                          dest='no_sharing', default=None,
+                          help='clear object sharing policy')
+        parser.add_option('-f', action='store',
+                          dest='srcpath', default=None,
+                          help='file descriptor to read from: pass - for standard input')
+        parser.add_option('--public', action='store_true',
+                          dest='x_object_public', default=False,
+                          help='make object publicly accessible')
     
-    def execute(self, path, srcpath='-', *args):
-        headers = {}
-        if self.manifest:
-            headers['X_OBJECT_MANIFEST'] = self.manifest
-        
-        if getattr(self, 'start'):
-            headers['CONTENT_RANGE'] = 'bytes %s-/*' % getattr(self, 'start')
-        elif self.append:
-            headers['CONTENT_RANGE'] = 'bytes */*'
-        
-        attrs = ['content-encoding', 'content-disposition']
-        attrs = [a for a in attrs if getattr(self, a)]
-        for a in attrs:
-            headers[a.replace('-', '_').upper()] = getattr(self, a)
+    def execute(self, path, *args):
+        if path.find('=') != -1:
+            raise Fault('Missing path argument')
         
         #prepare user defined meta
+        meta = {}
         for arg in args:
             key, sep, val = arg.partition('=')
-            headers['X_OBJECT_META_%s' %key.strip().upper()] = val.strip()
+            meta[key] = val
+        
+        if self.no_sharing:
+            self.x_object_sharing = ''
+        
+        attrs = ['content_encoding', 'content_disposition', 'x_object_sharing',
+                 'x_object_public']
+        args = self._build_args(attrs)
         
         container, sep, object = path.partition('/')
         
-        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()
+        f = None
+        if self.srcpath:
+            f = open(self.srcpath) if self.srcpath != '-' else stdin
+        
+        if self.chunked:
+            self.client.update_object_using_chunks(container, object, f,
+                                                    meta=meta, **args)
+        else:
+            self.client.update_object(container, object, f, meta=meta, **args)
+        if f:
+            f.close()
 
 @cli_command('move', 'mv')
 class MoveObject(Command):
     syntax = '<src container>/<src object> [<dst container>/]<dst object>'
-    description = 'moves an object to a different location'
+    description = 'move an object to a different location'
     
     def add_options(self, parser):
         parser.add_option('--version', action='store',
-                          dest='version', default=False,
-                          help='move specific version')
-
-    def execute(self, src, dst):
+                          dest='version', default=None,
+                          help='move a specific object version')
+        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, sep, dst_object = dst.partition('/')
         if not sep:
             dst_container = src_container
             dst_object = dst
         
-        version = getattr(self, 'version')
-        if version:
-            headers = {}
-            headers['X_SOURCE_VERSION'] = version 
-        self.client.move_object(src_container, src_object, dst_container,
-                                dst_object, headers)
-
-@cli_command('remove', 'rm')
-class TrashObject(Command):
-    syntax = '<container>/<object>'
-    description = 'trashes 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 TrashObject(Command):
-    syntax = '<container>/<object>'
-    description = 'trashes an object'
-    
-    def execute(self, src):
-        src_container, sep, src_object = src.partition('/')
+        #prepare user defined meta
+        meta = {}
+        for arg in args:
+            key, sep, val = arg.partition('=')
+            meta[key] = val
         
-        self.client.restore_object(src_container, src_object)
+        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, **args)
 
 @cli_command('unset')
-class TrashObject(Command):
+class UnsetObject(Command):
     syntax = '<container>/[<object>] key [key] [...]'
-    description = 'deletes metadata info'
+    description = 'delete metadata info'
     
     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)
@@ -487,8 +594,94 @@ class TrashObject(Command):
         else:
             self.client.delete_account_metadata(meta)
 
+@cli_command('group')
+class CreateGroup(Command):
+    syntax = 'key=val [key=val] [...]'
+    description = 'create account groups'
+    
+    def execute(self, *args):
+        groups = {}
+        for arg in args:
+            key, sep, val = arg.partition('=')
+            groups[key] = val
+        self.client.set_account_groups(**groups)
+
+@cli_command('ungroup')
+class DeleteGroup(Command):
+    syntax = 'key [key] [...]'
+    description = 'delete account groups'
+    
+    def execute(self, *args):
+        groups = []
+        for arg in args:
+            groups.append(arg)
+        self.client.unset_account_groups(groups)
+
+@cli_command('policy')
+class SetPolicy(Command):
+    syntax = 'container key=val [key=val] [...]'
+    description = 'set container policies'
+    
+    def execute(self, path, *args):
+        if path.find('=') != -1:
+            raise Fault('Missing container argument')
+        
+        container, sep, object = path.partition('/')
+        
+        if object:
+            raise Fault('Only containers have policies')
+        
+        policies = {}
+        for arg in args:
+            key, sep, val = arg.partition('=')
+            policies[key] = val
+        
+        self.client.set_container_policies(container, **policies)
+
+@cli_command('publish')
+class PublishObject(Command):
+    syntax = '<container>/<object>'
+    description = 'publish an object'
+    
+    def execute(self, src):
+        src_container, sep, src_object = src.partition('/')
+        
+        self.client.publish_object(src_container, src_object)
+
+@cli_command('unpublish')
+class UnpublishObject(Command):
+    syntax = '<container>/<object>'
+    description = 'unpublish an object'
+    
+    def execute(self, src):
+        src_container, sep, src_object = src.partition('/')
+        
+        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([])
+    cmd = Command('', [])
     parser = cmd.parser
     parser.usage = '%prog <command> [options]'
     parser.print_help()
@@ -500,27 +693,23 @@ def print_usage():
         commands.append('  %s %s' % (name.ljust(12), description))
     print '\nCommands:\n' + '\n'.join(sorted(commands))
 
-def print_dict(d, header='name', f=stdout):
-    header = header in d and header or 'subdir'
+def print_dict(d, header='name', f=stdout, detail=True):
+    header = header if header in d else 'subdir'
     if header and header in d:
-        f.write('%s\n' %d.pop(header))
-    patterns = ['^x_(account|container|object)_meta_(\w+)$']
-    patterns.append(patterns[0].replace('_', '-'))
-    for key, val in sorted(d.items()):
-        for p in patterns:
-            p = re.compile(p)
-            m = p.match(key)
-            if m:
-                key = m.group(2)
-        f.write('%s: %s\n' % (key.rjust(30), val))
-
-def print_list(l, verbose=False, f=stdout):
+        f.write('%s\n' %d.pop(header).encode('utf8'))
+    if detail:
+        patterns = ['^x_(account|container|object)_meta_(\w+)$']
+        patterns.append(patterns[0].replace('_', '-'))
+        for key, val in sorted(d.items()):
+            f.write('%s: %s\n' % (key.rjust(30), val))
+
+def print_list(l, verbose=False, f=stdout, detail=True):
     for elem in l:
         #if it's empty string continue
         if not elem:
             continue
         if type(elem) == types.DictionaryType:
-            print_dict(elem, f=f)
+            print_dict(elem, f=f, detail=detail)
         elif type(elem) == types.StringType:
             if not verbose:
                 elem = elem.split('Traceback')[0]
@@ -544,17 +733,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)