From 07f3f71c6cb2dbc080d33c23061b88c5ed5745be Mon Sep 17 00:00:00 2001 From: lukemartinlogan Date: Mon, 2 Oct 2023 02:18:26 -0500 Subject: [PATCH 1/4] Add sudoenv to keys --- jarvis_util/shell/exec_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jarvis_util/shell/exec_info.py b/jarvis_util/shell/exec_info.py index 94108fd..4c68e34 100644 --- a/jarvis_util/shell/exec_info.py +++ b/jarvis_util/shell/exec_info.py @@ -82,7 +82,7 @@ def __init__(self, exec_type=ExecType.LOCAL, nprocs=None, ppn=None, self.exec_async = exec_async self.stdin = stdin self.keys = ['exec_type', 'nprocs', 'ppn', 'user', 'pkey', 'port', - 'hostfile', 'env', 'sleep_ms', 'sudo', + 'hostfile', 'env', 'sleep_ms', 'sudo', 'sudoenv', 'cwd', 'hosts', 'collect_output', 'pipe_stdout', 'pipe_stderr', 'hide_output', 'exec_async', 'stdin'] From 4d73becedc2c6c218bba695c28e98410fd2d6500 Mon Sep 17 00:00:00 2001 From: lukemartinlogan Date: Mon, 2 Oct 2023 02:20:34 -0500 Subject: [PATCH 2/4] Print sudoenv --- jarvis_util/shell/local_exec.py | 1 + 1 file changed, 1 insertion(+) diff --git a/jarvis_util/shell/local_exec.py b/jarvis_util/shell/local_exec.py index 4e6c2e5..8094929 100644 --- a/jarvis_util/shell/local_exec.py +++ b/jarvis_util/shell/local_exec.py @@ -71,6 +71,7 @@ def __init__(self, cmd, exec_info): self.cwd = exec_info.cwd # Create the command + print(exec_info.sudoenv) cmd = self.smash_cmd(cmd, self.sudo, self.basic_env, exec_info.sudoenv) self.cmd = cmd if self.jutil.debug_local_exec: From 6fbba07060e8da8733e1372756afff912c0962fa Mon Sep 17 00:00:00 2001 From: lukemartinlogan Date: Mon, 2 Oct 2023 02:23:32 -0500 Subject: [PATCH 3/4] Never execute ssh itself as sudo --- jarvis_util/shell/local_exec.py | 1 - jarvis_util/shell/ssh_exec.py | 5 +++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/jarvis_util/shell/local_exec.py b/jarvis_util/shell/local_exec.py index 8094929..4e6c2e5 100644 --- a/jarvis_util/shell/local_exec.py +++ b/jarvis_util/shell/local_exec.py @@ -71,7 +71,6 @@ def __init__(self, cmd, exec_info): self.cwd = exec_info.cwd # Create the command - print(exec_info.sudoenv) cmd = self.smash_cmd(cmd, self.sudo, self.basic_env, exec_info.sudoenv) self.cmd = cmd if self.jutil.debug_local_exec: diff --git a/jarvis_util/shell/ssh_exec.py b/jarvis_util/shell/ssh_exec.py index e207971..36e6ec3 100644 --- a/jarvis_util/shell/ssh_exec.py +++ b/jarvis_util/shell/ssh_exec.py @@ -29,9 +29,10 @@ def __init__(self, cmd, exec_info): cmd = self.smash_cmd(cmd, self.sudo, self.basic_env, exec_info.sudoenv) if not exec_info.hostfile.is_local(): super().__init__(self.ssh_cmd(cmd), - exec_info.mod(env=exec_info.basic_env)) + exec_info.mod(env=exec_info.basic_env, + sudo=False)) else: - super().__init__(cmd, exec_info) + super().__init__(cmd, exec_info.mod(sudo=False)) def ssh_cmd(self, cmd): lines = ['ssh'] From 30b8a54e70daa93bf15a70d5c3c6daeda0e24a7f Mon Sep 17 00:00:00 2001 From: lukemartinlogan Date: Mon, 2 Oct 2023 04:39:40 -0500 Subject: [PATCH 4/4] Don't except on load_class import --- jarvis_util/util/import_mod.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/jarvis_util/util/import_mod.py b/jarvis_util/util/import_mod.py index 3104c27..d752205 100644 --- a/jarvis_util/util/import_mod.py +++ b/jarvis_util/util/import_mod.py @@ -24,7 +24,10 @@ def load_class(import_str, path, class_name): """ if len(path): sys.path.insert(0, path) - module = __import__(import_str, fromlist=[class_name]) + try: + module = __import__(import_str, fromlist=[class_name]) + except: + return None if len(path): sys.path.pop(0) return getattr(module, class_name)