From 6605f11d8d0b0445549d76038948a5a4ffd46739 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Mon, 16 Sep 2019 00:01:58 -0400 Subject: [PATCH] Update update.py script --- scripts/add_package.py | 50 ---------------- scripts/build.py | 5 -- scripts/update.py | 124 +++++++++++++++++++++++++++++++++++++++ scripts/update_builds.py | 88 --------------------------- 4 files changed, 124 insertions(+), 143 deletions(-) delete mode 100644 scripts/add_package.py create mode 100644 scripts/update.py delete mode 100644 scripts/update_builds.py diff --git a/scripts/add_package.py b/scripts/add_package.py deleted file mode 100644 index 283a02b7..00000000 --- a/scripts/add_package.py +++ /dev/null @@ -1,50 +0,0 @@ -import sys -import json -import os -import glob -import zipfile -import shutil -import build - - -PACKAGES_DIR = "../packages" -MANIFESTS_DIR = "manifests" -plugin_packages = sys.argv[1:] -slugs = set() - - -for package_src in plugin_packages: - # Open ZIP - z = zipfile.ZipFile(package_src) - manifest_src = [f for f in z.namelist() if f.endswith("/plugin.json")][0] - - # Read manifest - with z.open(manifest_src) as f: - manifest = json.load(f) - - # Review manifest - print(json.dumps(manifest, indent=" ")) - input() - - # Write manifest - slug = os.path.split(manifest_src)[0] - manifest_dest = os.path.join(MANIFESTS_DIR, slug + ".json") - with open(manifest_dest, "w") as f: - json.dump(manifest, f, indent=" ") - - # Copy package - package_dest = os.path.join(PACKAGES_DIR, os.path.basename(package_src)) - build.system(f"cp '{package_src}' '{package_dest}'") - build.system(f"touch '{package_dest}'") - - slugs.add(slug) - - -# Upload packages -build.system(f"cd {PACKAGES_DIR} && make upload") - -# Commit repository -build.system("git add manifests") -slugs_list = ", ".join(slugs) -build.system(f"git commit -m 'Update manifest for {slugs_list}'") -build.system("git push") diff --git a/scripts/build.py b/scripts/build.py index bcf588f8..e8d347b0 100644 --- a/scripts/build.py +++ b/scripts/build.py @@ -4,7 +4,6 @@ import sys RACK_SDK = os.path.abspath("Rack-SDK") STAGE_DIR = "stage" -PACKAGE_DIR = "../packages" def system(cmd): @@ -19,10 +18,6 @@ def stage_package(plugin_dir): system(f'mv {plugin_dir}/dist/*.zip {STAGE_DIR}/') -def move_stage(): - system(f'mv -vi {STAGE_DIR}/* {PACKAGE_DIR}/') - - def delete_stage(): system(f'rm -rf {STAGE_DIR}') diff --git a/scripts/update.py b/scripts/update.py new file mode 100644 index 00000000..08697495 --- /dev/null +++ b/scripts/update.py @@ -0,0 +1,124 @@ +import sys +import os +import glob +import json +import time +import build +import zipfile + + +PACKAGES_DIR = "../packages" +SCREENSHOTS_DIR = "../screenshots" +MANIFESTS_DIR = "manifests" +RACK_USER_DIR = "~/.Rack" +RACK_USER_PLUGIN_DIR = os.path.join(RACK_USER_DIR, "plugins-v1") + +# Update git before continuing +build.system("git pull") +build.system("git submodule update --init --recursive") + +plugin_filenames = sys.argv[1:] + +# Default to all repos, so all out-of-date repos are built +if not plugin_filenames: + plugin_filenames = glob.glob("repos/*") + +updated_slugs = set() + +for plugin_filename in plugin_filenames: + (plugin_basename, plugin_ext) = os.path.splitext(plugin_filename) + # Extract manifest from plugin dir or package + if os.path.isdir(plugin_filename): + manifest_filename = os.path.join(plugin_filename, "plugin.json") + try: + # Read manifest + with open(manifest_filename, "r") as f: + manifest = json.load(f) + except IOError: + # Skip plugins without plugin.json + continue + elif plugin_ext == ".zip": + # Open ZIP + z = zipfile.ZipFile(plugin_filename) + manifest_filename = [f for f in z.namelist() if f.endswith("/plugin.json")][0] + # Unzip manifest + with z.open(manifest_filename) as f: + manifest = json.load(f) + else: + raise Exception(f"Plugin {plugin_filename} must be a source dir or zip package") + + # Get library manifest + slug = manifest['slug'] + library_manifest_filename = os.path.join(MANIFESTS_DIR, f"{slug}.json") + + if os.path.isdir(plugin_filename): + # Check if the library manifest is up to date + try: + with open(library_manifest_filename, "r") as f: + library_manifest = json.load(f) + if library_manifest and manifest['version'] == library_manifest['version']: + continue + except IOError: + pass + + # Build repo + print() + print(f"Building {slug}") + try: + build.delete_stage() + build.build(plugin_filename) + build.system(f"cp -vi stage/* '{PACKAGES_DIR}'") + build.system(f"cp -vi stage/* '{RACK_USER_PLUGIN_DIR}'") + except Exception as e: + print(e) + print(f"{slug} build failed") + input() + continue + finally: + build.delete_stage() + + # Open plugin issue thread + os.system(f"qutebrowser 'https://github.com/VCVRack/library/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+in%3Atitle+{slug}' &") + + elif plugin_ext == ".zip": + # Review manifest for errors + print(json.dumps(manifest, indent=" ")) + print("Press enter to approve manifest") + input() + + # Copy package + package_dest = os.path.join(PACKAGES_DIR, os.path.basename(plugin_filename)) + build.system(f"cp '{plugin_filename}' '{package_dest}'") + build.system(f"touch '{package_dest}'") + + # Copy manifest + with open(library_manifest_filename, "w") as f: + json.dump(manifest, f, indent=" ") + + # Delete screenshot cache + screenshots_dir = os.path.join(SCREENSHOTS_DIR, slug) + build.system(f"rm -rf '{screenshots_dir}'") + + updated_slugs.add(slug) + + +if not updated_slugs: + print("Nothing to build") + exit(0) + + +print("Press enter to upload packages and push library repo") +input() + +# Upload packages +build.system("cd ../packages && make upload") + +# Commit repository +build.system("git add manifests") +built_slugs_str = ", ".join(updated_slugs) +build.system(f"git commit -m 'Update manifest for {built_slugs_str}'") +build.system("git push") + +print() +print(f"Built {built_slugs_str}") +print("Remember to generate and upload screenshots") diff --git a/scripts/update_builds.py b/scripts/update_builds.py deleted file mode 100644 index 5061a1e3..00000000 --- a/scripts/update_builds.py +++ /dev/null @@ -1,88 +0,0 @@ -import sys -import os -import glob -import json -import time -import build - - -build.system("git pull") -build.system("git submodule update --init --recursive") - - -plugin_dirs = sys.argv[1:] - -if not plugin_dirs: - plugin_dirs = glob.glob("repos/*") - -built_slugs = [] - -for plugin_dir in plugin_dirs: - manifest_filename = f"{plugin_dir}/plugin.json" - try: - with open(manifest_filename, "r") as f: - manifest = json.load(f) - except IOError: - # Skip plugins without plugin.json - continue - - slug = manifest['slug'] - library_manifest_filename = f"manifests/{slug}.json" - library_manifest = None - try: - with open(library_manifest_filename, "r") as f: - library_manifest = json.load(f) - except IOError: - pass - - # Check if the build is up to date - if library_manifest and manifest['version'] == library_manifest['version']: - continue - - # Build repo - print() - print(f"Building {slug}") - try: - build.build(plugin_dir) - build.move_stage() - except Exception as e: - print(e) - print(f"{slug} build failed") - input() - continue - finally: - build.delete_stage() - - # Copy manifest - with open(library_manifest_filename, "w") as f: - json.dump(manifest, f, indent=" ") - - built_slugs.append(slug) - # Open plugin issue thread - os.system(f"qutebrowser \"https://github.com/VCVRack/library/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+in%3Atitle+{slug}\" &") - - -if not built_slugs: - print("Nothing to build") - exit(0) - - -print("Press enter to upload packages and push library repo") -input() - -# Upload packages -build.system("cd ../packages && make upload") - -# Commit repository -build.system("git add manifests") -built_slugs_str = ", ".join(built_slugs) -build.system(f"git commit -m 'Update build for {built_slugs_str}'") -build.system("git push") - -# Delete screenshot cache -for slug in built_slugs: - build.system("rm -rf '../screenshots/{slug}'") - -print() -print("Built " + ", ".join(built_slugs)) -print("Remember to generate and upload screenshots")