-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
xbbs-project-rotate
executable file
·73 lines (58 loc) · 1.79 KB
/
xbbs-project-rotate
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
70
71
72
73
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-only
"""
Looks for builds of the given project (or cwd), removes outdated artifacts and
builds older than a month, preserving at least one successful build.
"""
import glob
import json
import os
import os.path as path
import shutil
import sys
from datetime import datetime, timedelta, timezone
import xbbs.util as xutils
if len(sys.argv) > 1:
os.chdir(sys.argv[1])
# 2021-05-22T13:41:59
coord_file_list = glob.glob("????-??-??T??:??:??/coordinator")
coord_file_list.sort(reverse=True)
remove_list = []
found_success = False
for i, f in enumerate(coord_file_list):
with open(f, "r") as o:
coordinator_object = json.load(o)
if "run_time" not in coordinator_object:
continue
if coordinator_object["success"] and not found_success:
found_success = True
continue
if i > 10:
remove_list.append(f)
TIMESTAMP_FORMAT = "%Y-%m-%dT%H:%M:%S"
passed_month = False
exception_list = []
def rmtree_errors(fn, path, excinfo):
exception = excinfo[1]
exception_list.append((path, exception.with_traceback(None)))
for f in remove_list:
tsdir = path.dirname(f)
if not passed_month:
delta = datetime.now(timezone.utc) - \
xutils.strptime(tsdir, xutils.TIMESTAMP_FORMAT)
if delta > timedelta(days=30):
passed_month = True
else:
shutil.rmtree(tsdir, onerror=rmtree_errors)
continue
for repo in ["package_repo", "tool_repo", "file_repo"]:
rp = path.join(tsdir, repo)
if not path.isdir(rp):
continue
shutil.rmtree(rp, onerror=rmtree_errors)
if len(exception_list) == 0:
exit(0)
print("hit errors on: ", file=sys.stderr)
for fp, exc in exception_list:
print(f"{fp}: {exc}", file=sys.stderr)
exit(1)