mirror-checker/project.py

36 lines
894 B
Python
Raw Normal View History

2021-10-03 15:44:08 -04:00
"""
Contains abstract class for a mirrored project
"""
from abc import ABC
import re
2021-10-03 15:44:08 -04:00
import requests
from shared import CSC_MIRROR
class Project(ABC):
"""Abstract class for a mirrored project"""
@staticmethod
2021-11-14 20:44:42 -05:00
def check(data, project, current_time):
2021-10-03 15:44:08 -04:00
"""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
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:
return False