-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
52 lines (43 loc) · 1.27 KB
/
run.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
import sys, getopt
import extract, convert
def print_usage():
print('USAGE: <action> [<additional_action_args>] -i <inputfile> -o <outputfile>\nactions: \n translate: '+
'\n\t-x\t\t\textract-names - extract all names to a mapping file for translation'+
'\n\t-c -m <mappingFile>\tconvert - use naming mapping file to translate csv names')
def main(argv):
inputFile = ''
outputFile = ''
mappingFile = ''
action = ''
try:
opts, args = getopt.getopt(argv,"hxci:o:m:")
except getopt.GetoptError:
print('Failed parsing command arguments')
print_usage()
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print_usage()
sys.exit()
elif opt == "-i":
inputFile = arg
elif opt == "-o":
outputFile = arg
elif opt == "-m":
mappingFile = arg
elif opt == '-x':
action = 'extract'
elif opt == '-c':
action = 'convert'
print(inputFile)
print(outputFile)
print(mappingFile)
if(not inputFile or not outputFile or not action or (action == 'convert' and not mappingFile)):
print_usage()
sys.exit(2)
if action == 'extract':
extract.apply(inputFile, outputFile)
if action == 'convert':
convert.apply(inputFile, outputFile, mappingFile)
if __name__ == "__main__":
main(sys.argv[1:])