forked from quic-interop/quic-interop-runner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcron.py
69 lines (57 loc) · 1.67 KB
/
cron.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
#!/usr/bin/env python3
import argparse
import json
import logging
import os
import os.path
import shutil
import sys
from datetime import datetime
from interop import InteropRunner
from run import client_implementations, implementations, server_implementations
from testcases import MEASUREMENTS, TESTCASES
def get_args():
parser = argparse.ArgumentParser()
parser.add_argument("-n", "--numlogs", help="keep this many logs")
return parser.parse_args()
try:
numlogs = int(get_args().numlogs)
except Exception as e:
logging.info(e)
sys.exit("Invalid -n argument.")
log_dir = "logs_{:%Y-%m-%dT%H:%M:%S}UTC".format(datetime.utcnow())
InteropRunner(
implementations=implementations,
servers=server_implementations,
clients=client_implementations,
tests=TESTCASES,
measurements=MEASUREMENTS,
output=log_dir + "/result.json",
debug=False,
log_dir=log_dir,
).run()
web_dir = "web/" # directory of the index.html of the interop runner website
logs_file = web_dir + "logs.json"
try:
with open(logs_file, "r") as f:
lines = json.load(f)
except FileNotFoundError:
lines = []
# make sure that web/ doesn't contain more than x old runs
while len(lines) >= numlogs:
d = web_dir + lines[0]
logging.info("Deleting %s.", d)
shutil.rmtree(d)
lines = lines[1:]
with open(logs_file, "w") as f:
lines.append(log_dir)
json.dump(lines, f)
# move log dir to the web folder
shutil.move(log_dir, web_dir + "/")
# adjust web/latest to point to the latest run
latest_symlink = web_dir + "latest"
try:
os.remove(latest_symlink)
except FileNotFoundError:
pass
os.symlink(src=log_dir, dst=latest_symlink, target_is_directory=True)