projects/apache: correctly parse Apache's timestamp file
This commit is contained in:
parent
76f7863a85
commit
f408922a96
|
@ -3,7 +3,35 @@ Contains Apache class
|
|||
"""
|
||||
|
||||
from project import Project
|
||||
|
||||
from shared import CSC_MIRROR
|
||||
import requests
|
||||
|
||||
class Apache(Project):
|
||||
"""Apache class"""
|
||||
"""Apache class"""
|
||||
|
||||
# Apache's time file has two segments, so we need a special function
|
||||
# Example: 1648323001 rsync-he-fi
|
||||
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"]
|
||||
|
||||
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 get_timestamp_from_apache(upstream) - get_timestamp_from_apache(CSC) < data[project]["out_of_sync_interval"]
|
||||
except ValueError:
|
||||
print("failed to parse apache")
|
||||
return False
|
||||
|
||||
def get_timestamp_from_apache(s: str) -> int:
|
||||
real_time = s.split(" ")[0]
|
||||
return int(real_time)
|
||||
|
|
Loading…
Reference in New Issue