|
|
|
@ -5,16 +5,35 @@ This mirror status checker determines whether CSC mirror is up-to-date with upst |
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
import time |
|
|
|
|
import os |
|
|
|
|
import sys |
|
|
|
|
import requests |
|
|
|
|
from almalinux import AlmaLinux |
|
|
|
|
from alpine import Alpine |
|
|
|
|
from apache import Apache |
|
|
|
|
from arch import Arch |
|
|
|
|
from centos import CentOS |
|
|
|
|
from ceph import Ceph |
|
|
|
|
from cpan import CPAN |
|
|
|
|
from cygwin import Cygwin |
|
|
|
|
from debian import Debian |
|
|
|
|
from debiancd import DebianCD |
|
|
|
|
from debianmultimedia import DebianMultimedia |
|
|
|
|
from debianports import DebianPorts |
|
|
|
|
from debiansecurity import DebianSecurity |
|
|
|
|
from eclipse import Eclipse |
|
|
|
|
from fedora import Fedora |
|
|
|
|
from freebsd import FreeBSD |
|
|
|
|
from gentoodistfiles import GentooDistfiles |
|
|
|
|
from gentooportage import GentooPortage |
|
|
|
|
from gnome import GNOME |
|
|
|
|
from gnu import GNU |
|
|
|
|
from gutenberg import Gutenberg |
|
|
|
|
from ipfire import IPFire |
|
|
|
|
from kde import KDE |
|
|
|
|
from kdeapplicationdata import KDEApplicationData |
|
|
|
|
from kernel import Kernel |
|
|
|
|
from openbsd import OpenBSD |
|
|
|
|
from shared import CSC_MIRROR |
|
|
|
|
from dateparser.search import search_dates # this library seems to be super slow but the other library: dateutil.parser gets some errors |
|
|
|
|
# http://theautomatic.net/2018/12/18/2-packages-for-extracting-dates-from-a-string-of-text-in-python/ |
|
|
|
|
import re # import regular expressions to remove stray numbers in string that might interfere with date finding |
|
|
|
@ -22,8 +41,6 @@ import json # import json to read distro info stored in json file |
|
|
|
|
|
|
|
|
|
import datefinder # another date finding library |
|
|
|
|
|
|
|
|
|
CSC_MIRROR = "http://mirror.csclub.uwaterloo.ca/" |
|
|
|
|
|
|
|
|
|
def checker(directory_URL, file_name): |
|
|
|
|
page = requests.get(directory_URL).text |
|
|
|
|
indexOfFile = page.find(file_name) |
|
|
|
@ -50,53 +67,7 @@ def checker(directory_URL, file_name): |
|
|
|
|
else: |
|
|
|
|
return('No dates found') |
|
|
|
|
|
|
|
|
|
def gentoo_portage_checker(data_json, distro_name): |
|
|
|
|
"""GentooPortage checker""" |
|
|
|
|
rsync_command = "rsync -q {}{} {}" |
|
|
|
|
os.system(rsync_command.format(data_json[distro_name]["csc"], |
|
|
|
|
data_json[distro_name]["file"], |
|
|
|
|
"csc_manifest")) |
|
|
|
|
os.system(rsync_command.format(data_json[distro_name]["upstream1"], |
|
|
|
|
data_json[distro_name]["file"], |
|
|
|
|
"upstream_manifest1")) |
|
|
|
|
os.system(rsync_command.format(data_json[distro_name]["upstream2"], |
|
|
|
|
data_json[distro_name]["file"], |
|
|
|
|
"upstream_manifest2")) |
|
|
|
|
stream1 = os.popen("diff csc_manifest upstream_manifest1") |
|
|
|
|
output1 = stream1.read() |
|
|
|
|
stream2 = os.popen("diff csc_manifest upstream_manifest2") |
|
|
|
|
output2 = stream2.read() |
|
|
|
|
os.system("rm csc_manifest") |
|
|
|
|
os.system("rm upstream_manifest1") |
|
|
|
|
os.system("rm upstream_manifest2") |
|
|
|
|
return 0 in [len(output1), len(output2)] |
|
|
|
|
|
|
|
|
|
def gnome_checker(data_json, distro_name): |
|
|
|
|
"""GNOME checker""" |
|
|
|
|
csc_url = CSC_MIRROR + data_json[distro_name]["file"] |
|
|
|
|
upstream_url1 = data_json[distro_name]["upstream1"] + data_json[distro_name]["file"] |
|
|
|
|
upstream_url2 = data_json[distro_name]["upstream2"] + data_json[distro_name]["file"] |
|
|
|
|
csc_gnome_text = requests.get(csc_url).text |
|
|
|
|
return csc_gnome_text in [requests.get(upstream_url1).text, requests.get(upstream_url2).text] |
|
|
|
|
|
|
|
|
|
def ipfire_checker(): |
|
|
|
|
"""IPFire checker""" |
|
|
|
|
ipfire_text = requests.get("https://mirrors.ipfire.org/mirrors/mirror.csclub.uwaterloo.ca").text |
|
|
|
|
return ipfire_text.find("The mirror is up") != -1 |
|
|
|
|
|
|
|
|
|
def general_checker(data_json, distro_name): |
|
|
|
|
"""General distro checker""" |
|
|
|
|
csc_url = CSC_MIRROR + data_json[distro_name]["csc"] + data_json[distro_name]["file"] |
|
|
|
|
upstream_url = data_json[distro_name]["upstream"] + data_json[distro_name]["file"] |
|
|
|
|
return requests.get(csc_url).text == requests.get(upstream_url).text |
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
|
"""for distro in [Arch, Ceph, Debian, Eclipse, GNU, Kernel, OpenBSD]: |
|
|
|
|
try: |
|
|
|
|
distro.print_output(distro.check()) |
|
|
|
|
except requests.exceptions.RequestException as err: |
|
|
|
|
print(f"Error: {distro.name()}\n{err}")""" |
|
|
|
|
|
|
|
|
|
"""distros = json.load(open('distros.json',)) |
|
|
|
|
print(distros) |
|
|
|
|
|
|
|
|
@ -114,36 +85,18 @@ if __name__ == "__main__": |
|
|
|
|
current_time = int(time.time()) |
|
|
|
|
for distro in distros: |
|
|
|
|
try: |
|
|
|
|
if distro == "CPAN": |
|
|
|
|
res_json = requests.get("http://mirrors.cpan.org/cpan-json.txt").json() |
|
|
|
|
for mirror in res_json: |
|
|
|
|
if mirror["url"] == f"{CSC_MIRROR}CPAN/": |
|
|
|
|
if current_time - int(mirror["age"]) \ |
|
|
|
|
> data[distro]["out_of_sync_interval"]: |
|
|
|
|
print(f"Failure: {distro} out-of-sync") |
|
|
|
|
else: |
|
|
|
|
print(f"Success: {distro} up-to-date") |
|
|
|
|
break |
|
|
|
|
if distro not in data: |
|
|
|
|
print(f"Failure: {distro} does not exist") |
|
|
|
|
continue |
|
|
|
|
if distro == "GentooPortage": |
|
|
|
|
checker_result = gentoo_portage_checker(data, distro) |
|
|
|
|
elif distro == "GNOME": |
|
|
|
|
gnome_text = requests.get("https://download.gnome.org/core/").text |
|
|
|
|
line_count = len(gnome_text.split('\n')) |
|
|
|
|
# Latest version is currently 41, which has line count of 49 |
|
|
|
|
if line_count == 49: |
|
|
|
|
checker_result = gnome_checker(data, distro) |
|
|
|
|
distro_class = getattr(sys.modules[__name__], distro) |
|
|
|
|
if distro == "CPAN": |
|
|
|
|
checker_result = distro_class.check(data, distro, current_time) |
|
|
|
|
if checker_result: |
|
|
|
|
print(f"Success: {distro} up-to-date") |
|
|
|
|
else: |
|
|
|
|
data[distro]["out_of_sync_since"] = None |
|
|
|
|
print(f"Failure: {distro} should check for latest version") |
|
|
|
|
continue |
|
|
|
|
elif distro == "IPFire": |
|
|
|
|
checker_result = ipfire_checker() |
|
|
|
|
elif distro not in data: |
|
|
|
|
print(f"Failure: {distro} does not exist") |
|
|
|
|
print(f"Failure: {distro} out-of-sync") |
|
|
|
|
continue |
|
|
|
|
else: |
|
|
|
|
checker_result = general_checker(data, distro) |
|
|
|
|
checker_result = distro_class.check(data, distro) |
|
|
|
|
if checker_result: |
|
|
|
|
data[distro]["out_of_sync_since"] = None |
|
|
|
|
elif data[distro]["out_of_sync_since"] is None: |
|
|
|
|