Skip to content

Commit

Permalink
Address tomsci review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewWilkes committed Jun 4, 2022
1 parent 69f5b6b commit e188ee2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
24 changes: 16 additions & 8 deletions modules/app_store/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ def redraw(self):
if not woezel_repo.load():
try:
woezel_repo.update(_showProgress=self.progress)
except OSError:
pass
except:
time.sleep(2)
time.sleep(3)
self.return_back()

class InstallProgress(TextWindow):

def redraw(self):
self.cls()
self.println("Installing...")
self.println("Checking...")

def progress(self, text, *args, **kwargs):
for line in self.flow_lines(text):
Expand All @@ -56,17 +56,19 @@ def installer(self, slug):
print(f"Install option for {slug}")
def do_install():
print(f"installing {slug}")
progress = InstallProgress(self.return_back)
sub_buttons = Buttons()
progress = InstallProgress(self.return_back, buttons=sub_buttons)
progress.bg = self.bg
progress.fg = self.fg
self.push_window(progress)
try:
woezel.install(slug, progress=progress.progress)
except:
pass
time.sleep(3)
self.pop_window()
return do_install
sub_buttons.on_press(tidal.BUTTON_FRONT, self.pop_window, autorepeat=False)
sub_buttons.on_press(tidal.BUTTON_A, self.pop_window, autorepeat=False)
progress.progress("Press [A] to return to menu")
return do_install

def make_choice(self, item):
return item['name'], self.installer(item['slug'])
Expand All @@ -76,7 +78,7 @@ def _choices(self):
return [
self.make_choice(application)
for application in woezel_repo.getCategory(self.category)
]
] + [("Back...", self.pop_window)]

class Store(MenuApp):
APP_ID = "store"
Expand All @@ -86,6 +88,7 @@ class Store(MenuApp):
def choices(self):
# Note, the text for each choice needs to be <= 16 characters in order to fit on screen
choices = [self.make_choice(choice) for choice in woezel_repo.categories]
choices = choices + [("Refresh...", self.trigger_update)]
return choices

def make_choice(self, choice):
Expand Down Expand Up @@ -113,6 +116,11 @@ def do_launch():

def on_activate(self):
super().on_activate()
self.trigger_update(force=False)

def trigger_update(self, force=True):
if force:
woezel_repo.updatedThisBoot = False
update = UpdateProgress(buttons=Buttons())
update.buttons.on_press(tidal.BUTTON_FRONT, self.pop_window, autorepeat=False)
update.return_back = self.return_back
Expand Down
8 changes: 4 additions & 4 deletions modules/dashboard/resources/woezel_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
path = "/cache/woezel"
categories = []
lastUpdate = 0
updatedThisBoot = False

try:
uos.mkdir("/cache")
Expand Down Expand Up @@ -37,7 +38,7 @@ def showProgress(msg, error=False, icon_wifi=False):
#easydraw.messageCentered(msg, False, icon)

def update(_showProgress=showProgress):
global path, categories, lastUpdate
global path, categories, lastUpdate, updatedThisBoot
if not wifi.status():
_showProgress("Connecting to WiFi...", False, True)
wifi.connect()
Expand Down Expand Up @@ -66,6 +67,7 @@ def update(_showProgress=showProgress):
f.write(str(lastUpdate))
f.close()
_showProgress("Done!")
updatedThisBoot = True
gc.collect()
return True
except BaseException as e:
Expand All @@ -85,18 +87,16 @@ def load():
categories = json.loads(f.read())
f.close()
gc.collect()
if (lastUpdate + 900) < time.time() or time.time() < 900 or time.time() < lastUpdate:
if (lastUpdate + 900) < time.time() or not updatedThisBoot:
# Refresh the cash if it's been at least 15 minutes since the last refresh
# or if we're in the first 15 minutes of all time ;)
# or if the last update is in the future
# - We don't have RTC set up so the clock resets on each boot
print("Current repository cache is too old!", lastUpdate + 900, "<", int(time.time()))
#time.sleep(2)
return False
return True
except BaseException as e:
sys.print_exception(e)
time.sleep(2)
return False

def getCategory(slug):
Expand Down
7 changes: 4 additions & 3 deletions modules/woezel.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def install_pkg(pkg_spec, install_path, force_reinstall, progress=print):
progress("Package %s already installed" % (pkg_spec))
already_installed = True
else:
progress("Package %s not yet installed" % (pkg_spec))
progress("Installing %s..." % (pkg_spec))
else:
# fallback for unix version
progress("Package %s already installed" % (pkg_spec))
Expand Down Expand Up @@ -251,7 +251,7 @@ def install(to_install, install_path=None, force_reinstall=False, progress=print
install_path += "/"
if not isinstance(to_install, list):
to_install = [to_install]
progress("Installing to: " + install_path)
progress("Installation root: " + install_path)
# sets would be perfect here, but don't depend on them
installed = []
try:
Expand All @@ -270,10 +270,11 @@ def install(to_install, install_path=None, force_reinstall=False, progress=print
deps = deps.decode("utf-8").split("\n")
to_install.extend(deps)
except Exception as e:
progress("Error installing '{}': {}, packages may be partially installed".format(
progress("'{}' not installed: {}".format(
pkg_spec, e),
file=sys.stderr)
raise e
progress(f"Installed: {"\n ".join(installed)}")

def display_pkg(packages):
for package in packages:
Expand Down

0 comments on commit e188ee2

Please sign in to comment.