Created Eclipse mirror status checker

This commit is contained in:
Laura Nguyen 2021-08-24 17:00:51 -04:00
parent 908d7f200e
commit bae3d74f00
8 changed files with 39 additions and 17 deletions

View File

@ -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"""

View File

@ -1,3 +0,0 @@
"""Contains shared constants"""
CSC_MIRROR = "http://mirror.csclub.uwaterloo.ca/"

View File

@ -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"""

21
eclipse.py Normal file
View File

@ -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

View File

@ -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"""

View File

@ -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:

View File

@ -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

10
shared.py Normal file
View File

@ -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)