forked from public/mirror-checker
error on 404 and fix artix checker
This commit is contained in:
parent
25f6bf1921
commit
5d3a4b47b4
|
@ -31,9 +31,7 @@
|
||||||
"out_of_sync_since": null,
|
"out_of_sync_since": null,
|
||||||
"out_of_sync_interval": 86400,
|
"out_of_sync_interval": 86400,
|
||||||
"csc": "artixlinux/",
|
"csc": "artixlinux/",
|
||||||
"upstream": "https://mirror1.artixlinux.org/repos/",
|
"upstream": "https://mirror1.artixlinux.org/repos/"
|
||||||
"file": "lastupdate",
|
|
||||||
"exclude": true
|
|
||||||
},
|
},
|
||||||
"CentOS": {
|
"CentOS": {
|
||||||
"out_of_sync_since": null,
|
"out_of_sync_since": null,
|
||||||
|
|
2
main.py
2
main.py
|
@ -36,7 +36,7 @@ if __name__ == "__main__":
|
||||||
if data[project].get('exclude', False):
|
if data[project].get('exclude', False):
|
||||||
continue
|
continue
|
||||||
checker_result = project_class.check(data, project, current_time)
|
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:
|
if checker_result:
|
||||||
safe_print(f"Success: {project} up-to-date")
|
safe_print(f"Success: {project} up-to-date")
|
||||||
else:
|
else:
|
||||||
|
|
17
project.py
17
project.py
|
@ -18,17 +18,18 @@ class Project(ABC):
|
||||||
"""Check if project packages are up-to-date"""
|
"""Check if project packages are up-to-date"""
|
||||||
csc_url = CSC_MIRROR + data[project]["csc"] + data[project]["file"]
|
csc_url = CSC_MIRROR + data[project]["csc"] + data[project]["file"]
|
||||||
upstream_url = data[project]["upstream"] + 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:
|
if upstream == CSC:
|
||||||
return True
|
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:
|
try:
|
||||||
return int(upstream) - int(CSC) < data[project]["out_of_sync_interval"]
|
return int(upstream) - int(CSC) < data[project]["out_of_sync_interval"]
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
|
|
@ -2,8 +2,43 @@
|
||||||
Contains Artix class
|
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):
|
class Artix(Project):
|
||||||
"""Artix class"""
|
"""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
|
||||||
|
|
Loading…
Reference in New Issue