-
Notifications
You must be signed in to change notification settings - Fork 147
/
updateIndexes.py
executable file
·61 lines (49 loc) · 2.05 KB
/
updateIndexes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python3
"""Generates new manifest and icon indexes."""
import hashlib
import os
import plistlib
from datetime import datetime, timezone
from glob import glob
def main():
"""Main process."""
# Path to the ProfileManifests repo
repo_path = os.path.dirname(__file__)
# Iterate through index types
file_types = {"Icons": "png", "Manifests": "plist"}
for index_type, ext in file_types.items():
index = {"date": datetime.now(timezone.utc)}
# Get all matching files in the desired subfolder
file_list = glob("%s/%s/*/*.%s" % (repo_path, index_type, ext))
for path in sorted(file_list, key=lambda x: x.lower()):
rel_path = os.path.relpath(path, repo_path)
_, category, file_name = rel_path.split("/")
# Add placeholder for category subfolders
if category not in index:
index[category] = {}
if index_type == "Icons":
# Generate index information for icons
domain = file_name[: -len(ext) - 1]
with open(path, "rb") as f:
hash = hashlib.md5(f.read()).hexdigest()
index[category][domain] = {
"hash": hash,
"path": rel_path,
}
elif index_type == "Manifests":
# Generate index information for manifests
with open(path, "rb") as f:
manifest = plistlib.load(f)
domain = manifest.get("pfm_domain")
if "pfm_subdomain" in manifest:
domain += "-%s" % (manifest.get("pfm_subdomain"))
index[category][domain] = {
"modified": manifest.get("pfm_last_modified"),
"version": manifest.get("pfm_version"),
"path": rel_path,
}
# Write the new index file
with open(os.path.join(repo_path, index_type, "index"), "wb") as f:
f.write(plistlib.dumps(index))
if __name__ == "__main__":
main()