1
0
plugin-repo/generate_pluginmaster.py
2023-09-09 19:10:51 +02:00

76 lines
2.9 KiB
Python

import datetime
import json
import os
from zipfile import ZipFile
import requests
plugin_names = [
# [path, internal name, github repo]
["../SliceIsRight", "SliceIsRight", "SliceIsRight"],
["../FishNotify", "FishNotify", "FishNotify"],
["../Pal/Pal.Client", "Palace Pal", "PalacePal"],
["../RetainerTrack/RetainerTrack", "RetainerTrack", "RetainerTrack"],
["../NewGamePlusAnywhere/NewGamePlusAnywhere", "NewGamePlusAnywhere", "NewGamePlusAnywhere"],
["../ARDiscard/ARDiscard", "ARDiscard", "ARDiscard"],
]
def extract_manifests():
manifests = []
for plugin_name in plugin_names:
path = f"{plugin_name[0]}/dist/{plugin_name[1]}"
for filename in [item for item in os.listdir(path) if item.endswith(".zip") ]:
print(f"== {filename} ==")
with ZipFile(f"{path}/{filename}", "r") as z:
manifest = json.loads(z.read(f"{plugin_name[1]}.json").decode())
manifest['InternalName'] = plugin_name[1]
releases = requests.get(f"https://git.carvel.li/api/v1/repos/liza/{plugin_name[2]}/releases?limit=1000").json()
manifest['DownloadCount'] = 0
manifest['LastUpdate'] = int(datetime.datetime.fromisoformat(releases[0].get('published_at').replace('Z', '+00:00')).timestamp())
changelog_counter = 0
changelog = ''
for release in releases:
for asset in release.get('assets'):
if asset.get('name').endswith('.zip'):
manifest['DownloadCount'] += asset.get('download_count')
if 'DownloadLinkInstall' not in manifest:
manifest["DownloadLinkInstall"] = manifest["DownloadLinkUpdate"] = asset.get('browser_download_url')
if changelog_counter < 5 and release.get('body'):
changelog_counter += 1
changelog += f"{release.get('tag_name')} ({datetime.datetime.fromisoformat(release.get('published_at').replace('Z', '+00:00')).date()})\n{release.get('body')}\n\n"
changelog = changelog.strip()
if changelog:
manifest['Changelog'] = changelog
print(changelog)
manifests.append(manifest)
return manifests
def add_extra_fields(manifests):
DEFAULTS = {
"IsHide": False,
"IsTestingExclusive": False,
"ApplicableVersion": "any",
}
for manifest in manifests:
for k, v in DEFAULTS.items():
if k not in manifest:
manifest[k] = v
def dump_master(manifests):
with open(f"dist/pluginmaster.json", "w") as f:
json.dump(manifests, f, indent=4)
if __name__ == "__main__":
manifests = extract_manifests()
add_extra_fields(manifests)
dump_master(manifests)