-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathoutbox_assembly_script.py
53 lines (41 loc) · 2.2 KB
/
outbox_assembly_script.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/python3
########################################################################################
# outbox_assembly_script.py - CLOVER optimisation outbox assembly script. #
# #
# Authors: Ben Winchester #
# Copyright: Ben Winchester, 2022 #
# Date created: 13/07/2021 #
# License: Open source #
# #
# For more information, please email: #
########################################################################################
"""
outbox_assembly_script.py - CLOVER optimisation outbox assembly script.
This script assembles output files from optimisations that were carried out on Imperial
College London's High-Performance Computer(s) (HPC) into a single "outbox directory",
from where they can be easily copied from the HPC for futher analysis.
"""
import os
import shutil
import subprocess
DESTINATION_DIRECTORY: str = "optimisation_outbox"
OPTIMISATION_NAME: str = "optimisation_output_*.json"
def main() -> None:
"""Script to prepare files for scp from hpc."""
filenames = subprocess.run(
["find", "locations", "-name", OPTIMISATION_NAME],
stdout=subprocess.PIPE,
check=True,
).stdout.decode()
filenames = filenames.split("\n")
filenames.remove("")
for source_filename in filenames:
destination_filename = os.path.join(DESTINATION_DIRECTORY, source_filename)
# Make the directory structure within the outbox if it doesn't already exist
if not os.path.isdir(os.path.dirname(destination_filename)):
os.makedirs(os.path.dirname(destination_filename))
# Copy across our file
shutil.copy2(source_filename, destination_filename)
if __name__ == "__main__":
main()