From a9334a1c8c6681305e76b361377864d0dd1e3d34 Mon Sep 17 00:00:00 2001 From: Alfredo Deza Date: Thu, 12 Dec 2013 11:16:38 -0500 Subject: [PATCH] use the absolute path for executables if found Signed-off-by: Alfredo Deza --- src/ceph-disk | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/ceph-disk b/src/ceph-disk index dcf45faef90..c76d2f0dfbd 100755 --- a/src/ceph-disk +++ b/src/ceph-disk @@ -227,14 +227,23 @@ def which(executable): return executable_path -def _check_command_executable(arguments): - """raise if the executable is not found""" +def _get_command_executable(arguments): + """ + Return the full path for an executable, raise if the executable is not + found. If the executable has already a full path do not perform any checks. + """ + if arguments[0].startswith('/'): # an absolute path + return arguments executable = which(arguments[0]) if not executable: command_msg = 'Could not run command: %s' % ' '.join(arguments) executable_msg = '%s not in path.' % arguments[0] raise ExecutableNotFound('%s %s' % (executable_msg, command_msg)) + # swap the old executable for the new one + arguments[0] = executable + return arguments + def command(arguments): """ @@ -246,7 +255,7 @@ def command(arguments): since it provides the caller with the safety net of making sure that executables *will* be found and will error nicely otherwise. """ - _check_command_executable(arguments) + arguments = _get_command_executable(arguments) return subprocess.Popen( arguments,