From bae3d74f0075b0af049dc736002f7305f821d176 Mon Sep 17 00:00:00 2001 From: Laura Nguyen Date: Tue, 24 Aug 2021 17:00:51 -0400 Subject: [PATCH] Created Eclipse mirror status checker --- arch.py | 2 +- constants.py | 3 --- debian.py | 2 +- eclipse.py | 21 +++++++++++++++++++++ kernel.py | 2 +- main.py | 3 ++- openbsd.py | 13 +++---------- shared.py | 10 ++++++++++ 8 files changed, 39 insertions(+), 17 deletions(-) delete mode 100644 constants.py create mode 100644 eclipse.py create mode 100644 shared.py diff --git a/arch.py b/arch.py index 4c1c12a..2b81880 100644 --- a/arch.py +++ b/arch.py @@ -5,7 +5,7 @@ Contains Arch class from datetime import datetime, timedelta import requests from distro import Distro -from constants import CSC_MIRROR +from shared import CSC_MIRROR class Arch(Distro): """Arch class""" diff --git a/constants.py b/constants.py deleted file mode 100644 index 9de4e7a..0000000 --- a/constants.py +++ /dev/null @@ -1,3 +0,0 @@ -"""Contains shared constants""" - -CSC_MIRROR = "http://mirror.csclub.uwaterloo.ca/" diff --git a/debian.py b/debian.py index 27ce0c1..9238fa8 100644 --- a/debian.py +++ b/debian.py @@ -5,7 +5,7 @@ Contains Debian class from datetime import datetime, timedelta import requests from distro import Distro -from constants import CSC_MIRROR +from shared import CSC_MIRROR class Debian(Distro): """Debian class""" diff --git a/eclipse.py b/eclipse.py new file mode 100644 index 0000000..e413e04 --- /dev/null +++ b/eclipse.py @@ -0,0 +1,21 @@ +""" +Contains Eclipse class +""" + +from distro import Distro +from shared import CSC_MIRROR, get_sec + +class Eclipse(Distro): + """Eclipse class""" + @staticmethod + def name(): + """Get name of Eclipse""" + return "Eclipse" + + @staticmethod + def check(): + """Check if Eclipse packages are up-to-date""" + official_sec = get_sec("http://download.eclipse.org/TIME") + csc_sec = get_sec(f"{CSC_MIRROR}eclipse/TIME") + # Out-of-sync by 2 days maximum + return official_sec < csc_sec + 172800 diff --git a/kernel.py b/kernel.py index 47357ed..30e6b83 100644 --- a/kernel.py +++ b/kernel.py @@ -4,7 +4,7 @@ Contains Kernel class import requests from distro import Distro -from constants import CSC_MIRROR +from shared import CSC_MIRROR class Kernel(Distro): """Kernel class""" diff --git a/main.py b/main.py index fe0a899..ddd1335 100644 --- a/main.py +++ b/main.py @@ -7,11 +7,12 @@ This mirror status checker determines whether CSC mirror is up-to-date with upst import requests from arch import Arch from debian import Debian +from eclipse import Eclipse from kernel import Kernel from openbsd import OpenBSD if __name__ == "__main__": - for distro in [Arch, Debian, Kernel, OpenBSD]: + for distro in [Arch, Debian, Eclipse, Kernel, OpenBSD]: try: distro.print_output(distro.check()) except requests.exceptions.RequestException as err: diff --git a/openbsd.py b/openbsd.py index b18e0ca..75a3709 100644 --- a/openbsd.py +++ b/openbsd.py @@ -2,18 +2,11 @@ Contains OpenBSD class """ -import requests from distro import Distro -from constants import CSC_MIRROR +from shared import CSC_MIRROR, get_sec class OpenBSD(Distro): """OpenBSD class""" - @staticmethod - def __get_sec(timestamp_file_url): - """Get OpenBSD seconds since the Epoch from timestamp file""" - sec_str = requests.get(timestamp_file_url).text - return int(sec_str) - @staticmethod def name(): """Get name of OpenBSD""" @@ -22,7 +15,7 @@ class OpenBSD(Distro): @staticmethod def check(): """Check if OpenBSD packages are up-to-date""" - official_sec = OpenBSD.__get_sec("https://ftp.openbsd.org/pub/OpenBSD/timestamp") - csc_sec = OpenBSD.__get_sec(f"{CSC_MIRROR}OpenBSD/timestamp") + official_sec = get_sec("https://ftp.openbsd.org/pub/OpenBSD/timestamp") + csc_sec = get_sec(f"{CSC_MIRROR}OpenBSD/timestamp") # Out-of-sync by 1 day maximum return official_sec < csc_sec + 86400 diff --git a/shared.py b/shared.py new file mode 100644 index 0000000..9f3ba69 --- /dev/null +++ b/shared.py @@ -0,0 +1,10 @@ +"""Contains shared constants and functions""" + +import requests + +CSC_MIRROR = "http://mirror.csclub.uwaterloo.ca/" + +def get_sec(timestamp_file_url): + """Get seconds since the Epoch from timestamp file""" + sec_str = requests.get(timestamp_file_url).text + return int(sec_str)