1+ import json
2+ import os
3+ from time import time
4+ from sys import argv
5+ from os .path import getmtime
6+ from zipfile import ZipFile , ZIP_DEFLATED
7+
8+ DOWNLOAD_URL = 'https://github.com/HaySome22/Repository/raw/master/plugins/{plugin_name}/latest.zip'
9+
10+ DEFAULTS = {
11+ 'IsHide' : False ,
12+ 'IsTestingExclusive' : False ,
13+ 'ApplicableVersion' : 'any' ,
14+ }
15+
16+ DUPLICATES = {
17+ 'DownloadLinkInstall' : ['DownloadLinkTesting' , 'DownloadLinkUpdate' ],
18+ }
19+
20+ TRIMMED_KEYS = [
21+ 'Author' ,
22+ 'Name' ,
23+ 'Description' ,
24+ 'InternalName' ,
25+ 'AssemblyVersion' ,
26+ 'RepoUrl' ,
27+ 'ApplicableVersion' ,
28+ 'Tags' ,
29+ 'DalamudApiLevel' ,
30+ 'IsTestingExclusive' ,
31+ 'IconUrl' ,
32+ ]
33+
34+ def main ():
35+ # extract the manifests from inside the zip files
36+ master = extract_manifests ()
37+
38+ # trim the manifests
39+ master = [trim_manifest (manifest ) for manifest in master ]
40+
41+ # convert the list of manifests into a master list
42+ add_extra_fields (master )
43+
44+ # update the LastUpdated field in master
45+ last_updated (master )
46+
47+ # write the master
48+ write_master (master )
49+
50+ def extract_manifests ():
51+ manifests = []
52+
53+ for dirpath , dirnames , filenames in os .walk ('./plugins' ):
54+ if len (filenames ) == 0 or 'latest.zip' not in filenames :
55+ continue
56+ plugin_name = dirpath .split ('/' )[- 1 ]
57+ latest_zip = f'{ dirpath } /latest.zip'
58+ print (f"plugin_name:{ plugin_name } " );
59+ with ZipFile (latest_zip ) as z :
60+ manifest = json .loads (z .read (f'{ plugin_name } .json' ).decode ('utf-8' ))
61+ manifests .append (manifest )
62+ return manifests
63+
64+ def add_extra_fields (manifests ):
65+ for manifest in manifests :
66+ # generate the download link from the internal assembly name
67+ manifest ['DownloadLinkInstall' ] = DOWNLOAD_URL .format (plugin_name = manifest ["InternalName" ])
68+ # add default values if missing
69+ for k , v in DEFAULTS .items ():
70+ if k not in manifest :
71+ manifest [k ] = v
72+ # duplicate keys as specified in DUPLICATES
73+ for source , keys in DUPLICATES .items ():
74+ for k in keys :
75+ if k not in manifest :
76+ manifest [k ] = manifest [source ]
77+ manifest ['DownloadCount' ] = 0
78+
79+ def write_master (master ):
80+ # write as pretty json
81+ with open ('pluginmaster.json' , 'w' ) as f :
82+ json .dump (master , f , indent = 4 )
83+
84+ def trim_manifest (plugin ):
85+ return {k : plugin [k ] for k in TRIMMED_KEYS if k in plugin }
86+
87+ def last_updated (master ):
88+ for plugin in master :
89+ latest = f'plugins/{ plugin ["InternalName" ]} /latest.zip'
90+ modified = int (getmtime (latest ))
91+
92+ if 'LastUpdated' not in plugin or modified != int (plugin ['LastUpdated' ]):
93+ plugin ['LastUpdated' ] = str (modified )
94+
95+ if __name__ == '__main__' :
96+ main ()
0 commit comments