Added store list_containers and a minor CLI fix
authorStavros Sachtouris <saxtouri@admin.grnet.gr>
Mon, 2 Jul 2012 13:53:38 +0000 (16:53 +0300)
committerStavros Sachtouris <saxtouri@admin.grnet.gr>
Tue, 10 Jul 2012 14:09:27 +0000 (17:09 +0300)
Exposed list_containers from storage to CLI as
    kamaki store list_containers

Moved method format_size from store_list to util, since it is semantically unreleated and
it was needed by list_ containers (and, possibly, other functions in the future)

Not tested yet

kamaki/cli.py
kamaki/utils.py

index 52bef8d..9c43e4c 100755 (executable)
@@ -88,7 +88,7 @@ from requests.exceptions import ConnectionError
 
 from . import clients
 from .config import Config
-from .utils import print_addresses, print_dict, print_items
+from .utils import print_addresses, print_dict, print_items, format_size
 
 
 _commands = OrderedDict()
@@ -727,21 +727,20 @@ class store_container(_store_account_command):
         reply = self.client.get_container_meta(container)
         print_dict(reply)
 
+@command(api='storage')
+class store_list_containers(_store_account_command):
+    """List containers"""
+
+    def main(self):
+        super(store_list_containers, self).main()
+        for object in self.client.list_containers():
+            size = self.format_size(object['bytes'])
+            print('%s (%s, %s objects)' % (object['name'], size, object['count']))
 
 @command(api='storage')
 class store_list(_store_container_command):
     """List objects"""
 
-    def format_size(self, size):
-        units = ('B', 'K', 'M', 'G', 'T')
-        size = float(size)
-        for unit in units:
-            if size <= 1024:
-                break
-            size /= 1024
-        s = ('%.1f' % size).rstrip('.0')
-        return s + unit
-
     def main(self, path=''):
         super(store_list, self).main()
         for object in self.client.list_objects():
@@ -749,6 +748,7 @@ class store_list(_store_container_command):
             print('%6s %s' % (size, object['name']))
 
 
+
 @command(api='storage')
 class store_upload(_store_container_command):
     """Upload a file"""
index 506e276..bb4f5ae 100644 (file)
@@ -85,3 +85,13 @@ def print_items(items, title=('id', 'name')):
         if item:
             print_dict(item)
             print
+
+def format_size(self, size):
+    units = ('B', 'K', 'M', 'G', 'T')
+    size = float(size)
+    for unit in units:
+        if size <= 1024:
+            break
+        size /= 1024
+    s = ('%.1f' % size).rstrip('.0')
+    return s + unit