File virtinst-python2-to-python3-conversion.patch of Package virt-manager.7890

Index: virt-manager-1.5.1/virt-install
===================================================================
--- virt-manager-1.5.1.orig/virt-install
+++ virt-manager-1.5.1/virt-install
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2
+#!/usr/bin/python3
 #
 # Copyright 2005-2014 Red Hat, Inc.
 #
Index: virt-manager-1.5.1/virtinst/uri.py
===================================================================
--- virt-manager-1.5.1.orig/virtinst/uri.py
+++ virt-manager-1.5.1/virtinst/uri.py
@@ -19,7 +19,7 @@
 
 import logging
 import re
-import urllib
+import urllib.request, urllib.parse, urllib.error
 
 from .cli import parse_optstr_tuples
 
@@ -47,7 +47,7 @@ class URI(object):
     """
     def __init__(self, uri):
         self.uri = uri
-        unquoted_uri = urllib.unquote(uri)
+        unquoted_uri = urllib.parse.unquote(uri)
 
         (self.scheme, self.username, self.hostname,
          self.path, self.query, self.fragment) = self._split(unquoted_uri)
Index: virt-manager-1.5.1/virtinst/hostkeymap.py
===================================================================
--- virt-manager-1.5.1.orig/virtinst/hostkeymap.py
+++ virt-manager-1.5.1/virtinst/hostkeymap.py
@@ -20,6 +20,7 @@
 import logging
 import os
 import re
+import functools
 
 
 _ETC_VCONSOLE = "/etc/vconsole.conf"
@@ -202,7 +203,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()), key=functools.cmp_to_key(len_cmp))
 
     for key in sorted_keys:
         origkey = key
Index: virt-manager-1.5.1/virtinst/support.py
===================================================================
--- virt-manager-1.5.1.orig/virtinst/support.py
+++ virt-manager-1.5.1/virtinst/support.py
@@ -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:
Index: virt-manager-1.5.1/virtinst/osdict.py
===================================================================
--- virt-manager-1.5.1.orig/virtinst/osdict.py
+++ virt-manager-1.5.1/virtinst/osdict.py
@@ -79,7 +79,7 @@ def _sort(tosort, sortpref=None, limit_p
     retlist = []
     sortpref = sortpref or []
 
-    for key, osinfo in tosort.items():
+    for key, osinfo in list(tosort.items()):
         # Libosinfo has some duplicate version numbers here, so append .1
         # if there's a collision
         sortby = osinfo.sortby
@@ -98,12 +98,12 @@ def _sort(tosort, sortpref=None, limit_p
     # 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:
@@ -264,7 +264,7 @@ class _OSDB(object):
         """
         sortmap = {}
 
-        for name, osobj in self._all_variants.items():
+        for name, osobj in list(self._all_variants.items()):
             if typename and typename != osobj.get_typename():
                 continue
             if only_supported and not osobj.get_supported():
Index: virt-manager-1.5.1/virtinst/guest.py
===================================================================
--- virt-manager-1.5.1.orig/virtinst/guest.py
+++ virt-manager-1.5.1/virtinst/guest.py
@@ -434,7 +434,7 @@ class Guest(XMLBuilder):
                 domain.undefine()
             except Exception:
                 pass
-            raise exc_info[0], exc_info[1], exc_info[2]
+            raise exc_info[0](exc_info[1]).with_traceback(exc_info[2])
 
         if install_xml and install_xml != final_xml:
             domain = self.conn.defineXML(final_xml)
@@ -1099,7 +1099,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
 
Index: virt-manager-1.5.1/virtinst/distroinstaller.py
===================================================================
--- virt-manager-1.5.1.orig/virtinst/distroinstaller.py
+++ virt-manager-1.5.1/virtinst/distroinstaller.py
@@ -68,7 +68,7 @@ def _sanitize_url(url):
  MEDIA_LOCATION_URL,
  MEDIA_CDROM_PATH,
  MEDIA_CDROM_URL,
- MEDIA_CDROM_IMPLIED) = range(1, 7)
+ MEDIA_CDROM_IMPLIED) = list(range(1, 7))
 
 
 class DistroInstaller(Installer):
Index: virt-manager-1.5.1/virtinst/cli.py
===================================================================
--- virt-manager-1.5.1.orig/virtinst/cli.py
+++ virt-manager-1.5.1/virtinst/cli.py
@@ -19,7 +19,7 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 # MA 02110-1301 USA.
 
-from __future__ import print_function
+
 
 import argparse
 import collections
@@ -294,7 +294,7 @@ def _do_creds_authname(creds):
 
         res = cred[retindex]
         if credtype == libvirt.VIR_CRED_AUTHNAME:
-            res = raw_input(prompt)
+            res = input(prompt)
         elif credtype == libvirt.VIR_CRED_PASSPHRASE:
             import getpass
             res = getpass.getpass(prompt)
@@ -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
 
Index: virt-manager-1.5.1/virtinst/xmlbuilder.py
===================================================================
--- virt-manager-1.5.1.orig/virtinst/xmlbuilder.py
+++ virt-manager-1.5.1/virtinst/xmlbuilder.py
@@ -327,7 +327,7 @@ class XMLChildProperty(property):
 
     def _findpropname(self, xmlbuilder):
         if self._propname is None:
-            for key, val in xmlbuilder._all_child_props().items():
+            for key, val in list(xmlbuilder._all_child_props().items()):
                 if val is self:
                     self._propname = key
                     break
@@ -475,7 +475,7 @@ class XMLProperty(property):
         as in the XMLBuilder class. This is just for debug purposes.
         """
         if self._propname is None:
-            for key, val in xmlbuilder._all_xml_props().items():
+            for key, val in list(xmlbuilder._all_xml_props().items()):
                 if val is self:
                     self._propname = key
                     break
@@ -832,7 +832,7 @@ class XMLBuilder(object):
         self.conn = conn
 
         if self._XML_SANITIZE:
-            parsexml = parsexml.decode('ascii', 'ignore').encode('ascii')
+            #parsexml = parsexml.decode('ascii', 'ignore').encode('ascii')
             parsexml = "".join([c for c in parsexml if c in string.printable])
 
         self._propstore = {}
@@ -846,7 +846,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)
@@ -888,7 +888,7 @@ class XMLBuilder(object):
 
         # XMLChildProperty stores a list in propstore, which dict shallow
         # copy won't fix for us.
-        for name, value in ret._propstore.items():
+        for name, value in list(ret._propstore.items()):
             if not isinstance(value, list):
                 continue
             ret._propstore[name] = [obj.copy() for obj in ret._propstore[name]]
@@ -929,8 +929,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:
@@ -993,7 +993,7 @@ class XMLBuilder(object):
         if not hasattr(self.__class__, cachename):
             ret = {}
             for c in reversed(type.mro(self.__class__)[:-1]):
-                for key, val in c.__dict__.items():
+                for key, val in list(c.__dict__.items()):
                     if isinstance(val, checkclass):
                         ret[key] = val
             setattr(self.__class__, cachename, ret)
@@ -1028,7 +1028,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:
@@ -1087,7 +1087,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
@@ -1110,7 +1110,7 @@ class XMLBuilder(object):
         xpaths point at their particular element
         """
         typecount = {}
-        for propname, xmlprop in self._all_child_props().items():
+        for propname, xmlprop in list(self._all_child_props().items()):
             for obj in util.listify(getattr(self, propname)):
                 idxstr = ""
                 if not xmlprop.is_single:
@@ -1168,7 +1168,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
@@ -1183,7 +1183,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)
 
Index: virt-manager-1.5.1/virtinst/domcapabilities.py
===================================================================
--- virt-manager-1.5.1.orig/virtinst/domcapabilities.py
+++ virt-manager-1.5.1/virtinst/domcapabilities.py
@@ -166,7 +166,7 @@ class DomainCapabilities(XMLBuilder):
                 return _("BIOS")
             return _("None")
 
-        for arch, patterns in self._uefi_arch_patterns.items():
+        for arch, patterns in list(self._uefi_arch_patterns.items()):
             for pattern in patterns:
                 if re.match(pattern, path):
                     return (_("UEFI %(arch)s: %(path)s") %
@@ -178,7 +178,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):
         """
Index: virt-manager-1.5.1/virtinst/devicedisk.py
===================================================================
--- virt-manager-1.5.1.orig/virtinst/devicedisk.py
+++ virt-manager-1.5.1/virtinst/devicedisk.py
@@ -87,7 +87,7 @@ def _is_dir_searchable(uid, username, pa
         logging.debug("Cmd '%s' failed: %s", cmd, err)
         return False
 
-    return bool(re.search("user:%s:..x" % username, out))
+    return bool(re.search("user:%s:..x" % username, out.decode()))
 
 
 class _Host(XMLBuilder):
@@ -453,7 +453,7 @@ class VirtualDisk(VirtualDevice):
                 digit = 1
 
             seen_valid = True
-            gen_t += "%c" % (ord('a') + digit - 1)
+            gen_t += "%c" % int(ord('a') + digit - 1)
 
         return gen_t
 
@@ -1054,11 +1054,11 @@ class VirtualDisk(VirtualDevice):
         def get_target():
             first_found = None
 
-            ran = range(maxnode)
+            ran = list(range(maxnode))
             if pref_ctrl is not None:
                 # We assume narrow SCSI bus and libvirt assigning 7
                 # (1-7, 8-14, etc.) devices per controller
-                ran = range(pref_ctrl * 7, (pref_ctrl + 1) * 7)
+                ran = list(range(pref_ctrl * 7, (pref_ctrl + 1) * 7))
 
             for i in ran:
                 postfix = self.num_to_target(i + 1)
Index: virt-manager-1.5.1/virtinst/storage.py
===================================================================
--- virt-manager-1.5.1.orig/virtinst/storage.py
+++ virt-manager-1.5.1/virtinst/storage.py
@@ -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):
Index: virt-manager-1.5.1/virtinst/devicegraphics.py
===================================================================
--- virt-manager-1.5.1.orig/virtinst/devicegraphics.py
+++ virt-manager-1.5.1/virtinst/devicegraphics.py
@@ -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()
Index: virt-manager-1.5.1/virtinst/util.py
===================================================================
--- virt-manager-1.5.1.orig/virtinst/util.py
+++ virt-manager-1.5.1/virtinst/util.py
@@ -147,7 +147,7 @@ def generate_name(base, collision_cb, su
         else:
             return collision_cb(tryname)
 
-    numrange = range(start_num, start_num + 100000)
+    numrange = list(range(start_num, start_num + 100000))
     if not force_num:
         numrange = [None] + numrange
 
Index: virt-manager-1.5.1/virtinst/urlfetcher.py
===================================================================
--- virt-manager-1.5.1.orig/virtinst/urlfetcher.py
+++ virt-manager-1.5.1/virtinst/urlfetcher.py
@@ -19,7 +19,7 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 # MA 02110-1301 USA.
 
-import ConfigParser
+import configparser
 import ftplib
 import io
 import logging
@@ -27,8 +27,8 @@ import os
 import re
 import subprocess
 import tempfile
-import urllib2
-import urlparse
+import urllib.request, urllib.error, urllib.parse
+import urllib.parse
 
 import requests
 
@@ -220,9 +220,13 @@ class _FTPURLFetcher(_URLFetcher):
             return
 
         try:
-            parsed = urlparse.urlparse(self.location)
+            parsed = urllib.parse.urlparse(self.location)
             self._ftp = ftplib.FTP()
-            self._ftp.connect(parsed.hostname, parsed.port)
+            if parsed.port is None:
+                port = 0
+            else:
+                port = parsed.port
+            self._ftp.connect(parsed.hostname, port)
             self._ftp.login()
             # Force binary mode
             self._ftp.voidcmd("TYPE I")
@@ -234,9 +238,9 @@ class _FTPURLFetcher(_URLFetcher):
         """
         Use urllib2 and ftplib to grab the file
         """
-        request = urllib2.Request(url)
-        urlobj = urllib2.urlopen(request)
-        size = self._ftp.size(urlparse.urlparse(url)[2])
+        request = urllib.request.Request(url)
+        urlobj = urllib.request.urlopen(request)
+        size = self._ftp.size(urllib.parse.urlparse(url)[2])
         return urlobj, size
 
 
@@ -252,7 +256,7 @@ class _FTPURLFetcher(_URLFetcher):
         self._ftp = None
 
     def _hasFile(self, url):
-        path = urlparse.urlparse(url)[2]
+        path = urllib.parse.urlparse(url)[2]
 
         try:
             try:
@@ -277,7 +281,7 @@ class _LocalURLFetcher(_URLFetcher):
         return os.path.exists(url)
 
     def _grabber(self, url):
-        urlobj = open(url, "r")
+        urlobj = open(url, "rb")
         size = os.path.getsize(url)
         return urlobj, size
 
@@ -358,6 +362,7 @@ class _ISOURLFetcher(_URLFetcher):
 
             logging.debug("Running isoinfo: %s", cmd)
             output = subprocess.check_output(cmd)
+            output = output.decode()
 
             self._cache_file_list = output.splitlines(False)
 
@@ -395,14 +400,14 @@ def _grabTreeinfo(fetcher):
         return None
 
     try:
-        treeinfo = ConfigParser.SafeConfigParser()
+        treeinfo = configparser.SafeConfigParser()
         treeinfo.read(tmptreeinfo)
     finally:
         os.unlink(tmptreeinfo)
 
     try:
         treeinfo.get("general", "family")
-    except ConfigParser.NoSectionError:
+    except configparser.NoSectionError:
         logging.debug("Did not find 'family' section in treeinfo")
         return None
 
@@ -415,11 +420,13 @@ def _distroFromSUSEContent(fetcher, arch
     # None if no content, GenericDistro if unknown label type.
     try:
         cbuf = fetcher.acquireFileContent("content")
+        cbuf = cbuf.decode()
     except ValueError:
         try:
             # If no content file, try media.1/products and media.1/build and create
             # a cbuf with enough info for the content file parsing code below to work
             pbuf = fetcher.acquireFileContent("media.1/products").strip()
+            pbuf = pbuf.decode()
             pbuf = pbuf.split(' ', 1)[1].strip()
             # The media.1/products file naming convention changed between SLE11 and SLE12
             if pbuf.startswith('SLE'):
@@ -428,6 +435,7 @@ def _distroFromSUSEContent(fetcher, arch
             cbuf = "\nDISTRO ," + pbuf.replace('-', ' ')
             try:
                 bbuf = fetcher.acquireFileContent("media.1/build").split('-')
+                bbuf = bbuf.decode()
             except:
                 bbuf = ["x86_64"]
             cbuf = cbuf + "\n" + " ".join(bbuf)
@@ -647,7 +655,7 @@ class Distro(object):
             try:
                 kernelpath = self._getTreeinfoMedia("kernel")
                 initrdpath = self._getTreeinfoMedia("initrd")
-            except ConfigParser.NoSectionError:
+            except configparser.NoSectionError:
                 pass
 
         if not kernelpath or not initrdpath:
@@ -714,6 +722,7 @@ class Distro(object):
         # Fetch 'filename' and return True/False if it matches the regex
         try:
             content = self.fetcher.acquireFileContent(filename)
+            content = content.decode()
         except ValueError:
             return False
 
@@ -783,15 +792,15 @@ class GenericDistro(Distro):
                     self._valid_kernel_path = (
                         self._getTreeinfoMedia("kernel"),
                         self._getTreeinfoMedia("initrd"))
-                except (ConfigParser.NoSectionError,
-                        ConfigParser.NoOptionError) as e:
+                except (configparser.NoSectionError,
+                        configparser.NoOptionError) as e:
                     logging.debug(e)
 
             if self.treeinfo.has_section(isoSection):
                 try:
                     self._valid_iso_path = self.treeinfo.get(isoSection,
                                                              "boot.iso")
-                except ConfigParser.NoOptionError as e:
+                except configparser.NoOptionError as e:
                     logging.debug(e)
 
         if self.type == "xen":
@@ -1477,7 +1486,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)
 
Index: virt-manager-1.5.1/virtinst/diskbackend.py
===================================================================
--- virt-manager-1.5.1.orig/virtinst/diskbackend.py
+++ virt-manager-1.5.1/virtinst/diskbackend.py
@@ -391,7 +391,7 @@ class CloneStorageCreator(_StorageCreato
         else:
             vfs = os.statvfs(os.path.dirname(self._path))
             avail = vfs.f_frsize * vfs.f_bavail
-        need = long(self._size * 1024 * 1024 * 1024)
+        need = int(self._size * 1024 * 1024 * 1024)
         if need > avail:
             if self._sparse:
                 msg = _("The filesystem will not have enough free space"
@@ -411,7 +411,7 @@ class CloneStorageCreator(_StorageCreato
         text = (_("Cloning %(srcfile)s") %
                 {'srcfile': os.path.basename(self._input_path)})
 
-        size_bytes = long(self.get_size() * 1024 * 1024 * 1024)
+        size_bytes = int(self.get_size() * 1024 * 1024 * 1024)
         progresscb.start(filename=self._output_path, size=size_bytes,
                          text=text)
 
Index: virt-manager-1.5.1/virtinst/progress.py
===================================================================
--- virt-manager-1.5.1.orig/virtinst/progress.py
+++ virt-manager-1.5.1/virtinst/progress.py
@@ -481,7 +481,7 @@ def format_number(number, SI=0, space='
         depth  = depth + 1
         number = number / step
 
-    if isinstance(number, int) or isinstance(number, long):
+    if isinstance(number, int) or isinstance(number, int):
         # it's an int or a long, which means it didn't get divided,
         # which means it's already short enough
         fmt = '%i%s%s'
Index: virt-manager-1.5.1/virtinst/pollhelpers.py
===================================================================
--- virt-manager-1.5.1.orig/virtinst/pollhelpers.py
+++ virt-manager-1.5.1/virtinst/pollhelpers.py
@@ -50,7 +50,7 @@ def _new_poll_helper(origmap, typename,
             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):
@@ -143,7 +143,7 @@ def fetch_pools(backend, origmap, build_
         for obj in objs:
             try:
                 obj.refresh(0)
-            except Exception, e:
+            except Exception as e:
                 pass
 
         return _new_poll_helper(origmap, name,
@@ -222,7 +222,7 @@ def _old_fetch_vms(backend, origmap, bui
     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:
@@ -285,7 +285,7 @@ def _old_fetch_vms(backend, origmap, bui
             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):
openSUSE Build Service is sponsored by