mirror of
https://github.com/morgan9e/mirror
synced 2026-04-13 16:04:10 +09:00
91 lines
2.4 KiB
Python
91 lines
2.4 KiB
Python
#!/usr/bin/env python3
|
|
|
|
import os
|
|
import sys
|
|
import re
|
|
import datetime
|
|
|
|
base_path = sys.argv[1]
|
|
assert os.path.exists(base_path)
|
|
|
|
out_path = os.path.join(base_path, "pub/")
|
|
log_path = os.path.join(base_path, "logs/all.log")
|
|
template = os.path.join(base_path, "scripts/base.html")
|
|
index = os.path.join(out_path, "index.html")
|
|
|
|
assert os.path.exists(log_path)
|
|
assert os.path.exists(template)
|
|
|
|
with open(log_path, 'r') as f:
|
|
log = f.read().splitlines()
|
|
log.reverse()
|
|
|
|
with open(template, 'r') as f:
|
|
html_file = f.read()
|
|
|
|
target_dists = re.findall("@@([^@@]+)@@", html_file)
|
|
source_dists = set(line.split(" ")[2] for line in log)
|
|
|
|
print(target_dists)
|
|
|
|
status = {k: [[0, 0], 0, 0] for k in target_dists}
|
|
|
|
for target in target_dists:
|
|
for line in log:
|
|
time, stat, dist = (spl := line.split(" "))[:3]
|
|
time = datetime.datetime.strptime(time, '%Y%m%d_%H%M')
|
|
|
|
if dist == target:
|
|
if stat == "DONE":
|
|
if not status[target][0][0]:
|
|
status[target][0][0] = time
|
|
if len(spl) == 5:
|
|
status[target][0][1] = spl[4]
|
|
|
|
elif stat == "ERROR":
|
|
if not status[target][1]:
|
|
status[target][1] = time
|
|
|
|
elif stat == "STARTED":
|
|
if not status[target][2]:
|
|
status[target][2] = time
|
|
|
|
if status[target][0][0]:
|
|
break
|
|
|
|
print(status)
|
|
|
|
error_tmpl = "<br><span style='color:red;font-size:12px'>{}</span>"
|
|
|
|
for target in status:
|
|
# if status[target][1] exists, recently errored
|
|
done = status[target][0]
|
|
error = status[target][1]
|
|
running = status[target][2]
|
|
|
|
HTML = done[0].strftime("%Y-%m-%d %H:00") if done[0] else "Not Synced"
|
|
|
|
if error and (error > running):
|
|
HTML += error_tmpl.format(f'ERR {error.strftime("%Y-%m-%d %H:%M")}')
|
|
|
|
if running:
|
|
HTML += error_tmpl.format(f'RUN {running.strftime("%Y-%m-%d %H:%M")}')
|
|
|
|
HTML += "</td><td>"
|
|
|
|
def sec_to_hum(sec):
|
|
if sec >= 60:
|
|
if sec >= 3600:
|
|
return f"{sec//3600}h {(sec%3600)//60}m"
|
|
return f"{sec//60}m {sec%60}s"
|
|
return f"{sec}s"
|
|
|
|
HTML += sec_to_hum(int(done[1])) if done[1] else ""
|
|
|
|
html_file = html_file.replace(f"@@{target}@@", HTML)
|
|
|
|
with open(index, 'w') as f:
|
|
f.write(html_file)
|
|
|
|
print("Written to index.html")
|