2021-06-23 21:26:35 +01:00
|
|
|
### Generation helper for run pages
|
|
|
|
|
2021-06-25 04:52:22 +01:00
|
|
|
from .. import file as util_file
|
|
|
|
from .. import csv as util_csv
|
|
|
|
import shutil
|
|
|
|
import os
|
2021-06-26 04:05:19 +01:00
|
|
|
import datetime
|
2021-06-23 21:26:35 +01:00
|
|
|
|
2021-06-25 04:52:22 +01:00
|
|
|
|
|
|
|
def generate(templatedir, destinationdir, templateFilename):
|
2021-06-25 21:13:36 +01:00
|
|
|
"""Main generation function for run page generation helper.
|
2021-06-25 04:52:22 +01:00
|
|
|
|
2021-06-25 21:13:36 +01:00
|
|
|
templatedir -- the relative path of the template html file's directory\n
|
|
|
|
destinationpath -- the directory where run paths should be generated\n
|
|
|
|
templateFilename -- the filename of the run template (always run.html)\n
|
2021-06-25 04:52:22 +01:00
|
|
|
"""
|
|
|
|
|
2021-06-25 21:13:36 +01:00
|
|
|
runIdName = "tk_run_id"
|
|
|
|
categoryIdName = "tk_category_dashname"
|
|
|
|
runs = util_csv.dictReaderMultiRow("../csv/runs.csv", runIdName)
|
|
|
|
categories = util_csv.dictReaderMultiRow("../csv/categories.csv", categoryIdName)
|
2021-06-25 04:52:22 +01:00
|
|
|
config = util_csv.dictReaderFirstRow("../csv/config.csv")
|
|
|
|
|
2021-06-25 21:13:36 +01:00
|
|
|
for run in runs:
|
2021-06-25 04:52:22 +01:00
|
|
|
|
2021-06-26 04:05:19 +01:00
|
|
|
thisRun = runs[run]
|
|
|
|
path = f"{destinationdir}/{thisRun[runIdName]}"
|
2021-06-25 04:52:22 +01:00
|
|
|
currentDir = os.getcwd()
|
|
|
|
|
|
|
|
os.makedirs(path, exist_ok=True)
|
|
|
|
|
|
|
|
shutil.copy(
|
|
|
|
f"{currentDir}/{templatedir}/{templateFilename}",
|
|
|
|
f"{currentDir}/{path}/index.html",
|
|
|
|
)
|
|
|
|
|
2021-06-25 21:13:36 +01:00
|
|
|
tk_run_link = ""
|
2021-06-26 04:05:19 +01:00
|
|
|
for key in thisRun:
|
|
|
|
util_file.replaceTextInFile(f"{path}/index.html", key, thisRun[key])
|
2021-06-25 21:13:36 +01:00
|
|
|
if key == "tk_run_link":
|
2021-06-26 04:05:19 +01:00
|
|
|
tk_run_link = thisRun[key]
|
|
|
|
elif key == "tk_run_duration":
|
|
|
|
tk_run_duration = thisRun[key]
|
2021-06-25 21:13:36 +01:00
|
|
|
|
2021-06-26 04:05:19 +01:00
|
|
|
for key in categories[thisRun["tk_run_category_dashname"]]:
|
2021-06-25 04:52:22 +01:00
|
|
|
util_file.replaceTextInFile(
|
2021-06-25 21:13:36 +01:00
|
|
|
f"{path}/index.html",
|
|
|
|
key,
|
2021-06-26 04:05:19 +01:00
|
|
|
categories[thisRun["tk_run_category_dashname"]][key],
|
2021-06-25 04:52:22 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
for key in config.keys():
|
|
|
|
util_file.replaceTextInFile(f"{path}/index.html", key, config[key])
|
2021-06-25 21:13:36 +01:00
|
|
|
|
2021-06-26 04:05:19 +01:00
|
|
|
## lk_run_link handler ##
|
|
|
|
|
2021-06-25 21:13:36 +01:00
|
|
|
if tk_run_link == "":
|
|
|
|
util_file.replaceTextInFile(
|
|
|
|
f"{path}/index.html", "lk_run_link", "No recording available"
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
util_file.replaceTextInFile(
|
|
|
|
f"{path}/index.html",
|
|
|
|
"lk_run_link",
|
|
|
|
f'<a class="runLink" href="{tk_run_link}">Run recording</a>',
|
|
|
|
)
|
2021-06-26 04:05:19 +01:00
|
|
|
|
|
|
|
## End of: lk_run_link handler ##
|
|
|
|
|
|
|
|
## lk_run_duration handler ##
|
|
|
|
|
|
|
|
runDurationSplit = [float(value) for value in tk_run_duration.split(":")]
|
|
|
|
lk_run_duration = datetime.timedelta(
|
|
|
|
hours=runDurationSplit[0],
|
|
|
|
minutes=runDurationSplit[1],
|
|
|
|
seconds=runDurationSplit[2],
|
|
|
|
)
|
|
|
|
util_file.replaceTextInFile(
|
|
|
|
f"{path}/index.html", "lk_run_duration", str(lk_run_duration)
|
|
|
|
)
|
|
|
|
|
|
|
|
## End of: lk_run_duration handler ##
|