-
Notifications
You must be signed in to change notification settings - Fork 110
/
Copy pathextract_stats.py
93 lines (72 loc) · 2.67 KB
/
extract_stats.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import os
import platform
import subprocess
import sys
def print_usage():
print('Usage: python extract_stats.py -acl=<path/to/raw_clips_directory> -version=<1.0.0-test>')
def parse_argv():
options = {}
options['acl'] = ''
options['version'] = None
for i in range(1, len(sys.argv)):
value = sys.argv[i]
# TODO: Strip trailing '/' or '\'
if value.startswith('-acl='):
options['acl'] = value[len('-acl='):].replace('"', '')
options['acl'] = os.path.expanduser(options['acl'])
if value.startswith('-version='):
options['version'] = value[len('-version='):]
if not os.path.exists(options['acl']) or not os.path.isdir(options['acl']):
print('ACL input directory not found: {}'.format(options['acl']))
print_usage()
sys.exit(1)
if options['version'] is None or len(options['version']) == 0:
print('-version missing')
sys.exit(1)
return options
def get_python_exe_name():
if platform.system() == 'Windows':
return 'python'
else:
return 'python3'
def safe_create_dir(dir_path):
if os.path.exists(dir_path):
print('Directory already exists: {}'.format(dir_path))
return False
os.makedirs(dir_path)
return True
def run_cmd(cmd, output_log):
try:
args = cmd.split(' ')
result = subprocess.check_output(args)
with open(output_log, 'w') as log_file:
log_file.write(result.decode('utf-8'))
except subprocess.CalledProcessError as e:
print('Failed command: {}'.format(cmd))
print(e.output.decode(sys.stdout.encoding))
sys.exit(1)
if __name__ == "__main__":
if sys.version_info < (3, 4):
print('Python 3.4 or higher needed to run this script')
sys.exit(1)
options = parse_argv()
os.environ['PYTHONIOENCODING'] = 'utf_8'
python_exe = get_python_exe_name()
acl_raw = options['acl']
version = options['version']
summary_output_dir = '{}-{}-summary'.format(acl_raw, version)
error_output_dir = '{}-{}-error'.format(acl_raw, version)
cmds = []
if safe_create_dir(summary_output_dir):
output_log = os.path.join(summary_output_dir, 'output.log')
cmds.append(('{} acl_compressor.py -acl="{}" -stats="{}" -csv_summary -parallel=14 -no_progress_bar -level=automatic'.format(python_exe, acl_raw, summary_output_dir, version), output_log))
if safe_create_dir(error_output_dir):
output_log = os.path.join(error_output_dir, 'output.log')
cmds.append(('{} acl_compressor.py -acl="{}" -stats="{}" -csv_error -parallel=30 -no_progress_bar -level=automatic -stat_exhaustive'.format(python_exe, acl_raw, error_output_dir, version), output_log))
root_dir = os.path.join(os.getcwd(), '../acl_compressor')
os.chdir(root_dir)
for (cmd, output_log) in cmds:
print('Running command: "{}" ...'.format(cmd))
run_cmd(cmd, output_log)
print('Done!')
sys.exit(0)