From 5d3a4b47b41fb349648c0ca22d83a1ed127f5ceb Mon Sep 17 00:00:00 2001 From: Rio Liu Date: Wed, 2 Feb 2022 22:08:16 -0500 Subject: [PATCH] error on 404 and fix artix checker --- data.json | 4 +--- main.py | 2 +- project.py | 17 +++++++++-------- projects/artix.py | 37 ++++++++++++++++++++++++++++++++++++- 4 files changed, 47 insertions(+), 13 deletions(-) diff --git a/data.json b/data.json index cbfa116..31c307a 100644 --- a/data.json +++ b/data.json @@ -31,9 +31,7 @@ "out_of_sync_since": null, "out_of_sync_interval": 86400, "csc": "artixlinux/", - "upstream": "https://mirror1.artixlinux.org/repos/", - "file": "lastupdate", - "exclude": true + "upstream": "https://mirror1.artixlinux.org/repos/" }, "CentOS": { "out_of_sync_since": null, diff --git a/main.py b/main.py index d8ab140..a91cb70 100644 --- a/main.py +++ b/main.py @@ -36,7 +36,7 @@ if __name__ == "__main__": if data[project].get('exclude', False): continue checker_result = project_class.check(data, project, current_time) - if project in ["CPAN", "ubuntu_releases", "manjaro", "mxlinux", "cran", "ctan", "gentooportage"]: + if project in ["CPAN", "ubuntu_releases", "manjaro", "mxlinux", "cran", "ctan", "gentooportage", "Artix"]: if checker_result: safe_print(f"Success: {project} up-to-date") else: diff --git a/project.py b/project.py index e3da361..b438e4a 100644 --- a/project.py +++ b/project.py @@ -18,17 +18,18 @@ class Project(ABC): """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"] - CSC = requests.get(csc_url).text - upstream = requests.get(upstream_url).text + + req = requests.get(csc_url) + req.raise_for_status() + CSC = req.text + + req = requests.get(upstream_url) + req.raise_for_status() + upstream = req.text + if upstream == CSC: return True - # Parse number differences - bad_re = '[a-zA-Z \-\n]+' - if re.search(bad_re, CSC): - # print(re.search(bad_re, CSC).group().strip()) - CSC = re.sub(bad_re, '', CSC) - upstream = re.sub(bad_re, '', upstream) try: return int(upstream) - int(CSC) < data[project]["out_of_sync_interval"] except ValueError: diff --git a/projects/artix.py b/projects/artix.py index c95e6cd..c3ace18 100644 --- a/projects/artix.py +++ b/projects/artix.py @@ -2,8 +2,43 @@ Contains Artix class """ -from project import Project +import re +from datetime import datetime +import requests +from project import Project +from shared import CSC_MIRROR + +def _get_date(url): + req = requests.head(url) + req.raise_for_status() + return datetime.strptime(req.headers['Last-Modified'], '%a, %d %b %Y %H:%M:%S %Z') class Artix(Project): """Artix class""" + @classmethod + def check(cls, data, project, current_time): + csc_url = CSC_MIRROR + data[project]['csc'] + upstream_url = data[project]['upstream'] + + req = requests.get(upstream_url) + req.raise_for_status() + index = req.text + + repos = re.findall(r'href="(\w+)/"', index); + + outdated_since = None + for repo in repos: + # Good enough for now, we can change it if Artix gets more arch in the future + db_path = repo + '/os/x86_64/' + repo + '.db' + upstream_date = _get_date(data[project]['upstream'] + db_path) + csc_date = _get_date(CSC_MIRROR + data[project]['csc'] + db_path) + if csc_date < upstream_date: + if outdated_since is None or upstream_date < outdated_since: + outdated_since = upstream_date + + if outdated_since is not None: + data[project]['out_of_sync_since'] = int(outdated_since.timestamp()) + return (datetime.now() - outdated_since).total_seconds() < data[project]['out_of_sync_interval'] + + return True