Skip to content
Snippets Groups Projects
Commit a584c0b6 authored by Michael Reuscher's avatar Michael Reuscher
Browse files

Save new SSH stuff 1.0 it works

parent e29fad6a
Branches
Tags
1 merge request!4Python driver and data analysis part
......@@ -6,21 +6,21 @@ import getpass
def parse_arguments():
main_folder = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
main_directory = 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='+', action='append', type=str,
parser.add_argument('-H', '--hosts', nargs='+', type=str,
help='Host addresses of remote machines default: lokal')
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')
parser.add_argument('-d', '--data', type=str, default=main_folder,
parser.add_argument('-d', '--data', type=str, default=main_directory,
help='Folder to store the date for visualizer default: ./')
parser.add_argument('-p', '--protokoll', type=str, default=main_folder,
parser.add_argument('-p', '--protokoll', type=str, default=main_directory,
help='Folder to store the test data from detector sim default: ./')
return parser.parse_args()
......@@ -89,7 +89,7 @@ def run_sim(e_list, d_path, sim_path, st_path):
relativ_path_stat = os.path.join(st_path, stat_file_name + ".dat")
if not args.hosts:
make_folders_lokal(test_data_path, output_path)
event[-1] = output_path
event[-1] = output_path
arguments = event
output, errors, return_code = start_process(sim_path, arguments, test_data_path, output_path)
print(output)
......@@ -104,15 +104,18 @@ def run_sim(e_list, d_path, sim_path, st_path):
def start_process(program_path, arguments, test_path, output_path):
if args.hosts:
# Remote execution on multiple machines with specified user
output = ""
errors = ""
result = ""
for host in args.hosts:
print(host) # Todooo
ssh_target = f'{args.user}@{host}'
make_folders_remote(test_path, output_path, ssh_target, host)
remote_output = make_folders_remote(test_path, output_path, ssh_target, host)
arguments[-1] = remote_output
command = ["ssh", ssh_target, program_path] + arguments
result = subprocess.run(command, capture_output=True, text=True)
output = result.stdout
errors = result.stderr
return output, errors, result.returncode
return output, errors, result.returncode
else:
command = [program_path] + arguments
result = subprocess.run(command, capture_output=True, text=True)
......@@ -132,6 +135,7 @@ def make_folders_remote(test_path, output_path, ssh_target, host):
output_command = f'ssh {ssh_target} "mkdir -p {host_output}"'
subprocess.run(test_command, shell=True, check=True)
subprocess.run(output_command, shell=True, check=True)
return host_output
def pull_data(remote_path, lokal_path):
......@@ -160,4 +164,6 @@ event_list = create_event_list()
# Run detectorSimulation
run_sim(event_list, data_path, simulation_path, stat_path)
# Pull data for visualizer
pull_data(data_path, main_folder)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment