From: Loic Dachary Date: Mon, 30 Dec 2013 22:07:27 +0000 (+0100) Subject: ceph-disk: which() uses PATH first X-Git-Tag: v0.67.6~1^2~14 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=deefb3a05788b308631812c652e9eccaeb999d7f;p=ceph.git ceph-disk: which() uses PATH first 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 (cherry picked from commit 2b935bbf60bafb6dd488c0eb30f156fce1b9d197) --- diff --git a/src/ceph-disk b/src/ceph-disk index d1c6401eb2c3..6df02ab01e4e 100755 --- a/src/ceph-disk +++ b/src/ceph-disk @@ -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)