-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompactor_doc.py
32 lines (26 loc) · 1.1 KB
/
compactor_doc.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
import os
import sys
import json
ROOT_FOLDER = sys.argv[1] if len(sys.argv) > 1 else './results/compactor_tests'
FILE_COMPACTED = "{}_compacted.cc".format(sys.argv[2] if len(sys.argv) > 2 else '29')
FILE_ORIGINAL = "{}.cc".format(sys.argv[2] if len(sys.argv) > 2 else '29')
OUTPUT_FOLDER = './docs/code'
JSON_FILE = sys.argv[3] if len(sys.argv) > 3 else 'test.json'
RUN_NUMBER = sys.argv[4] if len(sys.argv) > 4 else 'run_empty'
code = ""
with open(os.path.join(ROOT_FOLDER,FILE_COMPACTED), 'r') as file:
code = file.read()
code_original = ""
with open(os.path.join(ROOT_FOLDER,FILE_ORIGINAL), 'r') as file:
code_original = file.read()
loaded_code_json = {}
code_file_path = os.path.join(OUTPUT_FOLDER, JSON_FILE)
# when there is the file we need to load it
if os.path.exists(code_file_path):
print("EXISTS")
with open(code_file_path, 'r') as code_json:
loaded_code_json = json.load(code_json)
loaded_code_json[RUN_NUMBER] = code
loaded_code_json['{}_original'.format(RUN_NUMBER)] = code_original
with open(code_file_path, 'w+') as code_json:
json.dump(loaded_code_json, code_json, indent=2)