[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[PATCH] Search for iscsid in the $PATH, not in a hardcoded list of places (#645523).



While I'm at it, add a method that searches the $PATH and get rid of the
various other places we were doing this.
---
 pyanaconda/iutil.py                  |    8 ++++++++
 pyanaconda/storage/devicelibs/lvm.py |   14 +++-----------
 pyanaconda/storage/formats/fs.py     |    8 ++------
 pyanaconda/storage/iscsi.py          |   13 ++++---------
 4 files changed, 17 insertions(+), 26 deletions(-)

diff --git a/pyanaconda/iutil.py b/pyanaconda/iutil.py
index b07f9ed..1c5bb5b 100644
--- a/pyanaconda/iutil.py
+++ b/pyanaconda/iutil.py
@@ -1119,3 +1119,11 @@ def get_sysfs_attr(path, attr):
         return None
 
     return open(attribute, "r").read().strip()
+
+def find_program_in_path(prog):
+    for d in os.environ["PATH"].split(":"):
+        full = "%s/%s" % (d, prog)
+        if os.access(full, os.X_OK):
+            return full
+
+    return None
diff --git a/pyanaconda/storage/devicelibs/lvm.py b/pyanaconda/storage/devicelibs/lvm.py
index d0ff1bf..79615e8 100644
--- a/pyanaconda/storage/devicelibs/lvm.py
+++ b/pyanaconda/storage/devicelibs/lvm.py
@@ -37,20 +37,12 @@ _ = lambda x: gettext.ldgettext("anaconda", x)
 MAX_LV_SLOTS = 256
 
 def has_lvm():
-    has_lvm = False
-    for path in os.environ["PATH"].split(":"):
-        if os.access("%s/lvm" % path, os.X_OK):
-            has_lvm = True
-            break
-
-    if has_lvm:
-        has_lvm = False
+    if iutil.find_program_in_path("lvm"):
         for line in open("/proc/devices").readlines():
             if "device-mapper" in line.split():
-                has_lvm = True
-                break
+                return True
 
-    return has_lvm
+    return False
 
 # Start config_args handling code
 #
diff --git a/pyanaconda/storage/formats/fs.py b/pyanaconda/storage/formats/fs.py
index d9e3ee4..dca7f1a 100644
--- a/pyanaconda/storage/formats/fs.py
+++ b/pyanaconda/storage/formats/fs.py
@@ -734,8 +734,7 @@ class FS(DeviceFormat):
             if not prog:
                 continue
 
-            if not filter(lambda d: os.access("%s/%s" % (d, prog), os.X_OK),
-                          os.environ["PATH"].split(":")):
+            if not iutil.find_program_in_path(prog):
                 return False
 
         return True
@@ -804,10 +803,7 @@ class FS(DeviceFormat):
     def _isMigratable(self):
         """ Can filesystems of this type be migrated? """
         return bool(self._migratable and self.migratefsProg and
-                    filter(lambda d: os.access("%s/%s"
-                                               % (d, self.migratefsProg,),
-                                               os.X_OK),
-                           os.environ["PATH"].split(":")) and
+                    iutil.find_program_in_path(self.migratefsProg) is not None and
                     self.migrationTarget)
 
     migratable = property(_isMigratable)
diff --git a/pyanaconda/storage/iscsi.py b/pyanaconda/storage/iscsi.py
index 59d9008..e1b203c 100644
--- a/pyanaconda/storage/iscsi.py
+++ b/pyanaconda/storage/iscsi.py
@@ -43,16 +43,11 @@ except ImportError:
 ISCSID=""
 INITIATOR_FILE="/etc/iscsi/initiatorname.iscsi"
 
-def find_iscsi_files():
-    global ISCSID
-    if ISCSID == "":
-        for dir in ("/usr/sbin", "/tmp/updates", "/mnt/source/RHupdates"):
-            path="%s/iscsid" % (dir,)
-            if os.access(path, os.X_OK):
-                ISCSID=path
-
 def has_iscsi():
-    find_iscsi_files()
+    location = iutil.find_program_in_path("iscsid")
+    if location:
+        ISCSID = location
+
     if ISCSID == "" or not has_libiscsi:
         return False
 
-- 
1.7.1.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]