Merge pull request 'Fix Artix checker and make wrong http code raise error' (#3) from artix-checker into master

Reviewed-on: public/mirror-checker#3
This commit is contained in:
Raymond Li 2022-02-02 22:26:49 -05:00
commit 8bc7461fbd
4 changed files with 47 additions and 13 deletions

View File

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

View File

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

View File

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

View File

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