-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_pluginmaster.py
105 lines (85 loc) · 2.88 KB
/
generate_pluginmaster.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import json
import os
from time import time
from sys import argv
from os.path import getmtime
from zipfile import ZipFile, ZIP_DEFLATED
BRANCH = os.environ['GITHUB_REF'].split('refs/heads/')[-1]
DOWNLOAD_URL = 'https://github.com/Aireil/MyDalamudPlugins/raw/{branch}/plugins/{plugin_name}/latest.zip'
DEFAULTS = {
'IsHide': False,
'IsTestingExclusive': False,
'ApplicableVersion': 'any',
}
DUPLICATES = {
'DownloadLinkInstall': ['DownloadLinkTesting', 'DownloadLinkUpdate'],
}
TRIMMED_KEYS = [
'Author',
'Name',
'Punchline',
'Description',
'Changelog',
'InternalName',
'AssemblyVersion',
'RepoUrl',
'ApplicableVersion',
'Tags',
'DalamudApiLevel',
'IconUrl',
'ImageUrls',
]
def main():
# extract the manifests from inside the zip files
master = extract_manifests()
# trim the manifests
master = [trim_manifest(manifest) for manifest in master]
# convert the list of manifests into a master list
add_extra_fields(master)
# write the master
write_master(master)
# update the LastUpdate field in master
last_update()
def extract_manifests():
manifests = []
for dirpath, dirnames, filenames in os.walk('./plugins'):
if len(filenames) == 0 or 'latest.zip' not in filenames:
continue
plugin_name = dirpath.split('/')[-1]
latest_zip = f'{dirpath}/latest.zip'
with ZipFile(latest_zip) as z:
manifest = json.loads(z.read(f'{plugin_name}.json').decode('utf-8'))
manifests.append(manifest)
return manifests
def add_extra_fields(manifests):
for manifest in manifests:
# generate the download link from the internal assembly name
manifest['DownloadLinkInstall'] = DOWNLOAD_URL.format(branch=BRANCH, plugin_name=manifest["InternalName"])
# add default values if missing
for k, v in DEFAULTS.items():
if k not in manifest:
manifest[k] = v
# duplicate keys as specified in DUPLICATES
for source, keys in DUPLICATES.items():
for k in keys:
if k not in manifest:
manifest[k] = manifest[source]
manifest['DownloadCount'] = 0
def write_master(master):
# write as pretty json
with open('pluginmaster.json', 'w') as f:
json.dump(master, f, indent=4)
def trim_manifest(plugin):
return {k: plugin[k] for k in TRIMMED_KEYS if k in plugin}
def last_update():
with open('pluginmaster.json') as f:
master = json.load(f)
for plugin in master:
latest = f'plugins/{plugin["InternalName"]}/latest.zip'
modified = int(getmtime(latest))
if 'LastUpdate' not in plugin or modified != int(plugin['LastUpdate']):
plugin['LastUpdate'] = str(modified)
with open('pluginmaster.json', 'w') as f:
json.dump(master, f, indent=4)
if __name__ == '__main__':
main()