updated function to run directly via os.system and not in subprocess

This commit is contained in:
brb
2023-07-14 14:52:49 +02:00
parent c6fccb9047
commit 31ddd80fae
+35 -4
View File
@@ -31,9 +31,40 @@ def clone_repository(
return dst_dir return dst_dir
def execute_runner_script(path: Path) -> None: def execute_script(
rs = RunnerScript.from_file(path) local_repo_dir: Path
) -> None:
# locate the script
script_path = (
local_repo_dir /
'.gitea' /
'gpu_runner' /
'script.yml'
)
# determine original working dir
org_dir = os.getcwd()
# initialise command list
cmd_list = [
f'cd {local_repo_dir.resolve()}',
f'virtualenv -p python3.10 venv',
f'source venv/bin/activate',
]
# add in runner script
rs = RunnerScript.from_file(path=script_path)
for cmd in rs.script: for cmd in rs.script:
print(f'> {cmd}') cmd_list.append(cmd)
os.system(cmd) # append cleanup commands
cmd_list.append('deactivate')
cmd_list.append(f'cd {org_dir}')
cmd_list.append(f'rm -rf {local_repo_dir.resolve()}')
# build command string
cmd_str = ' && '.join(cmd_list)
os.system(cmd_str)
logging.debug('finished') logging.debug('finished')
if __name__ == '__main__':
local_repo_dir = Path(__file__).parent.parent / 'repo' / 'gpu_runner'
execute_script(
local_repo_dir=local_repo_dir
)