2020-12-26 15:11:32 +00:00
|
|
|
import yaml
|
|
|
|
import json
|
2021-01-04 14:19:10 +00:00
|
|
|
import os
|
2020-12-26 16:32:56 +00:00
|
|
|
from time import time
|
|
|
|
from sys import argv
|
|
|
|
from os.path import getmtime
|
2020-12-26 15:32:28 +00:00
|
|
|
from zipfile import ZipFile, ZIP_DEFLATED
|
2020-12-26 15:11:32 +00:00
|
|
|
|
|
|
|
DEFAULTS = {
|
|
|
|
'IsHide': False,
|
|
|
|
'IsTestingExclusive': False,
|
|
|
|
'ApplicableVersion': 'any',
|
|
|
|
}
|
|
|
|
|
|
|
|
DUPLICATES = {
|
|
|
|
'DownloadLinkInstall': ['DownloadLinkTesting', 'DownloadLinkUpdate'],
|
|
|
|
}
|
|
|
|
|
2020-12-26 15:32:28 +00:00
|
|
|
TRIMMED_KEYS = [
|
|
|
|
'Author',
|
|
|
|
'Name',
|
|
|
|
'Description',
|
|
|
|
'InternalName',
|
|
|
|
'AssemblyVersion',
|
|
|
|
'RepoUrl',
|
|
|
|
'ApplicableVersion',
|
|
|
|
'Tags',
|
|
|
|
'DalamudApiLevel',
|
|
|
|
]
|
|
|
|
|
2020-12-26 15:11:32 +00:00
|
|
|
def main():
|
2021-01-04 14:19:10 +00:00
|
|
|
# extract the manifests from inside the zip files
|
|
|
|
master = extract_manifests()
|
2020-12-26 15:32:28 +00:00
|
|
|
|
2021-01-04 14:19:10 +00:00
|
|
|
# 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)
|
2020-12-26 15:32:28 +00:00
|
|
|
|
2020-12-26 16:32:56 +00:00
|
|
|
# update the LastUpdated field in master
|
|
|
|
last_updated()
|
|
|
|
|
2021-01-04 14:19:10 +00:00
|
|
|
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'] = f'https://git.sr.ht/~jkcclemens/plugin_repo/blob/master/plugins/{manifest["InternalName"]}/latest.zip'
|
|
|
|
# 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
|
2020-12-26 15:11:32 +00:00
|
|
|
for source, keys in DUPLICATES.items():
|
|
|
|
for k in keys:
|
2021-01-04 14:19:10 +00:00
|
|
|
if k not in manifest:
|
|
|
|
manifest[k] = manifest[source]
|
|
|
|
|
|
|
|
def write_master(master):
|
2020-12-26 15:11:32 +00:00
|
|
|
# write as pretty json
|
|
|
|
with open('pluginmaster.json', 'w') as f:
|
|
|
|
json.dump(master, f, indent=4)
|
|
|
|
|
2020-12-26 15:32:28 +00:00
|
|
|
def trim_manifest(plugin):
|
|
|
|
return {k: plugin[k] for k in TRIMMED_KEYS if k in plugin}
|
|
|
|
|
2020-12-26 16:32:56 +00:00
|
|
|
def last_updated():
|
|
|
|
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 'LastUpdated' not in plugin or modified != int(plugin['LastUpdated']):
|
|
|
|
plugin['LastUpdated'] = str(modified)
|
|
|
|
|
|
|
|
with open('pluginmaster.json', 'w') as f:
|
|
|
|
json.dump(master, f, indent=4)
|
|
|
|
|
2020-12-26 15:11:32 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|