This repository has been archived by the owner on Dec 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_status.py
executable file
·100 lines (76 loc) · 2.55 KB
/
build_status.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/python3
import os
os.chdir(os.path.dirname(os.path.abspath(__file__)))
import json
from datetime import datetime, timezone, timedelta
# from IdolDatabase.Config import Config
# build_status_file = Config.BUILD_STATUS_FILE
build_status_file = "build/build.status"
try:
status_file = open(build_status_file, "r+")
except FileNotFoundError:
print("Build status file missing or unreadable.")
exit(-1337)
try:
status = json.load(status_file)
except json.decoder.JSONDecodeError:
print("Build status file corrupted/not valid json.")
exit(-1337)
now = datetime.now(timezone.utc)
disable_built_check = (now.hour == 6 and (now.minute >= 0 and now.minute <= 10)) or (now.hour == 5 and now.minute >= 55)
timestamp = datetime.fromisoformat(status['timestamp'])
timestamp_adjusted = timestamp - timedelta(hours=6, minutes=2)
today_adjusted = now - timedelta(hours=6, minutes=2)
# print()
# print("timestamp", timestamp)
# print("today", today)
# print(timestamp.day, today.day)
has_built_today = (timestamp_adjusted.day == today_adjusted.day)
already_handled = False
if status['handled'] != None:
already_handled = True
status['handled'] = datetime.now(timezone.utc).isoformat()
print()
if not disable_built_check and not has_built_today:
print("--------- WARNING! BUILD NOT RUN YET! ---------")
print("Today's build should have run by now.")
print()
print("------------------ CRON LOG! ------------------\n")
try:
cron_log = open("cron-update.log", "r")
print(cron_log.read())
except:
print("Unable to read cron update log...")
print("-----------------------------------------------")
print()
print("Below are the details for most recent build.")
print()
if status['success'] == True:
print("-------------- BUILD SUCCESSFUL! --------------")
else:
print("---------------- BUILD FAILED! ----------------")
print(f"Build date : {timestamp.strftime('%Y-%m-%d %H:%M:%S')}")
print(f"Automatic : {status['auto']}")
print(f"Forced : {status['forced']}")
print()
if not status['success'] and status['auto']:
print("------------------ CRON LOG! ------------------\n")
try:
cron_log = open("cron-update.log", "r")
print(cron_log.read())
except:
print("Unable to read cron update log...")
print("-----------------------------------------------")
print()
print(status['message'])
if not already_handled:
status_file.seek(0)
status_file.truncate()
json.dump(status, status_file)
status_file.close()
if not disable_built_check and not has_built_today:
exit(2)
elif status['success'] == True or not status['auto']:
exit(0)
else:
exit(1)