Check whether our mirror packages are up to date.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.9 KiB

#!/usr/bin/env python3
This mirror status checker determines whether CSC mirror is up-to-date with upstream
from datetime import datetime, timedelta
import requests
SUCCESS = "Success: {} up-to-date"
FAILURE = "Failure: {} out-of-sync"
ERROR = "Error: {}\n{}"
def get_debian_dt(trace_file_url):
"""Get Debian datetime object from trace file"""
response_text = requests.get(trace_file_url).text
time_str = response_text.split('\n')[0]
return datetime.strptime(time_str, "%a %b %d %H:%M:%S UTC %Y")
if __name__ == "__main__":
# Arch
arch_json = requests.get("").json()
last_check_str = arch_json["last_check"]
last_sync_str = [url for url in arch_json["urls"] if url["url"] == \
last_check_dt = datetime.strptime(last_check_str, "%Y-%m-%dT%H:%M:%S.%fZ")
last_sync_dt = datetime.strptime(last_sync_str, "%Y-%m-%dT%H:%M:%SZ")
# According to
# Due to the timing of mirror checks, any value under one hour should be viewed as ideal
OUTPUT = SUCCESS if last_check_dt < last_sync_dt + timedelta(hours = 1) else FAILURE
except requests.exceptions.RequestException as err:
print(ERROR.format("Arch", err))
# Debian
official_dt = get_debian_dt("")
csc_dt = get_debian_dt(f"{CSC_MIRROR}debian/project/trace/master")
# Keep the table cell at
# green and not yellow
OUTPUT = SUCCESS if official_dt < csc_dt + timedelta(hours = 7) else FAILURE
except requests.exceptions.RequestException as err:
print(ERROR.format("Debian", err))