only use one file for config and data

This commit is contained in:
Max Erenberg 2022-01-05 20:16:35 -05:00
parent 771d95814f
commit c30c555782
2 changed files with 46 additions and 47 deletions

View File

@ -98,7 +98,8 @@
"out_of_sync_interval": 86400,
"csc": "",
"upstream": "https://deb.debian.org/",
"file": "debian-ports/project/trace/porta.debian.org"
"file": "debian-ports/project/trace/porta.debian.org",
"exclude": true
},
"DebianSecurity": {
"out_of_sync_since": null,
@ -265,7 +266,8 @@
"out_of_sync_interval": 86400,
"csc": "",
"upstream": "https://ftp.openbsd.org/pub/",
"file": "OpenBSD/timestamp"
"file": "OpenBSD/timestamp",
"exclude": true
},
"opensuse": {
"out_of_sync_since": null,
@ -286,7 +288,8 @@
"out_of_sync_interval": 86400,
"csc": "pkgsrc/",
"upstream": "http://ftp.netbsd.org/pub/pkgsrc/",
"file": "MIRROR-TIMESTAMP"
"file": "MIRROR-TIMESTAMP",
"exclude": true
},
"puppy_linux": {
"out_of_sync_since": null,
@ -300,7 +303,8 @@
"out_of_sync_interval": 86400,
"csc": "qtproject/",
"upstream": "https://download.qt.io/",
"file": "timestamp.txt"
"file": "timestamp.txt",
"exclude": true
},
"racket": {
"out_of_sync_since": null,

23
main.py
View File

@ -16,25 +16,21 @@ if __name__ == "__main__":
exit_code = 0
with open("data.json", "r", encoding="utf-8") as file:
data = json.load(file)
if sys.stdin.isatty():
projects = data
else:
projects = [project.rstrip() for project in sys.stdin.readlines()]
data_file = 'data.json'
if len(sys.argv) > 1:
data_file = sys.argv[1]
data = json.load(open(data_file))
current_time = int(time.time())
for project in projects:
for project in data:
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
if project in ["pkgsrc", "qtproject", "DebianPorts", "OpenBSD"]:
if data[project].get('exclude', False):
continue
if project in ["CPAN", "ubuntu", "ubuntu_releases", "manjaro", "mxlinux", "cran", "ctan", "gentooportage"]:
checker_result = project_class.check(data, project, current_time)
if project in ["CPAN", "ubuntu", "ubuntu_releases", "manjaro", "mxlinux", "cran", "ctan", "gentooportage"]:
if checker_result:
print(f"Success: {project} up-to-date")
else:
@ -43,7 +39,6 @@ if __name__ == "__main__":
# Exit with non-zero status if any of the projects are not up-to-date
exit_code = 1
continue
checker_result = project_class.check(data, project, current_time)
if checker_result:
data[project]["out_of_sync_since"] = None
elif data[project]["out_of_sync_since"] is None:
@ -58,7 +53,7 @@ if __name__ == "__main__":
print(f"Success: {project} up-to-date")
except requests.exceptions.RequestException as err:
print(f"Error: {project}\n{err}")
with open("data.json", "w", encoding="utf-8") as file:
with open(data_file, "w", encoding="utf-8") as file:
json.dump(data, file, indent='\t')
sys.exit(exit_code)