Skip to content

Commit 4c9c3c0

Browse files
committed
Abstracted temp file creation for quick measurement modes
1 parent 04ea245 commit 4c9c3c0

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

runner.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@
2121
from lib.db import DB
2222
from lib.global_config import GlobalConfig
2323

24+
def create_and_replace_tmp_usage_scenario(folder, placeholder, content):
25+
with open(f"templates/{folder}/usage_scenario.yml", mode='r', encoding='utf-8') as f:
26+
usage_scenario = f.read()
27+
data = usage_scenario.replace(placeholder, content)
28+
usage_scenario_tmp = f"templates/{folder}/usage_scenario.yml.tmp"
29+
with open(usage_scenario_tmp, mode='w+', encoding='utf-8') as f:
30+
f.write(data)
31+
32+
return usage_scenario_tmp
33+
2434
if __name__ == '__main__':
2535
import argparse
2636

@@ -74,13 +84,8 @@
7484
error_helpers.log_error('--branch or --filename are not allowed in website mode. Please remove or use run mode with a repository')
7585
sys.exit(1)
7686

87+
args.filename = create_and_replace_tmp_usage_scenario('website', '__GMT_PLACEHOLDER_WEBSITE__', args.page)
7788
args.uri = GMT_ROOT_DIR
78-
with open('templates/website/usage_scenario.yml', mode='r', encoding='utf-8') as f:
79-
usage_scenario = f.read()
80-
usage_scenario = usage_scenario.replace('__GMT_PLACEHOLDER_WEBSITE__', args.page)
81-
with open('templates/website/usage_scenario.yml.tmp', mode='w+', encoding='utf-8') as f:
82-
f.write(usage_scenario)
83-
args.filename = 'templates/website/usage_scenario.yml.tmp'
8489
run_type = 'folder'
8590
commit_hash_folder = 'templates/website/'
8691

@@ -95,8 +100,8 @@
95100
error_helpers.log_error('--branch or --filename are not allowed in website mode. Please remove or use run mode with a repository')
96101
sys.exit(1)
97102

103+
args.filename = create_and_replace_tmp_usage_scenario('ai', '__GMT_PLACEHOLDER_PROMPT__', args.prompt)
98104
args.uri = GMT_ROOT_DIR
99-
args.filename = 'templates/ai/usage_scenario.yml'
100105
run_type = 'folder'
101106
commit_hash_folder = 'templates/ai/'
102107

@@ -187,9 +192,9 @@
187192

188193

189194
if args.print_phase_stats:
190-
data = DB().fetch_all('SELECT metric, detail_name, value, type, unit FROM phase_stats WHERE run_id = %s and phase LIKE %s ', params=(runner._run_id, f"%{args.print_phase_stats}"))
195+
phase_stats = DB().fetch_all('SELECT metric, detail_name, value, type, unit FROM phase_stats WHERE run_id = %s and phase LIKE %s ', params=(runner._run_id, f"%{args.print_phase_stats}"))
191196
print(f"Data for phase {args.print_phase_stats}")
192-
for el in data:
197+
for el in phase_stats:
193198
print(el)
194199
print('')
195200

0 commit comments

Comments
 (0)