]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-disk: which() uses PATH first
authorLoic Dachary <loic@dachary.org>
Mon, 30 Dec 2013 22:07:27 +0000 (23:07 +0100)
committerAlfredo Deza <alfredo@deza.pe>
Wed, 12 Feb 2014 21:17:11 +0000 (16:17 -0500)
Instead of relying on a hardcoded set of if paths. Although this has the
potential of changing the location of the binary being used by ceph-disk
on an existing installation, it is currently only used for sgdisk. It
could be disruptive for someone using a modified version of sgdisk but
the odds of this happening are very low.

Signed-off-by: Loic Dachary <loic@dachary.org>
(cherry picked from commit 2b935bbf60bafb6dd488c0eb30f156fce1b9d197)

src/ceph-disk

index d1c6401eb2c31deeceda67bcd359725b59613345..6df02ab01e4e619775af48d5022bee95c64b3390 100755 (executable)
@@ -211,14 +211,20 @@ def maybe_mkdir(*a, **kw):
 
 def which(executable):
     """find the location of an executable"""
-    locations = (
+    if 'PATH' in os.environ:
+        envpath = os.environ['PATH']
+    else:
+        envpath = os.defpath
+    PATH = envpath.split(os.pathsep)
+
+    locations = PATH + [
         '/usr/local/bin',
         '/bin',
         '/usr/bin',
         '/usr/local/sbin',
         '/usr/sbin',
         '/sbin',
-    )
+    ]
 
     for location in locations:
         executable_path = os.path.join(location, executable)