KojiDownloader can use either Koji or Brew. Currently the binary
name or full path is a mandatory argument to instantiate a
KojiDownloader class.

But systems with Brew have both '/usr/bin/brew' and '/usr/bin/koji',
(usually provided by the brewkoji package) while systems with plain
koji, only have '/usr/bin/koji'.

So, this patch adds this kind of "detection" and allows one to
simply instantiate a KojiDownloader without providing the binary
name.

Signed-off-by: Cleber Rosa <[email protected]>
---
 client/tests/kvm/kvm_utils.py |   20 +++++++++++++++-----
 1 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py
index 44ebb88..d8d3357 100644
--- a/client/tests/kvm/kvm_utils.py
+++ b/client/tests/kvm/kvm_utils.py
@@ -1539,7 +1539,12 @@ class KojiDownloader(object):
     This class provides a convenience methods to retrieve packages hosted on
     the build system.
     """
-    def __init__(self, cmd):
+
+    COMMANDS = ['/usr/bin/brew', '/usr/bin/koji' ]
+    CONFIG_MAP = {'/usr/bin/brew': '/etc/brewkoji.conf',
+                  '/usr/bin/koji': '/etc/koji.conf'}
+
+    def __init__(self, cmd=None):
         """
         Verifies whether the system has koji or brew installed, then loads
         the configuration file that will be used to download the files.
@@ -1552,6 +1557,14 @@ class KojiDownloader(object):
         if not KOJI_INSTALLED:
             raise ValueError('No koji/brew installed on the machine')
 
+        if cmd is None:
+            for command in self.COMMANDS:
+                if os.path.isfile(command):
+                    cmd = command
+                    break
+        if cmd is None:
+            raise ValueError('No koji/brew binary specified or default found')
+
         if os.path.isfile(cmd):
             koji_cmd = cmd
         else:
@@ -1559,11 +1572,8 @@ class KojiDownloader(object):
 
         logging.debug("Found %s as the buildsystem interface", koji_cmd)
 
-        config_map = {'/usr/bin/koji': '/etc/koji.conf',
-                      '/usr/bin/brew': '/etc/brewkoji.conf'}
-
         try:
-            config_file = config_map[koji_cmd]
+            config_file = self.CONFIG_MAP[koji_cmd]
         except IndexError:
             raise ValueError('Could not find config file for %s' % koji_cmd)
 
-- 
1.7.1

_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to