-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild_taskfile.py
More file actions
84 lines (66 loc) · 2.78 KB
/
Copy pathbuild_taskfile.py
File metadata and controls
84 lines (66 loc) · 2.78 KB
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
76
77
78
79
80
81
82
83
84
#!/usr/env/python
import argparse
import sys
import os
function_list = ['segment', 'focus', '2dmorph', '3dmorph']
def build_taskfile(function, directory_list=None):
if directory_list is None:
directory_list = 'dirs_segmented.txt'
if function not in function_list:
print 'Error: unknown function specified. Choose from: %s' % ', '.join(function_list)
sys.exit(1)
# output filename for tasklist
f = open('taskfile_'+function+'.txt', 'w')
# input list of directories
l = open(directory_list, 'r')
for line in l:
if directory_list.endswith('.csv'):
directory = line.strip('\n').split(',')[0]
else:
directory = line.strip('\n')
task = []
task.append('source ~/.bashrc')
task.append('cd '+directory)
if function == 'segment':
if os.path.exists(directory+'/segment_settings.txt'):
task.append('segment segment_settings.txt')
else:
print 'Settings file not found in %s. Double check your directory list: %s' % (directory, directory_list)
continue
elif function == 'focus':
task.append('focus final')
elif function == '2dmorph':
if os.path.exists(directory+'/2dmorph_settings.txt'):
task.append('run2dmorph 2dmorph_settings.txt')
else:
print 'Settings file not found in %s. Double check your directory list: %s' % (directory, directory_list)
continue
elif function == '3dmorph':
if os.path.exists(directory+'/3dmorph_settings.txt'):
task.append('run3dmorph 3dmorph_settings.txt')
else:
print 'Settings file not found in %s. Double check your directory list: %s' % (directory, directory_list)
continue
else:
sys.exit(1)
task_string = "; ".join(task)
f.write(task_string+'\n')
f.close()
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='')
parser.add_argument('function', help='specify AutoMorph function', choices=function_list)
parser.add_argument('-d', '--dirs', help="directory list file (required for 2d and 3d morph)")
args = parser.parse_args()
if args.function in ['2dmorph', '3dmorph']:
if args.dirs is None:
sys.exit('directory list is required for 2d and 3dmorph. Specify with -d <dir_list>.')
else:
if os.path.exists(args.dirs):
build_taskfile(args.function, args.dirs)
else:
sys.exit('directory list file not found %s.' % args.dirs)
else:
if args.dirs is not None:
build_taskfile(args.function, args.dirs)
else:
build_taskfile(args.function)