2018-07-29 12:33:46 -04:00
|
|
|
"""Official TiLDA MK4 Badge Store App
|
|
|
|
|
|
|
|
switches between app libraries, updates and installs apps.
|
2018-07-15 06:53:48 -04:00
|
|
|
|
|
|
|
To publish apps use https://badge.emfcamp.org"""
|
|
|
|
|
|
|
|
___license___ = "MIT"
|
2018-07-29 12:33:46 -04:00
|
|
|
___title___ = "Badge Store"
|
2018-08-31 10:55:28 -04:00
|
|
|
___dependencies___ = ["badge_store", "dialogs", "ugfx_helper", "app", "database", "ospath"]
|
2018-07-22 06:34:07 -04:00
|
|
|
___categories___ = ["System"]
|
2018-07-15 06:53:48 -04:00
|
|
|
___bootstrapped___ = True
|
|
|
|
|
2018-08-31 10:55:28 -04:00
|
|
|
import ugfx_helper, os, database, wifi, app, ospath
|
2018-08-02 17:42:45 -04:00
|
|
|
from dialogs import *
|
|
|
|
from lib.badge_store import BadgeStore
|
2018-07-15 06:53:48 -04:00
|
|
|
|
|
|
|
### VIEWS ###
|
|
|
|
|
2018-08-21 15:47:39 -04:00
|
|
|
ugfx_helper.init()
|
|
|
|
|
2018-08-27 17:20:51 -04:00
|
|
|
url = database.get("badge_store.url", "http://badgeserver.emfcamp.org/2018")
|
|
|
|
repo = database.get("badge_store.repo", "emfcamp/Mk4-Apps")
|
|
|
|
ref = database.get("badge_store.ref", "master")
|
|
|
|
store = BadgeStore(url=url, repo=repo, ref=ref)
|
2018-08-02 17:42:45 -04:00
|
|
|
title = "TiLDA Badge Store"
|
|
|
|
|
2018-07-15 06:53:48 -04:00
|
|
|
def clear():
|
2018-08-31 10:55:28 -04:00
|
|
|
ugfx.clear()
|
2018-07-15 06:53:48 -04:00
|
|
|
|
2018-08-02 17:42:45 -04:00
|
|
|
def show_categories():
|
2018-08-31 10:55:28 -04:00
|
|
|
clear()
|
2018-08-02 17:42:45 -04:00
|
|
|
with WaitingMessage():
|
|
|
|
menu_items = [{"title": c, "category": c} for c in store.get_categories()]
|
2018-07-15 06:53:48 -04:00
|
|
|
|
2018-08-02 17:42:45 -04:00
|
|
|
option = prompt_option(menu_items, none_text="Back", text="Categories", title=title)
|
|
|
|
|
|
|
|
if option:
|
|
|
|
show_apps(option["category"])
|
|
|
|
else:
|
|
|
|
return
|
|
|
|
|
|
|
|
def show_apps(c):
|
2018-08-31 10:55:28 -04:00
|
|
|
clear()
|
2018-08-02 17:42:45 -04:00
|
|
|
menu_items = [{"title": a, "app": a} for a in store.get_apps(c)]
|
|
|
|
|
|
|
|
option = prompt_option(menu_items, none_text="Back", title=title)
|
2018-07-15 06:53:48 -04:00
|
|
|
|
2018-08-02 17:42:45 -04:00
|
|
|
if option:
|
|
|
|
show_app(option["app"])
|
|
|
|
else:
|
|
|
|
return
|
|
|
|
|
|
|
|
def show_app(a):
|
2018-08-31 10:55:28 -04:00
|
|
|
clear()
|
2018-08-02 17:42:45 -04:00
|
|
|
with WaitingMessage():
|
|
|
|
app_info = store.get_app(a)
|
|
|
|
|
|
|
|
install = prompt_boolean(app_info["description"], title=a, true_text="Install", false_text="Back")
|
|
|
|
|
|
|
|
if install:
|
|
|
|
with WaitingMessage(title="Installing %s" % a, text="Please wait...") as message:
|
2018-08-27 11:28:38 -04:00
|
|
|
installers = store.install(_get_current_apps() + [a])
|
2018-08-02 17:42:45 -04:00
|
|
|
n = len(installers)
|
|
|
|
for i, installer in enumerate(installers):
|
|
|
|
message.text = "%s (%s/%s)" % (installer.path, i + 1, n)
|
|
|
|
installer.download()
|
2018-08-31 10:55:28 -04:00
|
|
|
app.uncache_apps()
|
2018-08-02 17:42:45 -04:00
|
|
|
|
2018-08-31 10:55:28 -04:00
|
|
|
notice("App %s has been successfully installed" % a, title=title, close_text="Back")
|
2018-08-02 17:42:45 -04:00
|
|
|
|
|
|
|
def show_update():
|
2018-08-31 10:55:28 -04:00
|
|
|
clear()
|
|
|
|
update = prompt_boolean("Do you want to update all apps on this badge?", title="Update", true_text="OK", false_text="Back")
|
|
|
|
if update:
|
|
|
|
clear()
|
|
|
|
with WaitingMessage(title=title, text="Please wait...") as message:
|
|
|
|
installers = store.install(_get_current_apps())
|
|
|
|
n = len(installers)
|
|
|
|
for i, installer in enumerate(installers):
|
|
|
|
message.text = "%s (%s/%s)" % (installer.path, i + 1, n)
|
|
|
|
installer.download()
|
|
|
|
notice("Your badge has been successfully updated", title=title, close_text="Back")
|
2018-07-15 06:53:48 -04:00
|
|
|
|
2018-08-02 17:42:45 -04:00
|
|
|
def show_remove():
|
2018-08-31 10:55:28 -04:00
|
|
|
clear()
|
|
|
|
app_to_remove = prompt_option(_get_current_apps(), none_text="Back", text="Select App to remove")
|
|
|
|
if app_to_remove:
|
|
|
|
ospath.recursive_rmdir(app_to_remove)
|
|
|
|
app.uncache_apps()
|
|
|
|
notice("%s has been removed" % app_to_remove, title=title, close_text="Back")
|
2018-07-15 06:53:48 -04:00
|
|
|
|
|
|
|
def main_menu():
|
|
|
|
while True:
|
|
|
|
clear()
|
|
|
|
|
|
|
|
menu_items = [
|
2018-08-02 17:42:45 -04:00
|
|
|
{"title": "Install Apps", "function": show_categories},
|
2018-08-31 10:55:28 -04:00
|
|
|
{"title": "Update all Apps", "function": show_update},
|
|
|
|
{"title": "Remove App", "function": show_remove}
|
2018-07-15 06:53:48 -04:00
|
|
|
]
|
|
|
|
|
2018-08-02 17:42:45 -04:00
|
|
|
option = prompt_option(menu_items, none_text="Exit", text="What do you want to do?", title=title)
|
2018-07-15 06:53:48 -04:00
|
|
|
|
|
|
|
if option:
|
|
|
|
option["function"]()
|
2018-08-31 13:04:20 -04:00
|
|
|
else:
|
|
|
|
break
|
2018-07-15 06:53:48 -04:00
|
|
|
|
2018-08-23 18:07:25 -04:00
|
|
|
def _get_current_apps():
|
|
|
|
return [a.name for a in app.get_apps()]
|
|
|
|
|
2018-08-21 15:47:39 -04:00
|
|
|
wifi.connect(show_wait_message=True)
|
2018-07-15 06:53:48 -04:00
|
|
|
main_menu()
|
2018-08-31 10:55:28 -04:00
|
|
|
app.restart_to_default()
|