Skip to content

Commit

Permalink
ceph-disk: which() uses PATH first
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Loic Dachary committed Jan 3, 2014
1 parent ad6b4b4 commit 2b935bb
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/ceph-disk
Expand Up @@ -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)
Expand Down

0 comments on commit 2b935bb

Please sign in to comment.