From 5dd21e49b414f6f2640c81267389478ece6745be Mon Sep 17 00:00:00 2001 From: Marek Ventur Date: Sat, 1 Sep 2018 18:50:25 +0100 Subject: [PATCH] Add review_helper app --- lib/badge_store.py | 3 +++ review_helper/main.py | 62 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 review_helper/main.py diff --git a/lib/badge_store.py b/lib/badge_store.py index 2e4a825..4be17c6 100644 --- a/lib/badge_store.py +++ b/lib/badge_store.py @@ -28,6 +28,9 @@ class BadgeStore: def get_app(self, app): return self._call("app", {"app": app}) + def get_prs(self): + return self._call("prs") + def install(self, apps): return self._create_installers(self._call("install", {"apps": ",".join(apps)})) diff --git a/review_helper/main.py b/review_helper/main.py new file mode 100644 index 0000000..97e1e04 --- /dev/null +++ b/review_helper/main.py @@ -0,0 +1,62 @@ +"""Helps to test incoming PRs""" + +___name___ = "PR Review Helper" +___license___ = "MIT" +___categories___ = ["System"] +___dependencies___ = ["dialogs", "app", "ugfx_helper", "badge_store", "http", "stack_nav", "wifi"] +___bootstrapped___ = True + +import ugfx_helper, ugfx, wifi +from app import * +from dialogs import * +from stack_nav import * +from badge_store import BadgeStore + +title = "PR Review Helper" + +def install(state): + apps = set() + with WaitingMessage(title="Fetching apps", text="Please wait...") as message: + for category, a in state["store"].get_all_apps().items(): + apps.update(a) + + menu_items = [{"title": a, "app": a} for a in apps] + + option = prompt_option(menu_items, none_text="Back", title="title") + + if option: + state["app"] = option + return show_app + +def show_app(state): + a = state["app"]["app"] + with WaitingMessage(title="Installing %s" % a, text="Please wait...") as message: + apps_to_install = []#[a.name for a in get_apps()] + apps_to_install.append(a) + print(apps_to_install) + installers = state["store"].install(apps_to_install) + n = len(installers) + for i, installer in enumerate(installers): + message.text = "%s (%s/%s)" % (installer.path, i + 1, n) + installer.download() + + notice("App %s has been successfully installed" % a, title=title, close_text="Run it!") + App(a).boot() + +def entry_point(state): + url = database.get("badge_store.url", "http://badgeserver.emfcamp.org/2018") + repo = database.get("badge_store.repo", "emfcamp/Mk4-Apps") + store = BadgeStore(url=url, repo=repo) + + prs = store.get_prs() + selection = prompt_option(prs, text="Select PR", none_text="Exit", title=title) + if selection: + state["store"] = BadgeStore(url=url, repo=repo, ref=selection["ref"]) + return install + + +### ENTRY POINT ### +ugfx_helper.init() +wifi.connect(show_wait_message=True) +nav(entry_point) +app.restart_to_default()