-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_all_references.py
48 lines (37 loc) · 1.32 KB
/
create_all_references.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
import argparse
import json
import subprocess
import os
def get_cmd(config_line):
config = config_line
cmd = '{}'.format(config['src_file'])
src_file = config['src_file']
del config['src_file']
for key, value in config.items():
if value is None:
continue
if type(value) == bool:
if value:
cmd += ' -{}'.format(key)
continue
cmd += ' -{} {}'.format(key, str(value))
config['src_file'] = src_file
return cmd, config
def cpu_run(args):
all_cmd = []
with open(args.input_file, 'r') as f:
for line in f:
config_line = json.loads(line)
cmd, _ = get_cmd(config_line)
cmd = 'TOKENIZERS_PARALLELISM=False python {}'.format(cmd)
print('Command: {}'.format(cmd))
cmd_run = cmd#.split()
all_cmd.append(cmd_run)
print("Using os.system command. Tried using subprocess but it was resulting in non-execution of command.")
for cmd_run in all_cmd:
os.system(cmd_run)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Reference Creator')
parser.add_argument("-i", "--input_file", default="precommands.json", help="File name where all json configurations are stored")
args = parser.parse_args()
cpu_run(args)