From 9d670728e75b0ab4f08d92c6e259c0782d6083f6 Mon Sep 17 00:00:00 2001 From: Michael Reuscher <michael.reuscher@desy.de> Date: Thu, 20 Jul 2023 10:19:56 +0200 Subject: [PATCH] new simrunner fix --- simrunner/simrunner.py | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/simrunner/simrunner.py b/simrunner/simrunner.py index caddd67..a6de2c7 100644 --- a/simrunner/simrunner.py +++ b/simrunner/simrunner.py @@ -8,12 +8,13 @@ import getpass def parse_arguments(): main_folder = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) default_sim_path = os.path.join(os.path.dirname(__file__), "../build/src/detsim") + current_user = getpass.getuser() parser = argparse.ArgumentParser(description='Run a subprocess locally or on remote machines.') parser.add_argument('-s', '--sim', type=str, default=default_sim_path, help='Path to the detector simulation script default: ./') parser.add_argument('-H', '--hosts', nargs='+', type=str, help='Host addresses of remote machines default: lokal') - parser.add_argument('-u', '--user', type=str, + parser.add_argument('-u', '--user', type=str, default=current_user, help='Username for SSH connection default: current user') parser.add_argument('-f', '--function', choices=['various', 'long'], default='various', help='Choose function to execute default: various') @@ -102,27 +103,15 @@ def run_sim(e_list, d_path, sim_path, st_path): def start_process(program_path, arguments): if args.hosts: - if args.user: - # Remote execution on multiple machines with specified user - for host in args.hosts: - ssh_command = f'{args.user}@{host}' - command = ["ssh", ssh_command] + arguments - print(command) - result = subprocess.run(command, capture_output=True, text=True) - output = result.stdout - errors = result.stderr - return output, errors, result.returncode - else: - # Remote execution on multiple machines with current user - current_user = getpass.getuser() - for host in args.hosts: - ssh_command = f'{current_user}@{host}' - command = ["ssh", ssh_command] + arguments - print(command) - result = subprocess.run(command, capture_output=True, text=True) - output = result.stdout - errors = result.stderr - return output, errors, result.returncode + # Remote execution on multiple machines with specified user + for host in args.hosts: + ssh_command = f'{args.user}@{host}' + command = ["ssh", ssh_command, program_path] + arguments + print(command) + result = subprocess.run(command, capture_output=True, text=True) + output = result.stdout + errors = result.stderr + return output, errors, result.returncode else: command = [program_path] + arguments result = subprocess.run(command, capture_output=True, text=True) -- GitLab