Created Eclipse mirror status checker

dev
Laura Nguyen 1 year ago
parent 908d7f200e
commit bae3d74f00
  1. 2
      arch.py
  2. 3
      constants.py
  3. 2
      debian.py
  4. 21
      eclipse.py
  5. 2
      kernel.py
  6. 3
      main.py
  7. 13
      openbsd.py
  8. 10
      shared.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"""

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

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

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

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

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

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

@ -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)
Loading…
Cancel
Save