79 lines
3.0 KiB
Python
79 lines
3.0 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"],
|
|
["../Deliveroo/Deliveroo", "Deliveroo", "Deliveroo"],
|
|
["../ARControl/ARControl", "ARControl", "ARControl"],
|
|
["../Workshoppa/Workshoppa", "Workshoppa", "Workshoppa"],
|
|
]
|
|
|
|
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) |