Remove __builtin__.print from _commands
authorStavros Sachtouris <saxtouri@admin.grnet.gr>
Thu, 12 Sep 2013 09:39:26 +0000 (12:39 +0300)
committerStavros Sachtouris <saxtouri@admin.grnet.gr>
Thu, 12 Sep 2013 09:39:26 +0000 (12:39 +0300)
Refs: #4292

kamaki/cli/commands/image.py
kamaki/cli/commands/livetest.py
kamaki/cli/commands/snf-astakos.py

index c481b73..cc1cdb4 100644 (file)
@@ -83,9 +83,8 @@ class _init_image(_command_init):
         if getattr(self, 'cloud', None):
             img_url = self._custom_url('image') or self._custom_url('plankton')
             if img_url:
-                token = self._custom_token('image')\
-                    or self._custom_token('plankton')\
-                    or self.config.get_cloud(self.cloud, 'token')
+                token = self._custom_token('image') or self._custom_token(
+                    'plankton') or self.config.get_cloud(self.cloud, 'token')
                 self.client = ImageClient(base_url=img_url, token=token)
                 return
         if getattr(self, 'auth_base', False):
@@ -378,9 +377,8 @@ class image_meta_delete(_init_image, _optional_output_cmd):
     )
 
     def _check_empty(self):
-        for term in (
-                'disk_format', 'container_format', 'status', 'properties'):
-            if self[term]:
+        for t in ('disk_format', 'container_format', 'status', 'properties'):
+            if self[t]:
                 return
         raiseCLIError(
             'Nothing to update, please use arguments (-h for a list)')
@@ -425,8 +423,7 @@ class image_register(_init_image, _optional_json):
     arguments = dict(
         checksum=ValueArgument('Set image checksum', '--checksum'),
         container_format=ValueArgument(
-            'Set container format',
-            '--container-format'),
+            'Set container format', '--container-format'),
         disk_format=ValueArgument('Set disk format', '--disk-format'),
         owner_name=ValueArgument('Set user uuid by user name', '--owner-name'),
         properties=KeyValueArgument(
@@ -461,8 +458,8 @@ class image_register(_init_image, _optional_json):
         if getattr(self, 'auth_base', False):
             return self.auth_base.term('id', atoken)
         else:
-            astakos_url = self.config.get('user', 'url')\
-                or self.config.get('astakos', 'url')
+            astakos_url = self.config.get('user', 'url') or self.config.get(
+                'astakos', 'url')
             if not astakos_url:
                 raise CLIBaseUrlError(service='astakos')
             user = AstakosClient(astakos_url, atoken)
@@ -494,7 +491,7 @@ class image_register(_init_image, _optional_json):
             try:
                 for k, v in _load_image_meta(pfile).items():
                     key = k.lower().replace('-', '_')
-                    if k == 'properties':
+                    if key == 'properties':
                         for pk, pv in v.items():
                             properties[pk.upper().replace('-', '_')] = pv
                     elif key == 'name':
@@ -639,14 +636,15 @@ class image_register(_init_image, _optional_json):
                     meta_path, dumps(r, indent=2),
                     container_info_cache=self.container_info_cache)
             except TypeError:
-                print('Failed to dump metafile %s:%s' % (dst_cont, meta_path))
+                self.error(
+                    'Failed to dump metafile %s:%s' % (dst_cont, meta_path))
                 return
             if self['json_output']:
                 print_json(dict(
                     metafile_location='%s:%s' % (dst_cont, meta_path),
                     headers=meta_headers))
             else:
-                print('Metadata file uploaded as %s:%s (version %s)' % (
+                self.error('Metadata file uploaded as %s:%s (version %s)' % (
                     dst_cont, meta_path, meta_headers['x-object-version']))
 
     def main(self, name, container___image_path):
@@ -775,9 +773,7 @@ class image_compute_list(
     arguments = dict(
         detail=FlagArgument('show detailed output', ('-l', '--details')),
         limit=IntArgument('limit number listed images', ('-n', '--number')),
-        more=FlagArgument(
-            'output results in pages (-n to set items per page, default 10)',
-            '--more'),
+        more=FlagArgument('handle long lists of results', '--more'),
         enum=FlagArgument('Enumerate results', '--enumerate'),
         user_id=ValueArgument('filter by user_id', '--user-id'),
         user_name=ValueArgument('filter by username', '--user-name'),
@@ -917,23 +913,6 @@ class image_compute_properties_get(_init_cyclades, _optional_json):
         self._run(image_id=image_id, key=key)
 
 
-#@command(image_cmds)
-#class image_compute_properties_add(_init_cyclades, _optional_json):
-#    """Add a property to an image"""
-#
-#    @errors.generic.all
-#    @errors.cyclades.connection
-#    @errors.plankton.id
-#    @errors.plankton.metadata
-#    def _run(self, image_id, key, val):
-#        self._print(
-#            self.client.create_image_metadata(image_id, key, val), print_dict)
-#
-#    def main(self, image_id, key, val):
-#        super(self.__class__, self)._run()
-#        self._run(image_id=image_id, key=key, val=val)
-
-
 @command(image_cmds)
 class image_compute_properties_set(_init_cyclades, _optional_json):
     """Add / update a set of properties for an image
index cb288e9..63ef762 100644 (file)
@@ -77,7 +77,7 @@ class livetest_args(_livetest_init):
 
     @errors.generic.all
     def _run(self, *args):
-        print(args)
+        self.writeln(args)
 
     def main(self, *args):
         self._run(args)
@@ -163,56 +163,56 @@ class livetest_prints(_livetest_init):
     @errors.generic.all
     def _run(self):
         from kamaki.cli.utils import print_dict, print_list, print_items
-        print('Test simple dict:\n- - -')
+        self.writeln('Test simple dict:\n- - -')
         print_dict(self.d1)
-        print('- - -\n')
-        print('\nTest simple list:\n- - -')
+        self.writeln('- - -\n')
+        self.writeln('\nTest simple list:\n- - -')
         print_list(self.l1)
-        print('- - -\n')
-        print('\nTest 2-level dict:\n- - -')
+        self.writeln('- - -\n')
+        self.writeln('\nTest 2-level dict:\n- - -')
         print_dict(self.d2)
-        print('- - -\n')
-        print('\nTest non-trivial list:\n- - -')
+        self.writeln('- - -\n')
+        self.writeln('\nTest non-trivial list:\n- - -')
         print_list(self.l2)
-        print('- - -')
-        print('\nTest extreme dict:\n- - -')
+        self.writeln('- - -')
+        self.writeln('\nTest extreme dict:\n- - -')
         print_dict(self.d3)
-        print('- - -\n')
-        print('Test simple enumerated dict:\n- - -')
+        self.writeln('- - -\n')
+        self.writeln('Test simple enumerated dict:\n- - -')
         print_dict(self.d1, with_enumeration=True)
-        print('- - -\n')
-        print('\nTest simple enumerated list:\n- - -')
+        self.writeln('- - -\n')
+        self.writeln('\nTest simple enumerated list:\n- - -')
         print_list(self.l1, with_enumeration=True)
-        print('- - -\n')
-        print('Test non-trivial deep-enumerated dict:\n- - -')
+        self.writeln('- - -\n')
+        self.writeln('Test non-trivial deep-enumerated dict:\n- - -')
         print_dict(self.d2, with_enumeration=True, recursive_enumeration=True)
-        print('- - -\n')
-        print('\nTest non-trivial enumerated list:\n- - -')
+        self.writeln('- - -\n')
+        self.writeln('\nTest non-trivial enumerated list:\n- - -')
         print_list(self.l2, with_enumeration=True)
-        print('- - -\n')
-        print('\nTest print_items with id:\n- - -')
+        self.writeln('- - -\n')
+        self.writeln('\nTest print_items with id:\n- - -')
         print_items([
             {'id': '42', 'title': 'lalakis 1', 'content': self.d1},
             {'id': '142', 'title': 'lalakis 2', 'content': self.d2}])
-        print('- - -')
-        print('\nTest print_items with id and enumeration:\n- - -')
+        self.writeln('- - -')
+        self.writeln('\nTest print_items with id and enumeration:\n- - -')
         print_items(
             [
                 {'id': '42', 'title': 'lalakis 1', 'content': self.d1},
                 {'id': '142', 'title': 'lalakis 2', 'content': self.d2}],
             with_enumeration=True)
-        print('- - -')
-        print('\nTest print_items with id, title and redundancy:\n- - -')
+        self.writeln('- - -')
+        self.writeln('\nTest print_items with id, title, redundancy:\n- - -')
         print_items(
             [
                 {'id': '42', 'title': 'lalakis 1', 'content': self.d1},
                 {'id': '142', 'title': 'lalakis 2', 'content': self.d2}],
             title=('id', 'title'),
             with_redundancy=True)
-        print('- - -')
-        print('\nTest print_items with lists- - -')
+        self.writeln('- - -')
+        self.writeln('\nTest print_items with lists- - -')
         print_items([['i00', 'i01', 'i02'], [self.l2, 'i11', self.d1], 3])
-        print('- - -')
+        self.writeln('- - -')
 
     def main(self):
         self._run()
index ea98e41..1bdb9cc 100644 (file)
@@ -421,8 +421,8 @@ class astakos_commission_resolve(_astakos_init, _optional_json):
     @errors.generic.all
     @astakoserror
     def _run(self):
-        print 'accepted ', self['accept']
-        print 'rejected ', self['reject']
+        self.writeln('accepted ', self['accept'])
+        self.writeln('rejected ', self['reject'])
         self._print(
             self.client.resolve_commissions(
                 self.token, self['accept'], self['reject']),
@@ -506,7 +506,7 @@ _project_specs = """
 def apply_notification(foo):
     def wrap(self, *args, **kwargs):
         r = foo(self, *args, **kwargs)
-        print 'Application is submitted successfully'
+        self.writeln('Application is submitted successfully')
         return r
     return wrap
 
@@ -811,7 +811,7 @@ class project_membership_join(_astakos_init):
     @errors.generic.all
     @astakoserror
     def _run(self, project_id):
-        print self.client.join_project(self.token, project_id)
+        self.writeln(self.client.join_project(self.token, project_id))
 
     def main(self, project_id):
         super(project_membership_join, self)._run()
@@ -825,7 +825,7 @@ class project_membership_enroll(_astakos_init):
     @errors.generic.all
     @astakoserror
     def _run(self, project_id, email):
-        print self.client.enroll_member(self.token, project_id, email)
+        self.writeln(self.client.enroll_member(self.token, project_id, email))
 
     def main(self, project_id, email):
         super(project_membership_join, self)._run()