56 lines
1.7 KiB
Python
56 lines
1.7 KiB
Python
|
|
class StatusManager:
|
|
def __init__(self):
|
|
self.running_app = {}
|
|
self.last_status = {}
|
|
self.curr_status = {}
|
|
self.progress = {}
|
|
self.log = []
|
|
|
|
def is_running(self):
|
|
return len(self.running_app) > 0
|
|
|
|
def run_app(self, app_name, app):
|
|
self.running_app[app_name] = app
|
|
|
|
def end_app(self, app_name):
|
|
self.running_app.pop(app_name)
|
|
|
|
def set_status(self, app_name, runner_name, key, value):
|
|
self.last_status = self.curr_status
|
|
if app_name not in self.curr_status:
|
|
self.curr_status[app_name] = {}
|
|
if runner_name not in self.curr_status[app_name]:
|
|
self.curr_status[app_name][runner_name] = {}
|
|
self.curr_status[app_name][runner_name][key] = value
|
|
|
|
def set_progress(self, app_name, runner_name, key, curr_value, max_value):
|
|
if app_name not in self.progress:
|
|
self.progress[app_name] = {}
|
|
if runner_name not in self.progress[app_name]:
|
|
self.progress[app_name][runner_name] = {}
|
|
self.progress[app_name][runner_name][key] = (curr_value, max_value)
|
|
|
|
def get_status(self):
|
|
return self.curr_status
|
|
|
|
def get_progress(self):
|
|
return self.progress
|
|
|
|
def add_log(self, time_str, log_type, message):
|
|
self.log.append((time_str, log_type, message))
|
|
|
|
def get_log(self):
|
|
return self.log
|
|
|
|
def get_running_apps(self):
|
|
return list(self.running_app.keys())
|
|
|
|
def get_last_status(self):
|
|
return self.last_status
|
|
|
|
def reset_status(self):
|
|
self.last_status = {}
|
|
self.curr_status = {}
|
|
|
|
status_manager = StatusManager() |