-
Notifications
You must be signed in to change notification settings - Fork 52
print warning and resolve to absolute path for commands specified with relative path #320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 4 commits
1b9ab12
d05d1ed
32dbd34
4b34d05
730192d
919b9ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,7 +74,7 @@ | |
| import time | ||
|
|
||
| from vsc.utils.fancylogger import getLogger | ||
| from vsc.utils.py2vs3 import ensure_ascii_string, is_py3, is_string | ||
| from vsc.utils.py2vs3 import ensure_ascii_string, is_py3, is_string, which | ||
|
|
||
| PROCESS_MODULE_ASYNCPROCESS_PATH = 'vsc.utils.asyncprocess' | ||
| PROCESS_MODULE_SUBPROCESS_PATH = 'subprocess' | ||
|
|
@@ -87,6 +87,38 @@ | |
| SHELL = BASH | ||
|
|
||
|
|
||
| def ensure_cmd_abs_path(cmd): | ||
|
||
| """Make sure that command is specified via an absolute path.""" | ||
stdweird marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if not cmd: | ||
| raise ValueError("Empty command specified!") | ||
| if is_string(cmd): | ||
| cmd_path = cmd.split(' ')[0] | ||
| elif isinstance(cmd, (list, tuple,)): | ||
| cmd_path = cmd[0] | ||
| else: | ||
| raise ValueError("Unknown type of command: %s (type %s)" % (cmd, type(cmd))) | ||
|
|
||
| if not os.path.isabs(cmd_path): | ||
| sys.stderr.write("WARNING: Command to run is specified via relative path: %s" % cmd_path) | ||
boegel marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # resolve to absolute path via $PATH | ||
| cmd_abs_path = which(cmd_path) | ||
| if cmd_abs_path is None: | ||
| raise OSError("Command %s not found in $PATH!" % cmd_path) | ||
|
|
||
| # re-assemble command with absolute path | ||
| if is_string(cmd): | ||
| cmd = ' '.join([cmd_abs_path] + cmd.split(' ')[1:]) | ||
| elif isinstance(cmd, list): | ||
| cmd[0] = cmd_abs_path | ||
| elif isinstance(cmd, tuple): | ||
| cmd = tuple([cmd_abs_path] + list(cmd[1:])) | ||
| else: | ||
| raise ValueError("Unknown type of command: %s (type %s)" % (cmd, type(cmd))) | ||
|
|
||
| return cmd | ||
|
|
||
|
|
||
| class CmdList(list): | ||
| """Wrapper for 'list' type to be used for constructing a list of options & arguments for a command.""" | ||
|
|
||
|
|
@@ -172,7 +204,7 @@ def __init__(self, cmd=None, **kwargs): | |
| if not hasattr(self, 'log'): | ||
| self.log = getLogger(self._get_log_name()) | ||
|
|
||
| self.cmd = cmd # actual command | ||
| self.cmd = ensure_cmd_abs_path(cmd) # actual command | ||
|
||
|
|
||
| self._cwd_before_startpath = None | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.