|
| 1 | +# Thx Greg Davill |
| 2 | +# https://github.com/gregdavill/KiBuzzard |
| 3 | + |
| 4 | + |
| 5 | +import os |
| 6 | +from os import path |
| 7 | +import shutil |
| 8 | + |
| 9 | +src_path = path.join(os.path.abspath(path.dirname(__file__)),'..','Stretch') |
| 10 | + |
| 11 | +metadata_template = path.join(os.path.abspath(path.dirname(__file__)),'metadata_template.json') |
| 12 | +resources_path = path.join(os.path.abspath(path.dirname(__file__)),'resources') |
| 13 | +print(src_path) |
| 14 | + |
| 15 | +build_path = os.path.abspath(path.join('build')) |
| 16 | + |
| 17 | +try: |
| 18 | + shutil.rmtree(build_path) |
| 19 | +except FileNotFoundError: |
| 20 | + pass |
| 21 | +os.mkdir(build_path) |
| 22 | +os.mkdir(path.join(build_path,'plugin')) |
| 23 | +os.chdir(build_path) |
| 24 | + |
| 25 | +shutil.copytree(src_path, path.join(os.path.abspath('plugin'),'plugins')) |
| 26 | + |
| 27 | +# clean out any __pycache__ or .pyc files (https://stackoverflow.com/a/41386937) |
| 28 | +import pathlib |
| 29 | +[p.unlink() for p in pathlib.Path('.').rglob('*.py[co]')] |
| 30 | +[p.rmdir() for p in pathlib.Path('.').rglob('__pycache__')] |
| 31 | + |
| 32 | + |
| 33 | +# copy metadata |
| 34 | +shutil.copy(metadata_template, path.join('plugin','metadata.json')) |
| 35 | +# copy icon |
| 36 | +shutil.copytree(resources_path, path.join('plugin','resources')) |
| 37 | + |
| 38 | +# load up json script |
| 39 | +from pathlib import Path |
| 40 | +import json |
| 41 | +with open(metadata_template) as f: |
| 42 | + md = json.load(f) |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | +# zip all files |
| 47 | +zip_file = 'Stretch-{0}-pcm.zip'.format(md['versions'][0]['version']) |
| 48 | +shutil.make_archive(Path(zip_file).stem, 'zip', 'plugin') |
| 49 | + |
| 50 | + |
| 51 | +zip_size = path.getsize(zip_file) |
| 52 | + |
| 53 | + |
| 54 | +uncompressed_size = sum(f.stat().st_size for f in Path('plugin').glob('**/*') if f.is_file()) |
| 55 | + |
| 56 | +import hashlib |
| 57 | +with open(zip_file, 'rb') as f: |
| 58 | + zip_sha256 = hashlib.sha256(f.read()).hexdigest() |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | +md['versions'][0].update({ |
| 63 | + 'install_size': uncompressed_size, |
| 64 | + 'download_size': zip_size, |
| 65 | + 'download_sha256': zip_sha256, |
| 66 | + 'download_url': 'https://github.com/JarrettR/Stretch/releases/download/{0}/Stretch-{0}-pcm.zip'.format(md['versions'][0]['version']) |
| 67 | +}) |
| 68 | + |
| 69 | +with open('metadata.json', 'w') as of: |
| 70 | + json.dump(md, of, indent=2) |
0 commit comments