mirror-checker/projects/gentooportage.py

50 lines
1.7 KiB
Python
Raw Permalink Normal View History

2021-10-03 15:35:17 -04:00
"""
Contains GentooPortage class
"""
import os
2021-10-03 15:44:08 -04:00
from project import Project
2021-10-03 15:35:17 -04:00
2021-10-17 15:49:06 -04:00
import requests
import datefinder # another date finding library
from datetime import timedelta
import re
import pandas as pd
2021-10-03 15:35:17 -04:00
2021-10-03 15:44:08 -04:00
class GentooPortage(Project):
2021-10-03 15:35:17 -04:00
"""GentooPortage class"""
@staticmethod
2021-11-14 20:44:42 -05:00
def check(data, project, current_time):
2021-10-17 15:49:06 -04:00
"""rsync_command = "rsync -q {}{} {}"
2021-10-03 15:44:08 -04:00
os.system(rsync_command.format(data[project]["csc"],
data[project]["file"],
2021-10-03 15:35:17 -04:00
"csc_manifest"))
2021-10-03 15:44:08 -04:00
os.system(rsync_command.format(data[project]["upstream1"],
data[project]["file"],
2021-10-03 15:35:17 -04:00
"upstream_manifest1"))
2021-10-03 15:44:08 -04:00
os.system(rsync_command.format(data[project]["upstream2"],
data[project]["file"],
2021-10-03 15:35:17 -04:00
"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")
2021-10-17 15:49:06 -04:00
return 0 in [len(output1), len(output2)]"""
# i'm changing the above code to the bottom one, since the above one only works in linux
page = requests.get(data[project]["upstream"]).text
indexOfFile = page.find("rsync4.ca.gentoo.org")
m = re.search(r'(\d+ minutes?)|(\d+ hours?)|(\d+(\.)?\d+ days?)', page[indexOfFile:])
2021-10-17 15:49:06 -04:00
duration = pd.to_timedelta(m.group(0))
data[project]["out_of_sync_since"] = current_time - duration.total_seconds()
2021-10-17 15:49:06 -04:00
return duration <= pd.to_timedelta(data[project]["out_of_sync_interval"], unit='s')