]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Use list comprehensions when possible
authorSeif Lotfy <s.lotfy@telekom.de>
Fri, 21 Jun 2013 13:22:47 +0000 (13:22 +0000)
committerSeif Lotfy <s.lotfy@telekom.de>
Fri, 21 Jun 2013 15:05:55 +0000 (15:05 +0000)
Replace some for loops with list comprehensions for compacting

Change-Id: Ia80a013735c595d7c4d40172b34beb18b4383ee0

cinder/backup/services/swift.py
cinder/volume/drivers/solidfire.py
cinder/volume/drivers/storwize_svc.py

index 7e2aa287abdfd187221b645da2a956e4ba623d89..69f9a68f03ec166af992b3f02e2b16be88dd5ca4 100644 (file)
@@ -154,9 +154,7 @@ class SwiftBackupService(base.Base):
         swift_objects = self.conn.get_container(backup['container'],
                                                 prefix=prefix,
                                                 full_listing=True)[1]
-        swift_object_names = []
-        for swift_object in swift_objects:
-            swift_object_names.append(swift_object['name'])
+        swift_object_names = [swift_obj['name'] for swift_obj in swift_objects]
         LOG.debug(_('generated object list: %s') % swift_object_names)
         return swift_object_names
 
@@ -298,9 +296,8 @@ class SwiftBackupService(base.Base):
         LOG.debug(_('v1 swift volume backup restore of %s started'), backup_id)
         container = backup['container']
         metadata_objects = metadata['objects']
-        metadata_object_names = []
-        for metadata_object in metadata_objects:
-            metadata_object_names.extend(metadata_object.keys())
+        metadata_object_names = sum((obj.keys() for obj in metadata_objects),
+                                    [])
         LOG.debug(_('metadata_object_names = %s') % metadata_object_names)
         prune_list = [self._metadata_filename(backup)]
         swift_object_names = [swift_object_name for swift_object_name in
index 63c8c9899f18bdecd1d93a9e18b4aeba0edbf7ca..f4bf1bb8b0d8eb60438ae4bc845e23deb1a35392 100644 (file)
@@ -462,7 +462,7 @@ class SolidFire(SanISCSIDriver):
                       'is_clone': 'False'}
         if qos:
             for k, v in qos.items():
-                            attributes[k] = str(v)
+                attributes[k] = str(v)
 
         params = {'name': 'UUID-%s' % volume['id'],
                   'accountID': None,
index b9eacc494b160fdd59534b0483f1df14304f6a67..2c9774ecdb36508bb14186a7550c29de0bd4d73a 100755 (executable)
@@ -588,9 +588,7 @@ class StorwizeSVCDriver(san.SanISCSIDriver):
             mapped_flag = True
             result_lun = mapping_data[volume_name]['SCSI_id']
         else:
-            lun_used = []
-            for k, v in mapping_data.iteritems():
-                lun_used.append(int(v['SCSI_id']))
+            lun_used = [int(v['SCSI_id']) for v in mapping_data.values()]
             lun_used.sort()
             # Assume all luns are taken to this point, and then try to find
             # an unused one
@@ -853,8 +851,7 @@ class StorwizeSVCDriver(san.SanISCSIDriver):
         mapping_ids = []
         if (len(out.strip())):
             lines = out.strip().split('\n')
-            for line in lines:
-                mapping_ids.append(line.split()[0])
+            mapping_ids = [line.split()[0] for line in lines]
         return mapping_ids
 
     def _get_vdisk_params(self, type_id):
@@ -1513,9 +1510,7 @@ class StorwizeSVCDriver(san.SanISCSIDriver):
               'Headers: %(header)s\n Values: %(row)s')
             % {'header': str(header),
                'row': str(row)})
-        dic = {}
-        for attribute, value in map(None, attributes, values):
-            dic[attribute] = value
+        dic = dict((a, v) for a, v in map(None, attributes, values))
         return dic
 
     def _log_cli_output_error(self, function, cmd, out, err):