-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathharvest.py
executable file
·76 lines (53 loc) · 2.08 KB
/
harvest.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"""
This script finds all the results objects from a long run on a remote machine and moves
them to the local machine for easier analysis.
"""
import importlib
import os
import subprocess
import sys
import ml.infra.work_spec
def get_list_of_source_destination_pairs(work_spec):
source_destination_pairs = []
remote_az_dir = os.environ['REMOTE_AZ_DIR']
local_az_dir = os.environ['LOCAL_AZ_DIR']
relative_file_paths = work_spec.get_all_results_obj_paths()
relative_dir_paths = work_spec.get_all_model_dirs()
remote_file_paths = [remote_az_dir + p for p in relative_file_paths]
local_dir_paths = [local_az_dir + p for p in relative_dir_paths]
for (file_path, dir_path) in zip(remote_file_paths, local_dir_paths):
source_destination_pairs.append((file_path, dir_path))
return source_destination_pairs
def gather_results_from_remote_machine(host_str, source_destination_pairs, execute):
"""
Given the (remote_file_path, local_destination_directory) pairs, scp each of those
files onto the local machine.
"""
for (source_file, destination_dir) in source_destination_pairs:
try:
os.makedirs(destination_dir)
except Exception as e:
# TODO: handle gracefully if this directory exists but is empty.
print e
source = '%s:%s' % (host_str, source_file)
# TODO: Continue if one of these fails for some reason.
if execute is True:
p = subprocess.Popen([
'scp',
source,
destination_dir,
])
sts = os.waitpid(p.pid, 0)
def main():
work_spec_name = sys.argv[1]
host_str = sys.argv[2]
execute = (sys.argv[3] == 'True')
work_spec = ml.infra.work_spec.WorkSpec.get_work_spec_object_by_name(work_spec_name)
source_destination_pairs = get_list_of_source_destination_pairs(work_spec)
gather_results_from_remote_machine(
host_str,
source_destination_pairs,
execute,
)
if __name__ == '__main__':
main()