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/ceph.py b/ceph.py new file mode 100644 index 0000000..fe8f28b --- /dev/null +++ b/ceph.py @@ -0,0 +1,21 @@ +""" +Contains Ceph class +""" + +from distro import Distro +from shared import CSC_MIRROR, get_sec + +class Ceph(Distro): + """Ceph class""" + @staticmethod + def name(): + """Get name of Ceph""" + return "Ceph" + + @staticmethod + def check(): + """Check if Ceph packages are up-to-date""" + official_sec = get_sec("https://download.ceph.com/timestamp") + csc_sec = get_sec(f"{CSC_MIRROR}ceph/timestamp") + # Out-of-sync by 1 day maximum + return official_sec < csc_sec + 86400 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/gnu.py b/gnu.py new file mode 100644 index 0000000..2d23ade --- /dev/null +++ b/gnu.py @@ -0,0 +1,21 @@ +""" +Contains GNU class +""" + +from distro import Distro +from shared import CSC_MIRROR, get_sec + +class GNU(Distro): + """GNU class""" + @staticmethod + def name(): + """Get name of GNU""" + return "GNU" + + @staticmethod + def check(): + """Check if GNU packages are up-to-date""" + official_sec = get_sec("https://mirrors.kernel.org/gnu/mirror-updated-timestamp.txt") + csc_sec = get_sec(f"{CSC_MIRROR}gnu/mirror-updated-timestamp.txt") + # Out-of-sync by 1 day maximum + return official_sec < csc_sec + 86400 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 7c415e8..54699db 100644 --- a/main.py +++ b/main.py @@ -6,7 +6,10 @@ This mirror status checker determines whether CSC mirror is up-to-date with upst import requests from arch import Arch +from ceph import Ceph from debian import Debian +from eclipse import Eclipse +from gnu import GNU from kernel import Kernel from openbsd import OpenBSD from dateparser.search import search_dates # this library seems to be super slow but the other library: dateutil.parser gets some errors @@ -43,7 +46,7 @@ def checker(directory_URL, file_name): return('No dates found') if __name__ == "__main__": - """for distro in [Arch, Debian, Kernel, OpenBSD]: + """for distro in [Arch, Ceph, Debian, Eclipse, GNU, 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)