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)
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)