From 02075a5a19b4ef85a78b4b5a097cd32b50a307fb Mon Sep 17 00:00:00 2001 From: Seif Lotfy Date: Fri, 21 Jun 2013 13:22:47 +0000 Subject: [PATCH] Use list comprehensions when possible Replace some for loops with list comprehensions for compacting Change-Id: Ia80a013735c595d7c4d40172b34beb18b4383ee0 --- cinder/backup/services/swift.py | 9 +++------ cinder/volume/drivers/solidfire.py | 2 +- cinder/volume/drivers/storwize_svc.py | 11 +++-------- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/cinder/backup/services/swift.py b/cinder/backup/services/swift.py index 7e2aa287a..69f9a68f0 100644 --- a/cinder/backup/services/swift.py +++ b/cinder/backup/services/swift.py @@ -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 diff --git a/cinder/volume/drivers/solidfire.py b/cinder/volume/drivers/solidfire.py index 63c8c9899..f4bf1bb8b 100644 --- a/cinder/volume/drivers/solidfire.py +++ b/cinder/volume/drivers/solidfire.py @@ -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, diff --git a/cinder/volume/drivers/storwize_svc.py b/cinder/volume/drivers/storwize_svc.py index b9eacc494..2c9774ecd 100755 --- a/cinder/volume/drivers/storwize_svc.py +++ b/cinder/volume/drivers/storwize_svc.py @@ -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): -- 2.45.2