diff --git a/main.py b/main.py index f5969f6..1f2c01c 100644 --- a/main.py +++ b/main.py @@ -34,7 +34,7 @@ if __name__ == "__main__": else: print(f"Failure: {project} out-of-sync") continue - checker_result = project_class.check(data, project) + checker_result = project_class.check(data, project, current_time) if checker_result: data[project]["out_of_sync_since"] = None elif data[project]["out_of_sync_since"] is None: diff --git a/project.py b/project.py index c2b280e..90664ad 100644 --- a/project.py +++ b/project.py @@ -13,7 +13,7 @@ class Project(ABC): """Abstract class for a mirrored project""" @staticmethod - def check(data, project): + def check(data, project, current_time): """Check if project packages are up-to-date""" csc_url = CSC_MIRROR + data[project]["csc"] + data[project]["file"] upstream_url = data[project]["upstream"] + data[project]["file"] diff --git a/projects/ctan.py b/projects/ctan.py index fbbdd13..788a93b 100644 --- a/projects/ctan.py +++ b/projects/ctan.py @@ -13,7 +13,7 @@ import re import pandas as pd class ctan(Project): - """cran class""" + """ctan class""" @staticmethod def check(data, project, current_time): page = requests.get(data[project]["upstream"]).text @@ -23,4 +23,4 @@ class ctan(Project): duration = pd.to_timedelta(m.group(0)) - return duration <= pd.to_timedelta(data[project]["out_of_sync_interval"], unit='s') \ No newline at end of file + return duration <= pd.to_timedelta(data[project]["out_of_sync_interval"], unit='s') diff --git a/projects/gentooportage.py b/projects/gentooportage.py index 3e25497..d216774 100644 --- a/projects/gentooportage.py +++ b/projects/gentooportage.py @@ -18,7 +18,7 @@ class GentooPortage(Project): """GentooPortage class""" @staticmethod - def check(data, project): + def check(data, project, current_time): """rsync_command = "rsync -q {}{} {}" os.system(rsync_command.format(data[project]["csc"], data[project]["file"], diff --git a/projects/gnome.py b/projects/gnome.py index d028479..dd1e85a 100644 --- a/projects/gnome.py +++ b/projects/gnome.py @@ -14,7 +14,7 @@ class GNOME(Project): """GNOME class""" @staticmethod - def check(data, project): + def check(data, project, current_time): file = data[project]["file1"] csc_versions = requests.get(CSC_MIRROR + data[project]["csc"] + file).text upstream_versions = requests.get(data[project]["upstream1"] + file).text diff --git a/projects/ipfire.py b/projects/ipfire.py index e7c24f4..77e6fd2 100644 --- a/projects/ipfire.py +++ b/projects/ipfire.py @@ -11,7 +11,7 @@ class IPFire(Project): """IPFire class""" @staticmethod - def check(data, project): + def check(data, project, current_time): ipfire_url = "https://mirrors.ipfire.org/mirrors/mirror.csclub.uwaterloo.ca" ipfire_text = requests.get(ipfire_url).text return ipfire_text.find("The mirror is up") != -1 diff --git a/projects/sage.py b/projects/sage.py index 49be2e8..3466376 100644 --- a/projects/sage.py +++ b/projects/sage.py @@ -5,38 +5,38 @@ from datetime import datetime from project import Project from shared import CSC_MIRROR -class sage(Project): - """sagemath class""" - - @staticmethod - def get_latest_date(dates): - dates = [list(datefinder.find_dates(date))[0] for date in dates] - return(max(dates)) - - @classmethod - def check(cls, data, project): - page1 = requests.get(CSC_MIRROR + data[project]["csc"] + data[project]["file"]).text - page2 = requests.get("http://mirrors.mit.edu/sage/src/index.html").text - page3 = requests.get("https://mirror.rcg.sfu.ca/mirror/sage/src/index.html").text - CSC_dates = re.findall(r'(\d{4}-\d{2}-\d{2} \d{2}:\d{2})', page1) - MIT_dates = re.findall(r'(\d{4}-\d{2}-\d{2} \d{2}:\d{2})', page2) - SFU_dates = re.findall(r'(\d{4}-\d{2}-\d{2} \d{2}:\d{2})', page3) - - # print(len(CSC_dates)) - # print(len(MIT_dates)) - # print(len(SFU_dates)) - # print(cls.get_latest_date(CSC_dates)) - # print(cls.get_latest_date(MIT_dates)) - # print(cls.get_latest_date(SFU_dates)) - - if len(CSC_dates) < max([len(MIT_dates), len(SFU_dates)]): - return False - elif len(CSC_dates) > max([len(MIT_dates), len(SFU_dates)]): - # if we have more entries than their mirror, ours must be the new one - # since distros only add new versions, and don't delete old versions - return True - if (cls.get_latest_date(CSC_dates) < max([cls.get_latest_date(MIT_dates),cls.get_latest_date(SFU_dates)])): - return False - return True - \ No newline at end of file +class sage(Project): + """sagemath class""" + + @staticmethod + def get_latest_date(dates): + dates = [list(datefinder.find_dates(date))[0] for date in dates] + return max(dates) + + @classmethod + def check(cls, data, project): + page1 = requests.get(CSC_MIRROR + data[project]["csc"] + data[project]["file"]).text + page2 = requests.get("http://mirrors.mit.edu/sage/src/index.html").text + page3 = requests.get("https://mirror.rcg.sfu.ca/mirror/sage/src/index.html").text + + CSC_dates = re.findall(r'(\d{4}-\d{2}-\d{2} \d{2}:\d{2})', page1) + MIT_dates = re.findall(r'(\d{4}-\d{2}-\d{2} \d{2}:\d{2})', page2) + SFU_dates = re.findall(r'(\d{4}-\d{2}-\d{2} \d{2}:\d{2})', page3) + + # print(len(CSC_dates)) + # print(len(MIT_dates)) + # print(len(SFU_dates)) + # print(cls.get_latest_date(CSC_dates)) + # print(cls.get_latest_date(MIT_dates)) + # print(cls.get_latest_date(SFU_dates)) + + if len(CSC_dates) < max([len(MIT_dates), len(SFU_dates)]): + return False + elif len(CSC_dates) > max([len(MIT_dates), len(SFU_dates)]): + # if we have more entries than their mirror, ours must be the new one + # since distros only add new versions, and don't delete old versions + return True + if cls.get_latest_date(CSC_dates) < max([cls.get_latest_date(MIT_dates), cls.get_latest_date(SFU_dates)]): + return False + return True diff --git a/projects/saltstack.py b/projects/saltstack.py index 8080938..7ec3d5b 100644 --- a/projects/saltstack.py +++ b/projects/saltstack.py @@ -5,21 +5,22 @@ from datetime import datetime from project import Project from shared import CSC_MIRROR + class saltstack(Project): - """saltstack class""" - - @staticmethod - def check(data, project): - csc_url = CSC_MIRROR + data[project]["csc"] + data[project]["file"] - upstream_url = data[project]["upstream"] + data[project]["file"] + """saltstack class""" - page1 = requests.get(csc_url).text - page2 = requests.get(upstream_url).text + @staticmethod + def check(data, project, current_time): + csc_url = CSC_MIRROR + data[project]["csc"] + data[project]["file"] + upstream_url = data[project]["upstream"] + data[project]["file"] - CSC_release = re.search(r'Latest release: (\d)+.(\d)+ \((.+)\)', page1) - upstream_release = re.search(r'Latest release: (\d)+.(\d)+ \((.+)\)', page2) - - # print(CSC_release.group(0)) - # print(upstream_release.group(0)) - - return CSC_release.group(0) == upstream_release.group(0) \ No newline at end of file + page1 = requests.get(csc_url).text + page2 = requests.get(upstream_url).text + + CSC_release = re.search(r'Latest release: (\d)+.(\d)+ \((.+)\)', page1) + upstream_release = re.search(r'Latest release: (\d)+.(\d)+ \((.+)\)', page2) + + # print(CSC_release.group(0)) + # print(upstream_release.group(0)) + + return CSC_release.group(0) == upstream_release.group(0)