Make app start/stop observable

This commit is contained in:
Disassembler 2020-04-03 15:14:06 +02:00
parent 929e8d9a60
commit d3455b5dcd
No known key found for this signature in database
GPG Key ID: 524BD33A0EE29499
3 changed files with 22 additions and 4 deletions

View File

@ -63,11 +63,15 @@ def uninstall(app_name):
def start(app_name):
# Start all application containers
App(app_name).start()
queue = ActionQueue()
queue.start_app(App(app_name))
queue.process()
def stop(app_name):
# Stop all application containers
App(app_name).stop()
queue = ActionQueue()
queue.stop_app(App(app_name))
queue.process()
def status(app_name):
# Print status of all application containers

View File

@ -133,15 +133,23 @@ class App:
except FileNotFoundError:
pass
def start(self):
def start(self, observer=None):
# Start all application containers
if observer:
observer.units_total = len(self.containers)
for container in self.containers:
container.start()
if observer:
observer.units_done += 1
def stop(self):
def stop(self, observer=None):
# Stop all application containers
if observer:
observer.units_total = len(self.containers)
for container in self.containers:
container.stop()
if observer:
observer.units_done += 1
def status(self):
# Return status fo all application containers

View File

@ -54,6 +54,12 @@ class ActionQueue:
def uninstall_app(self, app):
self.queue.append(ActionItem(f'Uninstalling application {app.name}', app.uninstall))
def start_app(self, app):
self.queue.append(ActionItem(f'Starting application {app.name}', app.start))
def stop_app(self, app):
self.queue.append(ActionItem(f'Stopping application {app.name}', app.stop))
def process(self):
index = 0
queue_length = len(self.queue)