[Kimchi-devel] [PATCH 1/4] bug fix: Identify update tool based on available system tools

Aline Manera alinefm at linux.vnet.ibm.com
Tue Mar 11 20:34:18 UTC 2014


From: Aline Manera <alinefm at br.ibm.com>

Instead of using platform.linux_distribution() and keep a list of possible
values to match, this patch verifies the tools on the system to identify
which update tool to use in Kimchi.
So try to import yum module, apt module or run the zypper command and in
last case raise an error.

Signed-off-by: Aline Manera <alinefm at br.ibm.com>
---
 src/kimchi/swupdate.py |   33 ++++++++++++++++-----------------
 1 file changed, 16 insertions(+), 17 deletions(-)

diff --git a/src/kimchi/swupdate.py b/src/kimchi/swupdate.py
index 2c2713a..ff5c9d1 100644
--- a/src/kimchi/swupdate.py
+++ b/src/kimchi/swupdate.py
@@ -17,7 +17,6 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
 
-import platform
 import subprocess
 import time
 
@@ -25,11 +24,6 @@ from kimchi.basemodel import Singleton
 from kimchi.exception import NotFoundError, OperationFailed
 from kimchi.utils import kimchi_log, run_command
 
-YUM_DISTROS = ['fedora', 'red hat enterprise linux',
-               'red hat enterprise linux server']
-APT_DISTROS = ['debian', 'ubuntu']
-ZYPPER_DISTROS = ['opensuse ', 'suse linux enterprise server ']
-
 
 class SoftwareUpdate(object):
     __metaclass__ = Singleton
@@ -51,19 +45,24 @@ class SoftwareUpdate(object):
 
         # Get the distro of host machine and creates an object related to
         # correct package management system
-        self._distro = platform.linux_distribution()[0].lower()
-        if (self._distro in YUM_DISTROS):
+        try:
+            __import__('yum')
             kimchi_log.info("Loading YumUpdate features.")
             self._pkg_mnger = YumUpdate()
-        elif (self._distro in APT_DISTROS):
-            kimchi_log.info("Loading AptUpdate features.")
-            self._pkg_mnger = AptUpdate()
-        elif (self._distro in ZYPPER_DISTROS):
-            kimchi_log.info("Loading ZypperUpdate features.")
-            self._pkg_mnger = ZypperUpdate()
-        else:
-            raise Exception("There is no compatible package manager for "
-                            "this system.")
+        except ImportError:
+            try:
+                __import__('apt')
+                kimchi_log.info("Loading AptUpdate features.")
+                self._pkg_mnger = AptUpdate()
+            except ImportError:
+                zypper_help = "zypper --help"
+                (stdout, stderr, returncode) = run_command(zypper_help)
+                if returncode == 0:
+                    kimchi_log.info("Loading ZypperUpdate features.")
+                    self._pkg_mnger = ZypperUpdate()
+                else:
+                    raise Exception("There is no compatible package manager "
+                                    "for this system.")
 
     def _scanUpdates(self):
         """
-- 
1.7.10.4




More information about the Kimchi-devel mailing list