forked from public/mirror-checker
Compare commits
5 Commits
Author | SHA1 | Date |
---|---|---|
David Hui | 0b8787dd44 | |
Raymond Li | 8bc7461fbd | |
Rio Liu | 5d3a4b47b4 | |
Raymond Li | 25f6bf1921 | |
Raymond Li | 06f5f46bb1 |
13
data.json
13
data.json
|
@ -31,8 +31,7 @@
|
|||
"out_of_sync_since": null,
|
||||
"out_of_sync_interval": 86400,
|
||||
"csc": "artixlinux/",
|
||||
"upstream": "https://mirror1.artixlinux.org/repos/",
|
||||
"file": "lastupdate"
|
||||
"upstream": "https://mirror1.artixlinux.org/repos/"
|
||||
},
|
||||
"CentOS": {
|
||||
"out_of_sync_since": null,
|
||||
|
@ -132,7 +131,7 @@
|
|||
"GentooDistfiles": {
|
||||
"out_of_sync_since": null,
|
||||
"out_of_sync_interval": 86400,
|
||||
"csc": "gentoo-distfiles",
|
||||
"csc": "gentoo-distfiles/",
|
||||
"upstream": "http://gentoo.mirrors.tera-byte.com/",
|
||||
"file": "distfiles/timestamp.dev-local"
|
||||
},
|
||||
|
@ -273,7 +272,7 @@
|
|||
"out_of_sync_since": null,
|
||||
"out_of_sync_interval": 86400,
|
||||
"csc": "opensuse/update/",
|
||||
"upstream": "http://download.opensuse.org/update/",
|
||||
"upstream": "http://opensuse-mirror-gce-us.opensu.se/update/",
|
||||
"file": ""
|
||||
},
|
||||
"parabola": {
|
||||
|
@ -351,9 +350,9 @@
|
|||
"tdf": {
|
||||
"out_of_sync_since": null,
|
||||
"out_of_sync_interval": 86400,
|
||||
"csc": "",
|
||||
"upstream": "https://download.documentfoundation.org/TIMESTAMP",
|
||||
"file": "tdf/TIMESTAMP"
|
||||
"csc": "tdf/",
|
||||
"upstream": "https://download.documentfoundation.org/",
|
||||
"file": "TIMESTAMP"
|
||||
},
|
||||
"trisquel": {
|
||||
"out_of_sync_since": null,
|
||||
|
|
2
main.py
2
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:
|
||||
|
|
18
project.py
18
project.py
|
@ -3,6 +3,7 @@ Contains abstract class for a mirrored project
|
|||
"""
|
||||
|
||||
from abc import ABC
|
||||
import re
|
||||
|
||||
import requests
|
||||
|
||||
|
@ -17,4 +18,19 @@ 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"]
|
||||
return requests.get(csc_url).text == 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
|
||||
|
||||
try:
|
||||
return int(upstream) - int(CSC) < data[project]["out_of_sync_interval"]
|
||||
except ValueError:
|
||||
return False
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue