forked from public/mirror-checker
only use one file for config and data
This commit is contained in:
parent
771d95814f
commit
c30c555782
12
data.json
12
data.json
|
@ -98,7 +98,8 @@
|
||||||
"out_of_sync_interval": 86400,
|
"out_of_sync_interval": 86400,
|
||||||
"csc": "",
|
"csc": "",
|
||||||
"upstream": "https://deb.debian.org/",
|
"upstream": "https://deb.debian.org/",
|
||||||
"file": "debian-ports/project/trace/porta.debian.org"
|
"file": "debian-ports/project/trace/porta.debian.org",
|
||||||
|
"exclude": true
|
||||||
},
|
},
|
||||||
"DebianSecurity": {
|
"DebianSecurity": {
|
||||||
"out_of_sync_since": null,
|
"out_of_sync_since": null,
|
||||||
|
@ -265,7 +266,8 @@
|
||||||
"out_of_sync_interval": 86400,
|
"out_of_sync_interval": 86400,
|
||||||
"csc": "",
|
"csc": "",
|
||||||
"upstream": "https://ftp.openbsd.org/pub/",
|
"upstream": "https://ftp.openbsd.org/pub/",
|
||||||
"file": "OpenBSD/timestamp"
|
"file": "OpenBSD/timestamp",
|
||||||
|
"exclude": true
|
||||||
},
|
},
|
||||||
"opensuse": {
|
"opensuse": {
|
||||||
"out_of_sync_since": null,
|
"out_of_sync_since": null,
|
||||||
|
@ -286,7 +288,8 @@
|
||||||
"out_of_sync_interval": 86400,
|
"out_of_sync_interval": 86400,
|
||||||
"csc": "pkgsrc/",
|
"csc": "pkgsrc/",
|
||||||
"upstream": "http://ftp.netbsd.org/pub/pkgsrc/",
|
"upstream": "http://ftp.netbsd.org/pub/pkgsrc/",
|
||||||
"file": "MIRROR-TIMESTAMP"
|
"file": "MIRROR-TIMESTAMP",
|
||||||
|
"exclude": true
|
||||||
},
|
},
|
||||||
"puppy_linux": {
|
"puppy_linux": {
|
||||||
"out_of_sync_since": null,
|
"out_of_sync_since": null,
|
||||||
|
@ -300,7 +303,8 @@
|
||||||
"out_of_sync_interval": 86400,
|
"out_of_sync_interval": 86400,
|
||||||
"csc": "qtproject/",
|
"csc": "qtproject/",
|
||||||
"upstream": "https://download.qt.io/",
|
"upstream": "https://download.qt.io/",
|
||||||
"file": "timestamp.txt"
|
"file": "timestamp.txt",
|
||||||
|
"exclude": true
|
||||||
},
|
},
|
||||||
"racket": {
|
"racket": {
|
||||||
"out_of_sync_since": null,
|
"out_of_sync_since": null,
|
||||||
|
|
81
main.py
81
main.py
|
@ -14,51 +14,46 @@ import json
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
exit_code = 0
|
exit_code = 0
|
||||||
|
|
||||||
with open("data.json", "r", encoding="utf-8") as file:
|
data_file = 'data.json'
|
||||||
data = json.load(file)
|
if len(sys.argv) > 1:
|
||||||
if sys.stdin.isatty():
|
data_file = sys.argv[1]
|
||||||
projects = data
|
data = json.load(open(data_file))
|
||||||
else:
|
|
||||||
projects = [project.rstrip() for project in sys.stdin.readlines()]
|
|
||||||
current_time = int(time.time())
|
|
||||||
for project in projects:
|
|
||||||
try:
|
|
||||||
if project not in data:
|
|
||||||
print(f"Failure: {project} does not exist")
|
|
||||||
continue
|
|
||||||
project_class = getattr(sys.modules[__name__], project)
|
|
||||||
|
|
||||||
# Skip projects we no longer mirror
|
current_time = int(time.time())
|
||||||
if project in ["pkgsrc", "qtproject", "DebianPorts", "OpenBSD"]:
|
for project in data:
|
||||||
continue
|
try:
|
||||||
if project in ["CPAN", "ubuntu", "ubuntu_releases", "manjaro", "mxlinux", "cran", "ctan", "gentooportage"]:
|
project_class = getattr(sys.modules[__name__], project)
|
||||||
checker_result = project_class.check(data, project, current_time)
|
|
||||||
if checker_result:
|
|
||||||
print(f"Success: {project} up-to-date")
|
|
||||||
else:
|
|
||||||
print(f"Failure: {project} out-of-sync")
|
|
||||||
|
|
||||||
# Exit with non-zero status if any of the projects are not up-to-date
|
# Skip projects we no longer mirror
|
||||||
exit_code = 1
|
if data[project].get('exclude', False):
|
||||||
continue
|
continue
|
||||||
checker_result = project_class.check(data, project, current_time)
|
checker_result = project_class.check(data, project, current_time)
|
||||||
if checker_result:
|
if project in ["CPAN", "ubuntu", "ubuntu_releases", "manjaro", "mxlinux", "cran", "ctan", "gentooportage"]:
|
||||||
data[project]["out_of_sync_since"] = None
|
if checker_result:
|
||||||
elif data[project]["out_of_sync_since"] is None:
|
print(f"Success: {project} up-to-date")
|
||||||
data[project]["out_of_sync_since"] = current_time
|
else:
|
||||||
elif current_time - data[project]["out_of_sync_since"] \
|
print(f"Failure: {project} out-of-sync")
|
||||||
> data[project]["out_of_sync_interval"]:
|
|
||||||
print(f"Failure: {project} out-of-sync")
|
|
||||||
|
|
||||||
# Exit with non-zero status if any of the projects are not up-to-date
|
# Exit with non-zero status if any of the projects are not up-to-date
|
||||||
exit_code = 1
|
exit_code = 1
|
||||||
continue
|
continue
|
||||||
print(f"Success: {project} up-to-date")
|
if checker_result:
|
||||||
except requests.exceptions.RequestException as err:
|
data[project]["out_of_sync_since"] = None
|
||||||
print(f"Error: {project}\n{err}")
|
elif data[project]["out_of_sync_since"] is None:
|
||||||
with open("data.json", "w", encoding="utf-8") as file:
|
data[project]["out_of_sync_since"] = current_time
|
||||||
json.dump(data, file, indent='\t')
|
elif current_time - data[project]["out_of_sync_since"] \
|
||||||
|
> data[project]["out_of_sync_interval"]:
|
||||||
|
print(f"Failure: {project} out-of-sync")
|
||||||
|
|
||||||
sys.exit(exit_code)
|
# Exit with non-zero status if any of the projects are not up-to-date
|
||||||
|
exit_code = 1
|
||||||
|
continue
|
||||||
|
print(f"Success: {project} up-to-date")
|
||||||
|
except requests.exceptions.RequestException as err:
|
||||||
|
print(f"Error: {project}\n{err}")
|
||||||
|
with open(data_file, "w", encoding="utf-8") as file:
|
||||||
|
json.dump(data, file, indent='\t')
|
||||||
|
|
||||||
|
sys.exit(exit_code)
|
||||||
|
|
Loading…
Reference in New Issue