mirror of
https://github.com/virt-manager/virt-manager.git
synced 2024-12-22 13:34:07 +03:00
Wrap keys(), values() in a list
In Python 3 dict.values() [1] , dict.keys() [2] and dict.items() [3] return a view [4] of the dictionary’s values, keys and items. In Python 2 these functions return a list. [5] [6] [7] To resolve this we can convert the result of these function to a list. [1] https://docs.python.org/3/library/stdtypes.html#dict.values [2] https://docs.python.org/3/library/stdtypes.html#dict.keys [3] https://docs.python.org/3/library/stdtypes.html#dict.items [4] https://docs.python.org/3/library/stdtypes.html#dict-views [5] https://docs.python.org/2/library/stdtypes.html#dict.items [6] https://docs.python.org/2/library/stdtypes.html#dict.keys [7] https://docs.python.org/2/library/stdtypes.html#dict.values
This commit is contained in:
parent
810ee09292
commit
978fb25ac7
@ -69,7 +69,7 @@ class TestNodeDev(unittest.TestCase):
|
||||
|
||||
def _testCompare(self, devname, vals, devxml=None):
|
||||
def _compare(dev, vals, root=""):
|
||||
for attr in vals.keys():
|
||||
for attr in list(vals.keys()):
|
||||
expect = vals[attr]
|
||||
actual = getattr(dev, attr)
|
||||
if isinstance(expect, list):
|
||||
|
@ -253,7 +253,7 @@ def _make_tests():
|
||||
vals.get("testshortcircuit", "0") == "1")
|
||||
urls[d.name] = d
|
||||
|
||||
keys = urls.keys()
|
||||
keys = list(urls.keys())
|
||||
keys.sort()
|
||||
for key in keys:
|
||||
distroobj = urls[key]
|
||||
|
@ -174,7 +174,7 @@ class vmmAddStorage(vmmGObjectUI):
|
||||
_("Don't ask about these directories again."))
|
||||
|
||||
if chkres:
|
||||
src.config.add_perms_fix_ignore(errors.keys())
|
||||
src.config.add_perms_fix_ignore(list(errors.keys()))
|
||||
|
||||
def reset_state(self):
|
||||
self._update_host_space()
|
||||
|
@ -336,7 +336,7 @@ class vmmCloneVM(vmmGObjectUI):
|
||||
|
||||
build_net_row(label, mac, newmac)
|
||||
|
||||
no_net = bool(len(self.net_list.keys()) == 0)
|
||||
no_net = (not list(self.net_list.keys()))
|
||||
self.widget("clone-network-box").set_visible(not no_net)
|
||||
self.widget("clone-no-net").set_visible(no_net)
|
||||
|
||||
@ -460,7 +460,7 @@ class vmmCloneVM(vmmGObjectUI):
|
||||
if cd.clone_name == newname:
|
||||
return
|
||||
|
||||
for row in self.storage_list.values():
|
||||
for row in list(self.storage_list.values()):
|
||||
origpath = row[STORAGE_INFO_ORIG_PATH]
|
||||
if row[STORAGE_INFO_MANUAL_PATH]:
|
||||
continue
|
||||
@ -599,7 +599,7 @@ class vmmCloneVM(vmmGObjectUI):
|
||||
# If any storage cannot be cloned or shared, don't allow cloning
|
||||
clone = True
|
||||
tooltip = ""
|
||||
for row in self.storage_list.values():
|
||||
for row in list(self.storage_list.values()):
|
||||
can_clone = row[STORAGE_INFO_CAN_CLONE]
|
||||
can_share = row[STORAGE_INFO_CAN_SHARE]
|
||||
if not (can_clone or can_share):
|
||||
|
@ -1215,35 +1215,35 @@ class vmmConnection(vmmGObject):
|
||||
def _update_nets(self, dopoll):
|
||||
keymap = dict((o.get_connkey(), o) for o in self.list_nets())
|
||||
if not dopoll or not self.is_network_capable():
|
||||
return [], [], keymap.values()
|
||||
return [], [], list(keymap.values())
|
||||
return pollhelpers.fetch_nets(self._backend, keymap,
|
||||
(lambda obj, key: vmmNetwork(self, obj, key)))
|
||||
|
||||
def _update_pools(self, dopoll):
|
||||
keymap = dict((o.get_connkey(), o) for o in self.list_pools())
|
||||
if not dopoll or not self.is_storage_capable():
|
||||
return [], [], keymap.values()
|
||||
return [], [], list(keymap.values())
|
||||
return pollhelpers.fetch_pools(self._backend, keymap,
|
||||
(lambda obj, key: vmmStoragePool(self, obj, key)))
|
||||
|
||||
def _update_interfaces(self, dopoll):
|
||||
keymap = dict((o.get_connkey(), o) for o in self.list_interfaces())
|
||||
if not dopoll or not self.is_interface_capable():
|
||||
return [], [], keymap.values()
|
||||
return [], [], list(keymap.values())
|
||||
return pollhelpers.fetch_interfaces(self._backend, keymap,
|
||||
(lambda obj, key: vmmInterface(self, obj, key)))
|
||||
|
||||
def _update_nodedevs(self, dopoll):
|
||||
keymap = dict((o.get_connkey(), o) for o in self.list_nodedevs())
|
||||
if not dopoll or not self.is_nodedev_capable():
|
||||
return [], [], keymap.values()
|
||||
return [], [], list(keymap.values())
|
||||
return pollhelpers.fetch_nodedevs(self._backend, keymap,
|
||||
(lambda obj, key: vmmNodeDevice(self, obj, key)))
|
||||
|
||||
def _update_vms(self, dopoll):
|
||||
keymap = dict((o.get_connkey(), o) for o in self.list_vms())
|
||||
if not dopoll:
|
||||
return [], [], keymap.values()
|
||||
return [], [], list(keymap.values())
|
||||
return pollhelpers.fetch_vms(self._backend, keymap,
|
||||
(lambda obj, key: vmmDomain(self, obj, key)))
|
||||
|
||||
|
@ -932,7 +932,7 @@ class vmmCreate(vmmGObjectUI):
|
||||
model.clear()
|
||||
|
||||
default = -1
|
||||
for c in self.engine.conns.values():
|
||||
for c in list(self.engine.conns.values()):
|
||||
connobj = c["conn"]
|
||||
if not connobj.is_active():
|
||||
continue
|
||||
|
@ -556,12 +556,12 @@ class vmmCreateInterface(vmmGObjectUI):
|
||||
row[INTERFACE_ROW_KEY] = key
|
||||
row_dict[name] = row
|
||||
|
||||
for row in row_dict.values():
|
||||
for row in list(row_dict.values()):
|
||||
name = row[INTERFACE_ROW_NAME]
|
||||
row[INTERFACE_ROW_IN_USE_BY] = self.iface_in_use_by(self.conn,
|
||||
name)
|
||||
|
||||
for row in row_dict.values():
|
||||
for row in list(row_dict.values()):
|
||||
model.append(row)
|
||||
|
||||
def get_default_name(self):
|
||||
|
@ -744,7 +744,7 @@ class vmmDetails(vmmGObjectUI):
|
||||
rmHW.connect("activate", self.remove_xml_dev)
|
||||
|
||||
self._addhwmenuitems = {"add": addHW, "remove": rmHW}
|
||||
for i in self._addhwmenuitems.values():
|
||||
for i in list(self._addhwmenuitems.values()):
|
||||
self.addhwmenu.add(i)
|
||||
|
||||
self.widget("hw-panel").set_show_tabs(False)
|
||||
@ -1516,7 +1516,9 @@ class vmmDetails(vmmGObjectUI):
|
||||
'tEXt::Generator Version': self.config.get_appversion(),
|
||||
}
|
||||
|
||||
ret = image.save_to_bufferv('png', metadata.keys(), metadata.values())
|
||||
ret = image.save_to_bufferv(
|
||||
'png', list(metadata.keys()), list(metadata.values())
|
||||
)
|
||||
# On Fedora 19, ret is (bool, str)
|
||||
# Someday the bindings might be fixed to just return the str, try
|
||||
# and future proof it a bit
|
||||
|
@ -154,7 +154,7 @@ class vmmEngine(vmmGObject):
|
||||
self._application.add_action(action)
|
||||
|
||||
def _default_startup(self, skip_autostart, cliuri):
|
||||
uris = self.conns.keys()
|
||||
uris = list(self.conns.keys())
|
||||
if not uris:
|
||||
logging.debug("No stored URIs found.")
|
||||
else:
|
||||
@ -514,10 +514,10 @@ class vmmEngine(vmmGObject):
|
||||
focus, and use that
|
||||
"""
|
||||
windowlist = [self.windowManager]
|
||||
for conndict in self.conns.values():
|
||||
windowlist.extend(conndict["windowDetails"].values())
|
||||
for conndict in list(self.conns.values()):
|
||||
windowlist.extend(list(conndict["windowDetails"].values()))
|
||||
windowlist.extend(
|
||||
[conndict["windowHost"] for conndict in self.conns.values()])
|
||||
[conndict["windowHost"] for conndict in list(self.conns.values())])
|
||||
|
||||
use_win = None
|
||||
for window in windowlist:
|
||||
@ -593,7 +593,7 @@ class vmmEngine(vmmGObject):
|
||||
self.conns[uri]["windowClone"].cleanup()
|
||||
|
||||
details = self.conns[uri]["windowDetails"]
|
||||
for win in details.values():
|
||||
for win in list(details.values()):
|
||||
win.cleanup()
|
||||
|
||||
self.conns[uri]["conn"].cleanup()
|
||||
@ -613,7 +613,7 @@ class vmmEngine(vmmGObject):
|
||||
handle_id = vmmGObject.connect(self, name, callback, *args)
|
||||
|
||||
if name == "conn-added":
|
||||
for conn_dict in self.conns.values():
|
||||
for conn_dict in list(self.conns.values()):
|
||||
self.emit("conn-added", conn_dict["conn"])
|
||||
|
||||
return handle_id
|
||||
@ -763,7 +763,7 @@ class vmmEngine(vmmGObject):
|
||||
return self.connect_to_uri(uri, autoconnect, probe=True)
|
||||
|
||||
def cancelled(src):
|
||||
if len(self.conns.keys()) == 0:
|
||||
if not list(self.conns.keys()):
|
||||
self.exit_app(src)
|
||||
|
||||
obj = vmmConnect()
|
||||
|
@ -313,7 +313,7 @@ class vmmMigrateDialog(vmmGObjectUI):
|
||||
model.clear()
|
||||
|
||||
rows = []
|
||||
for conn in self._conns.values():
|
||||
for conn in list(self._conns.values()):
|
||||
rows.append(self._build_dest_row(conn))
|
||||
|
||||
if not any([row[COL_CAN_MIGRATE] for row in rows]):
|
||||
|
@ -197,7 +197,7 @@ class vmmNetworkList(vmmGObjectUI):
|
||||
for slave in slave_names:
|
||||
netdevs.pop(slave, None)
|
||||
|
||||
for name, is_bridge, slave_names in netdevs.values():
|
||||
for name, is_bridge, slave_names in list(netdevs.values()):
|
||||
if ((name in vnet_taps) or
|
||||
(name in [v + "-nic" for v in vnet_bridges]) or
|
||||
(name in skip_ifaces)):
|
||||
|
@ -507,7 +507,7 @@ class vmmSnapshotPage(vmmGObjectUI):
|
||||
basesn = os.path.join(cachedir, "snap-screenshot-%s" % name)
|
||||
|
||||
# Remove any pre-existing screenshots so we don't show stale data
|
||||
for ext in mimemap.values():
|
||||
for ext in list(mimemap.values()):
|
||||
p = basesn + "." + ext
|
||||
if os.path.exists(basesn + "." + ext):
|
||||
os.unlink(p)
|
||||
|
@ -199,13 +199,13 @@ class vmmSystray(vmmGObject):
|
||||
|
||||
def repopulate_menu_list(self):
|
||||
# Build sorted connection list
|
||||
connsort = self.conn_menuitems.keys()
|
||||
connsort = list(self.conn_menuitems.keys())
|
||||
connsort.sort()
|
||||
connsort.reverse()
|
||||
|
||||
# Empty conn list
|
||||
for child in self.systray_menu.get_children():
|
||||
if child in self.conn_menuitems.values():
|
||||
if child in list(self.conn_menuitems.values()):
|
||||
self.systray_menu.remove(child)
|
||||
|
||||
# Build sorted conn list
|
||||
@ -265,7 +265,7 @@ class vmmSystray(vmmGObject):
|
||||
for vm in conn.list_vms():
|
||||
vm_mappings[vm.get_name()] = vm.get_connkey()
|
||||
|
||||
vm_names = vm_mappings.keys()
|
||||
vm_names = list(vm_mappings.keys())
|
||||
vm_names.sort()
|
||||
|
||||
if len(vm_names) == 0:
|
||||
|
@ -1193,7 +1193,7 @@ class VirtCLIParser(object):
|
||||
passed an invalid argument such as --disk idontexist=foo
|
||||
"""
|
||||
if optdict:
|
||||
fail(_("Unknown options %s") % optdict.keys())
|
||||
fail(_("Unknown options %s") % list(optdict.keys()))
|
||||
|
||||
def _parse(self, inst):
|
||||
"""
|
||||
@ -1681,7 +1681,7 @@ class ParserBoot(VirtCLIParser):
|
||||
def _parse(self, inst):
|
||||
# Build boot order
|
||||
boot_order = []
|
||||
for cliname in self.optdict.keys():
|
||||
for cliname in list(self.optdict.keys()):
|
||||
if cliname not in inst.os.BOOT_DEVICES:
|
||||
continue
|
||||
|
||||
|
@ -84,7 +84,7 @@ class VirtualGraphics(VirtualDevice):
|
||||
"""
|
||||
from . import hostkeymap
|
||||
|
||||
orig_list = hostkeymap.keytable.values()
|
||||
orig_list = list(hostkeymap.keytable.values())
|
||||
sort_list = []
|
||||
|
||||
orig_list.sort()
|
||||
|
@ -151,7 +151,7 @@ class DomainCapabilities(XMLBuilder):
|
||||
"""
|
||||
Return True if we know how to setup UEFI for the passed arch
|
||||
"""
|
||||
return self.arch in self._uefi_arch_patterns.keys()
|
||||
return self.arch in list(self._uefi_arch_patterns.keys())
|
||||
|
||||
def supports_uefi_xml(self):
|
||||
"""
|
||||
|
@ -1046,7 +1046,7 @@ class Guest(XMLBuilder):
|
||||
(str(d), str(addresses[addrstr][addr.function])))
|
||||
addresses[addrstr][addr.function] = d
|
||||
|
||||
for devs in addresses.values():
|
||||
for devs in list(addresses.values()):
|
||||
if len(devs) > 1 and 0 in devs:
|
||||
devs[0].address.multifunction = True
|
||||
|
||||
|
@ -202,7 +202,7 @@ def sanitize_keymap(kt):
|
||||
return len(b) - len(a)
|
||||
|
||||
clean_kt = kt.replace("-", "").replace("_", "")
|
||||
sorted_keys = sorted(keytable.keys(), len_cmp)
|
||||
sorted_keys = sorted(list(keytable.keys()), len_cmp)
|
||||
|
||||
for key in sorted_keys:
|
||||
origkey = key
|
||||
|
@ -98,12 +98,12 @@ def _sort(tosort, sortpref=None, limit_point_releases=False):
|
||||
# debian5, debian4, fedora14, fedora13
|
||||
# rather than
|
||||
# debian4, debian5, fedora13, fedora14
|
||||
for distro_list in distro_mappings.values():
|
||||
for distro_list in list(distro_mappings.values()):
|
||||
distro_list.sort()
|
||||
distro_list.reverse()
|
||||
|
||||
# Move the sortpref values to the front of the list
|
||||
sorted_distro_list = distro_mappings.keys()
|
||||
sorted_distro_list = list(distro_mappings.keys())
|
||||
sorted_distro_list.sort()
|
||||
sortpref.reverse()
|
||||
for prefer in sortpref:
|
||||
|
@ -50,7 +50,7 @@ def _new_poll_helper(origmap, typename, listfunc, buildfunc):
|
||||
current[connkey] = origmap[connkey]
|
||||
del(origmap[connkey])
|
||||
|
||||
return (origmap.values(), new.values(), current.values())
|
||||
return (list(origmap.values()), list(new.values()), list(current.values()))
|
||||
|
||||
|
||||
def _old_poll_helper(origmap, typename,
|
||||
@ -108,7 +108,7 @@ def _old_poll_helper(origmap, typename,
|
||||
except Exception:
|
||||
logging.exception("Couldn't fetch %s '%s'", typename, name)
|
||||
|
||||
return (origmap.values(), new.values(), current.values())
|
||||
return (list(origmap.values()), list(new.values()), list(current.values()))
|
||||
|
||||
|
||||
def fetch_nets(backend, origmap, build_func):
|
||||
@ -209,7 +209,7 @@ def _old_fetch_vms(backend, origmap, build_func):
|
||||
new = {}
|
||||
|
||||
# Build list of previous vms with proper id/name mappings
|
||||
for vm in origmap.values():
|
||||
for vm in list(origmap.values()):
|
||||
if vm.is_active():
|
||||
oldActiveIDs[vm.get_id()] = vm
|
||||
else:
|
||||
@ -272,7 +272,7 @@ def _old_fetch_vms(backend, origmap, build_func):
|
||||
except Exception:
|
||||
logging.exception("Couldn't fetch domain '%s'", name)
|
||||
|
||||
return (origmap.values(), new.values(), current.values())
|
||||
return (list(origmap.values()), list(new.values()), list(current.values()))
|
||||
|
||||
|
||||
def fetch_vms(backend, origmap, build_func):
|
||||
|
@ -130,7 +130,7 @@ class StoragePool(_StorageObject):
|
||||
"""
|
||||
Return list of appropriate pool types
|
||||
"""
|
||||
return StoragePool._descs.keys()
|
||||
return list(StoragePool._descs.keys())
|
||||
|
||||
@staticmethod
|
||||
def get_pool_type_desc(pool_type):
|
||||
|
@ -167,7 +167,7 @@ class _SupportCheck(object):
|
||||
self.hv_version = hv_version or {}
|
||||
self.hv_libvirt_version = hv_libvirt_version or {}
|
||||
|
||||
versions = ([self.version] + self.hv_libvirt_version.values())
|
||||
versions = ([self.version] + list(self.hv_libvirt_version.values()))
|
||||
for vstr in versions:
|
||||
v = _version_str_to_int(vstr)
|
||||
if vstr is not None and v != 0 and v < 7009:
|
||||
|
@ -1382,7 +1382,7 @@ class ALTLinuxDistro(Distro):
|
||||
# Build list of all *Distro classes
|
||||
def _build_distro_list():
|
||||
allstores = []
|
||||
for obj in globals().values():
|
||||
for obj in list(globals().values()):
|
||||
if isinstance(obj, type) and issubclass(obj, Distro) and obj.name:
|
||||
allstores.append(obj)
|
||||
|
||||
|
@ -843,7 +843,7 @@ class XMLBuilder(object):
|
||||
def _initial_child_parse(self):
|
||||
# Walk the XML tree and hand of parsing to any registered
|
||||
# child classes
|
||||
for xmlprop in self._all_child_props().values():
|
||||
for xmlprop in list(self._all_child_props().values()):
|
||||
if xmlprop.is_single:
|
||||
child_class = xmlprop.child_classes[0]
|
||||
prop_path = xmlprop.get_prop_xpath(self, child_class)
|
||||
@ -926,8 +926,8 @@ class XMLBuilder(object):
|
||||
if leave_stub:
|
||||
_top_node = _get_xpath_node(self._xmlstate.xml_ctx,
|
||||
self.get_root_xpath())
|
||||
props = self._all_xml_props().values()
|
||||
props += self._all_child_props().values()
|
||||
props = list(self._all_xml_props().values())
|
||||
props += list(self._all_child_props().values())
|
||||
for prop in props:
|
||||
prop.clear(self)
|
||||
finally:
|
||||
@ -1025,7 +1025,7 @@ class XMLBuilder(object):
|
||||
|
||||
def _find_child_prop(self, child_class, return_single=False):
|
||||
xmlprops = self._all_child_props()
|
||||
for xmlprop in xmlprops.values():
|
||||
for xmlprop in list(xmlprops.values()):
|
||||
if xmlprop.is_single and not return_single:
|
||||
continue
|
||||
if child_class in xmlprop.child_classes:
|
||||
@ -1084,7 +1084,7 @@ class XMLBuilder(object):
|
||||
Return a list of all XML child objects with the passed class
|
||||
"""
|
||||
ret = []
|
||||
for prop in self._all_child_props().values():
|
||||
for prop in list(self._all_child_props().values()):
|
||||
ret += [obj for obj in util.listify(prop._get(self))
|
||||
if obj.__class__ == klass]
|
||||
return ret
|
||||
@ -1165,7 +1165,7 @@ class XMLBuilder(object):
|
||||
xmlprops = self._all_xml_props()
|
||||
childprops = self._all_child_props()
|
||||
|
||||
for prop in xmlprops.values():
|
||||
for prop in list(xmlprops.values()):
|
||||
prop._set_default(self)
|
||||
|
||||
# Set up preferred XML ordering
|
||||
@ -1180,7 +1180,7 @@ class XMLBuilder(object):
|
||||
elif key in childprops:
|
||||
do_order.insert(0, key)
|
||||
|
||||
for key in childprops.keys():
|
||||
for key in list(childprops.keys()):
|
||||
if key not in do_order:
|
||||
do_order.append(key)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user