Blame SOURCES/0015-relative-imports-don-t-work-on-both-Python-2-and-3.patch

1070a0
From f565382b5291409ac1ab4a96494c566cd9a4dfd4 Mon Sep 17 00:00:00 2001
1070a0
From: Jan Dobes <jdobes@redhat.com>
1070a0
Date: Wed, 18 Oct 2017 13:18:24 +0200
1070a0
Subject: [PATCH 15/17] relative imports don't work on both Python 2 and 3
1070a0
1070a0
(cherry picked from commit a2339d3a544c0cfbec6cfc5437942a79abe4bd30)
1070a0
1070a0
Conflicts:
1070a0
  koan/app.py
1070a0
  koan/utils.py
1070a0
  koan/virtinstall.py
1070a0
---
1070a0
 koan/app.py              | 34 +++++++++-------------------------
1070a0
 koan/imagecreate.py      |  7 ++++---
1070a0
 koan/qcreate.py          | 11 ++++++-----
1070a0
 koan/register.py         |  6 +++---
1070a0
 koan/utils.py            |  6 ++++--
1070a0
 koan/virtinstall.py      | 27 ++++++++++++++-------------
1070a0
 koan/vmwcreate.py        |  4 ++--
1070a0
 koan/xencreate.py        |  7 ++++---
1070a0
 scripts/cobbler-register |  2 +-
1070a0
 scripts/koan             |  2 +-
1070a0
 10 files changed, 48 insertions(+), 58 deletions(-)
1070a0
1070a0
diff --git a/koan/app.py b/koan/app.py
1070a0
index 4ae4c90..f5af5e9 100755
1070a0
--- a/koan/app.py
1070a0
+++ b/koan/app.py
1070a0
@@ -41,7 +41,7 @@ try: #python2
1070a0
 except ImportError: #python3
1070a0
     import xmlrpc.client as xmlrpclib
1070a0
 import re
1070a0
-from . import utils
1070a0
+from koan import utils
1070a0
 
1070a0
 COBBLER_REQUIRED = 1.300
1070a0
 
1070a0
@@ -228,22 +228,6 @@ def main():
1070a0
 #=======================================================
1070a0
 
1070a0
 
1070a0
-class KoanException(Exception):
1070a0
-
1070a0
-    def __init__(self, value, *args):
1070a0
-        self.value = value % args
1070a0
-        # this is a hack to work around some odd exception handling
1070a0
-        # in older pythons
1070a0
-        self.from_koan = 1
1070a0
-
1070a0
-    def __str__(self):
1070a0
-        return repr(self.value)
1070a0
-
1070a0
-
1070a0
-class KX(KoanException):
1070a0
-    pass
1070a0
-
1070a0
-
1070a0
 class InfoException(Exception):
1070a0
     """
1070a0
     Custom exception for tracking of fatal errors.
1070a0
@@ -1145,9 +1129,9 @@ class Koan:
1070a0
         """
1070a0
         pd = profile_data
1070a0
         # importing can't throw exceptions any more, don't put it in a sub-method
1070a0
-        from . import xencreate
1070a0
-        from . import qcreate
1070a0
-        from . import imagecreate
1070a0
+        from koan import xencreate
1070a0
+        from koan import qcreate
1070a0
+        from koan import imagecreate
1070a0
 
1070a0
         arch                          = self.safe_load(pd,'arch','x86')
1070a0
         kextra                        = self.calc_kernel_args(pd)
1070a0
@@ -1232,11 +1216,11 @@ class Koan:
1070a0
         if (self.image is not None) and (pd["image_type"] == "virt-clone"):
1070a0
             fullvirt = True
1070a0
             uuid = None
1070a0
-            from . import imagecreate
1070a0
+            from koan import imagecreate
1070a0
             creator = imagecreate.start_install
1070a0
         elif self.virt_type in [ "xenpv", "xenfv" ]:
1070a0
             uuid    = self.get_uuid(self.calc_virt_uuid(pd))
1070a0
-            from . import xencreate
1070a0
+            from koan import xencreate
1070a0
             creator = xencreate.start_install
1070a0
             if self.virt_type == "xenfv":
1070a0
                fullvirt = True 
1070a0
@@ -1244,15 +1228,15 @@ class Koan:
1070a0
         elif self.virt_type == "qemu":
1070a0
             fullvirt = True
1070a0
             uuid    = None
1070a0
-            from . import qcreate
1070a0
+            from koan import qcreate
1070a0
             creator = qcreate.start_install
1070a0
             can_poll = "qemu"
1070a0
         elif self.virt_type == "vmware":
1070a0
-            from . import vmwcreate
1070a0
+            from koan import vmwcreate
1070a0
             uuid = None
1070a0
             creator = vmwcreate.start_install
1070a0
         elif self.virt_type == "vmwarew":
1070a0
-            from . import vmwwcreate
1070a0
+            from koan import vmwwcreate
1070a0
             uuid = None
1070a0
             creator = vmwwcreate.start_install
1070a0
         else:
1070a0
diff --git a/koan/imagecreate.py b/koan/imagecreate.py
1070a0
index d70d519..9b98f74 100644
1070a0
--- a/koan/imagecreate.py
1070a0
+++ b/koan/imagecreate.py
1070a0
@@ -23,9 +23,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
1070a0
 02110-1301  USA
1070a0
 """
1070a0
 
1070a0
-from . import utils
1070a0
-from . import virtinstall
1070a0
+from koan.utils import subprocess_call
1070a0
+from koan import virtinstall
1070a0
+
1070a0
 
1070a0
 def start_install(*args, **kwargs):
1070a0
     cmd = virtinstall.build_commandline("import", *args, **kwargs)
1070a0
-    utils.subprocess_call(cmd)
1070a0
+    subprocess_call(cmd)
1070a0
diff --git a/koan/qcreate.py b/koan/qcreate.py
1070a0
index d0bafae..73b6abb 100755
1070a0
--- a/koan/qcreate.py
1070a0
+++ b/koan/qcreate.py
1070a0
@@ -23,10 +23,11 @@ module for creating fullvirt guests via KVM/kqemu/qemu
1070a0
 requires python-virtinst-0.200 (or virt-install in later distros).
1070a0
 """
1070a0
 
1070a0
-from . import utils
1070a0
-from . import virtinstall
1070a0
 from xml.dom.minidom import parseString
1070a0
-from . import app as koan
1070a0
+from koan.utils import subprocess_call
1070a0
+from koan import virtinstall
1070a0
+from koan import app
1070a0
+
1070a0
 
1070a0
 def start_install(*args, **kwargs):
1070a0
     # See http://post-office.corp.redhat.com/archives/satellite-dept-list/2013-December/msg00039.html for discussion on this hack.
1070a0
@@ -37,7 +38,7 @@ def start_install(*args, **kwargs):
1070a0
     try:
1070a0
         import libvirt
1070a0
     except:
1070a0
-        raise koan.InfoException("package libvirt is required for installing virtual guests")
1070a0
+        raise app.InfoException("package libvirt is required for installing virtual guests")
1070a0
     conn = libvirt.openReadOnly(None)
1070a0
     # See http://libvirt.org/formatcaps.html
1070a0
     capabilities = parseString(conn.getCapabilities())
1070a0
@@ -49,4 +50,4 @@ def start_install(*args, **kwargs):
1070a0
 
1070a0
     virtinstall.create_image_file(*args, **kwargs)
1070a0
     cmd = virtinstall.build_commandline("qemu:///system", *args, **kwargs)
1070a0
-    utils.subprocess_call(cmd)
1070a0
+    subprocess_call(cmd)
1070a0
diff --git a/koan/register.py b/koan/register.py
1070a0
index a69f2d1..8ce7db3 100755
1070a0
--- a/koan/register.py
1070a0
+++ b/koan/register.py
1070a0
@@ -30,7 +30,7 @@ try: #python2
1070a0
 except ImportError: #python3
1070a0
     import xmlrpc.client as xmlrpclib
1070a0
 import socket
1070a0
-from . import utils
1070a0
+from koan.utils import connect_to_server, get_network_info
1070a0
 
1070a0
 # usage: cobbler-register [--server=server] [--hostname=hostname] --profile=foo
1070a0
 
1070a0
@@ -127,10 +127,10 @@ class Register:
1070a0
            raise InfoException("root access is required to register")
1070a0
  
1070a0
         print("- preparing to koan home")
1070a0
-        self.conn = utils.connect_to_server(self.server, self.port)
1070a0
+        self.conn = connect_to_server(self.server, self.port)
1070a0
         reg_info = {}
1070a0
         print("- gathering network info")
1070a0
-        netinfo = utils.get_network_info()
1070a0
+        netinfo = get_network_info()
1070a0
         reg_info["interfaces"] = netinfo
1070a0
         print("- checking hostname")
1070a0
         sysname = ""
1070a0
diff --git a/koan/utils.py b/koan/utils.py
1070a0
index 12ec718..607db1f 100644
1070a0
--- a/koan/utils.py
1070a0
+++ b/koan/utils.py
1070a0
@@ -44,6 +44,7 @@ VIRT_STATE_NAME_MAP = {
1070a0
    6 : "crashed"
1070a0
 }
1070a0
 
1070a0
+
1070a0
 class InfoException(Exception):
1070a0
     """
1070a0
     Custom exception for tracking of fatal errors.
1070a0
@@ -54,6 +55,7 @@ class InfoException(Exception):
1070a0
     def __str__(self):
1070a0
         return repr(self.value)
1070a0
 
1070a0
+
1070a0
 def setupLogging(appname):
1070a0
     """
1070a0
     set up logging ... code borrowed/adapted from virt-manager
1070a0
@@ -253,7 +255,7 @@ def nfsmount(input_path):
1070a0
     rc = sub_process.call(mount_cmd)
1070a0
     if not rc == 0:
1070a0
         shutil.rmtree(tempdir, ignore_errors=True)
1070a0
-        raise koan.InfoException("nfs mount failed: %s" % dirpath)
1070a0
+        raise InfoException("nfs mount failed: %s" % dirpath)
1070a0
     # NOTE: option for a blocking install might be nice, so we could do this
1070a0
     # automatically, if supported by virt-install
1070a0
     print("after install completes, you may unmount and delete %s" % tempdir)
1070a0
@@ -333,7 +335,7 @@ def os_release():
1070a0
              return (make,float(t))
1070a0
          except ValueError:
1070a0
              pass
1070a0
-      raise koan.KX("failed to detect local OS version from /etc/redhat-release")
1070a0
+      raise InfoException("failed to detect local OS version from /etc/redhat-release")
1070a0
 
1070a0
    elif check_dist() == "debian":
1070a0
       fd = open("/etc/debian_version")
1070a0
diff --git a/koan/virtinstall.py b/koan/virtinstall.py
1070a0
index 5359b2a..ce6c425 100644
1070a0
--- a/koan/virtinstall.py
1070a0
+++ b/koan/virtinstall.py
1070a0
@@ -30,15 +30,15 @@ import os
1070a0
 import re
1070a0
 import shlex
1070a0
 
1070a0
-from . import app as koan
1070a0
-from . import utils
1070a0
+from koan import app
1070a0
+from koan.utils import subprocess_get_response, nfsmount, make_floppy
1070a0
 
1070a0
 # The virtinst module will no longer be availabe to import in some
1070a0
 # distros. We need to get all the info we need from the virt-install
1070a0
 # command line tool. This should work on both old and new variants,
1070a0
 # as the virt-install command line tool has always been provided by
1070a0
 # python-virtinst (and now the new virt-install rpm).
1070a0
-rc, response = utils.subprocess_get_response(
1070a0
+rc, response = subprocess_get_response(
1070a0
         shlex.split('virt-install --version'), True)
1070a0
 if rc == 0:
1070a0
     virtinst_version = response
1070a0
@@ -63,7 +63,7 @@ try:
1070a0
             supported_variants.add(variant)
1070a0
 except:
1070a0
     try:
1070a0
-        rc, response = utils.subprocess_get_response(
1070a0
+        rc, response = subprocess_get_response(
1070a0
                 shlex.split('virt-install --os-variant list'))
1070a0
         variants = response.split('\n')
1070a0
         for variant in variants:
1070a0
@@ -90,7 +90,7 @@ def _sanitize_disks(disks):
1070a0
         if d[1] != 0 or d[0].startswith("/dev"):
1070a0
             ret.append((d[0], d[1], driver_type))
1070a0
         else:
1070a0
-            raise koan.InfoException("this virtualization type does not work without a disk image, set virt-size in Cobbler to non-zero")
1070a0
+            raise app.InfoException("this virtualization type does not work without a disk image, set virt-size in Cobbler to non-zero")
1070a0
 
1070a0
     return ret
1070a0
 
1070a0
@@ -128,7 +128,7 @@ def _sanitize_nics(nics, bridge, profile_bridge, network_count):
1070a0
             intf_bridge = intf["virt_bridge"]
1070a0
             if intf_bridge == "":
1070a0
                 if profile_bridge == "":
1070a0
-                    raise koan.InfoException("virt-bridge setting is not defined in cobbler")
1070a0
+                    raise app.InfoException("virt-bridge setting is not defined in cobbler")
1070a0
                 intf_bridge = profile_bridge
1070a0
 
1070a0
         else:
1070a0
@@ -151,7 +151,8 @@ def create_image_file(disks=None, **kwargs):
1070a0
             continue
1070a0
         if str(size) == "0":
1070a0
             continue
1070a0
-        utils.create_qemu_image_file(path, size, driver_type)
1070a0
+        # This method doesn't exist and this functionality is probably broken
1070a0
+        # create_qemu_image_file(path, size, driver_type)
1070a0
 
1070a0
 def build_commandline(uri,
1070a0
                       name=None,
1070a0
@@ -230,12 +231,12 @@ def build_commandline(uri,
1070a0
     if is_import:
1070a0
         importpath = profile_data.get("file")
1070a0
         if not importpath:
1070a0
-            raise koan.InfoException("Profile 'file' required for image "
1070a0
+            raise app.InfoException("Profile 'file' required for image "
1070a0
                                      "install")
1070a0
 
1070a0
     elif "file" in profile_data:
1070a0
         if is_xen:
1070a0
-            raise koan.InfoException("Xen does not work with --image yet")
1070a0
+            raise app.InfoException("Xen does not work with --image yet")
1070a0
 
1070a0
         # this is an image based installation
1070a0
         input_path = profile_data["file"]
1070a0
@@ -244,7 +245,7 @@ def build_commandline(uri,
1070a0
             # this is not an NFS path
1070a0
             cdrom = input_path
1070a0
         else:
1070a0
-            (tempdir, filename) = utils.nfsmount(input_path)
1070a0
+            (tempdir, filename) = nfsmount(input_path)
1070a0
             cdrom = os.path.join(tempdir, filename)
1070a0
 
1070a0
         kickstart = profile_data.get("kickstart","")
1070a0
@@ -252,11 +253,11 @@ def build_commandline(uri,
1070a0
             # we have a (windows?) answer file we have to provide
1070a0
             # to the ISO.
1070a0
             print("I want to make a floppy for %s" % kickstart)
1070a0
-            floppy = utils.make_floppy(kickstart)
1070a0
+            floppy = make_floppy(kickstart)
1070a0
     elif is_qemu or is_xen:
1070a0
         # images don't need to source this
1070a0
         if not "install_tree" in profile_data:
1070a0
-            raise koan.InfoException("Cannot find install source in kickstart file, aborting.")
1070a0
+            raise app.InfoException("Cannot find install source in kickstart file, aborting.")
1070a0
 
1070a0
         if not profile_data["install_tree"].endswith("/"):
1070a0
             profile_data["install_tree"] = profile_data["install_tree"] + "/"
1070a0
@@ -277,7 +278,7 @@ def build_commandline(uri,
1070a0
             bridge = profile_data["virt_bridge"]
1070a0
 
1070a0
         if bridge == "":
1070a0
-            raise koan.InfoException("virt-bridge setting is not defined in cobbler")
1070a0
+            raise app.InfoException("virt-bridge setting is not defined in cobbler")
1070a0
         nics = [(bridge, None)]
1070a0
 
1070a0
 
1070a0
diff --git a/koan/vmwcreate.py b/koan/vmwcreate.py
1070a0
index 33c5819..1b90a27 100755
1070a0
--- a/koan/vmwcreate.py
1070a0
+++ b/koan/vmwcreate.py
1070a0
@@ -24,7 +24,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
1070a0
 import os
1070a0
 import random
1070a0
 
1070a0
-from . import app as koan
1070a0
+from koan import app
1070a0
 
1070a0
 IMAGE_DIR = "/var/lib/vmware/images"
1070a0
 VMX_DIR = "/var/lib/vmware/vmx"
1070a0
@@ -127,7 +127,7 @@ def start_install(name=None,
1070a0
                   virt_auto_boot=False):
1070a0
 
1070a0
     if "file" in profile_data:
1070a0
-        raise koan.InfoException("vmware does not work with --image yet")
1070a0
+        raise app.InfoException("vmware does not work with --image yet")
1070a0
 
1070a0
     mac = None
1070a0
     if not "interfaces" in profile_data:
1070a0
diff --git a/koan/xencreate.py b/koan/xencreate.py
1070a0
index 7eda3e6..18b2969 100755
1070a0
--- a/koan/xencreate.py
1070a0
+++ b/koan/xencreate.py
1070a0
@@ -26,9 +26,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
1070a0
 02110-1301  USA
1070a0
 """
1070a0
 
1070a0
-from . import utils
1070a0
-from . import virtinstall
1070a0
+from koan.utils import subprocess_call
1070a0
+from koan import virtinstall
1070a0
+
1070a0
 
1070a0
 def start_install(*args, **kwargs):
1070a0
     cmd = virtinstall.build_commandline("xen:///", *args, **kwargs)
1070a0
-    utils.subprocess_call(cmd)
1070a0
+    subprocess_call(cmd)
1070a0
diff --git a/scripts/cobbler-register b/scripts/cobbler-register
1070a0
index ed97cfc..3f2ffb1 100755
1070a0
--- a/scripts/cobbler-register
1070a0
+++ b/scripts/cobbler-register
1070a0
@@ -15,5 +15,5 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1070a0
 """
1070a0
 
1070a0
 import sys
1070a0
-import koan.register as register
1070a0
+from koan import register
1070a0
 sys.exit(register.main() or 0)
1070a0
diff --git a/scripts/koan b/scripts/koan
1070a0
index aeccb0e..9c3f445 100755
1070a0
--- a/scripts/koan
1070a0
+++ b/scripts/koan
1070a0
@@ -15,5 +15,5 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1070a0
 """
1070a0
 
1070a0
 import sys
1070a0
-import koan.app as app
1070a0
+from koan import app
1070a0
 sys.exit(app.main() or 0)
1070a0
-- 
1070a0
2.5.5
1070a0