Simplify defining core with only the general flow.
Signed-off-by: Mathieu Trudel-Lapierre <mathieu.trudel-lapierre@canonical.com>
This commit is contained in:
parent
e85859fa62
commit
f6bb666c4d
|
@ -26,69 +26,13 @@ from subiquitycore.core import CoreControllerError, Controller as ControllerBase
|
||||||
log = logging.getLogger('console_conf.core')
|
log = logging.getLogger('console_conf.core')
|
||||||
|
|
||||||
|
|
||||||
class CoreControllerError(Exception):
|
|
||||||
""" Basecontroller exception """
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class Controller(ControllerBase):
|
class Controller(ControllerBase):
|
||||||
def __init__(self, ui, opts):
|
|
||||||
try:
|
|
||||||
prober = Prober(opts)
|
|
||||||
except ProberException as e:
|
|
||||||
err = "Prober init failed: {}".format(e)
|
|
||||||
log.exception(err)
|
|
||||||
raise CoreControllerError(err)
|
|
||||||
|
|
||||||
self.common = {
|
project = "console_conf"
|
||||||
"ui": ui,
|
controllers = {
|
||||||
"opts": opts,
|
"Welcome": None,
|
||||||
"signal": Signal(),
|
"Network": None,
|
||||||
"prober": prober,
|
"Identity": None,
|
||||||
"loop": None
|
"Login": None,
|
||||||
}
|
}
|
||||||
self.controllers = {
|
|
||||||
"Welcome": None,
|
|
||||||
"Network": None,
|
|
||||||
"Identity": None,
|
|
||||||
"Login": None,
|
|
||||||
}
|
|
||||||
self.common['controllers'] = self.controllers
|
|
||||||
|
|
||||||
def run(self):
|
|
||||||
if not hasattr(self, 'loop'):
|
|
||||||
palette = STYLES
|
|
||||||
additional_opts = {
|
|
||||||
'screen': urwid.raw_display.Screen(),
|
|
||||||
'unhandled_input': self.header_hotkeys,
|
|
||||||
'handle_mouse': False
|
|
||||||
}
|
|
||||||
if self.common['opts'].run_on_serial:
|
|
||||||
palette = STYLES_MONO
|
|
||||||
else:
|
|
||||||
additional_opts['screen'].set_terminal_properties(colors=256)
|
|
||||||
additional_opts['screen'].reset_default_terminal_palette()
|
|
||||||
|
|
||||||
evl = urwid.TornadoEventLoop(IOLoop())
|
|
||||||
self.common['loop'] = urwid.MainLoop(
|
|
||||||
self.common['ui'], palette, event_loop=evl, **additional_opts)
|
|
||||||
log.debug("Running event loop: {}".format(
|
|
||||||
self.common['loop'].event_loop))
|
|
||||||
|
|
||||||
try:
|
|
||||||
self.set_alarm_in(0.05, self.welcome)
|
|
||||||
for k in self.controllers.keys():
|
|
||||||
log.debug("Importing controller: {}".format(k))
|
|
||||||
klass = import_object(
|
|
||||||
"subiquitycore.controllers.{}Controller".format(
|
|
||||||
k))
|
|
||||||
klass = import_object(
|
|
||||||
"console_conf.controllers.{}Controller".format(
|
|
||||||
k))
|
|
||||||
self.controllers[k] = klass(self.common)
|
|
||||||
|
|
||||||
self._connect_base_signals()
|
|
||||||
self.common['loop'].run()
|
|
||||||
except:
|
|
||||||
log.exception("Exception in controller.run():")
|
|
||||||
raise
|
|
||||||
|
|
|
@ -30,6 +30,18 @@ class CoreControllerError(Exception):
|
||||||
|
|
||||||
|
|
||||||
class Controller:
|
class Controller:
|
||||||
|
|
||||||
|
project = "subiquitycore"
|
||||||
|
controllers = {
|
||||||
|
"Welcome": None,
|
||||||
|
"Installpath": None,
|
||||||
|
"Network": None,
|
||||||
|
"Filesystem": None,
|
||||||
|
"Identity": None,
|
||||||
|
"InstallProgress": None,
|
||||||
|
"Login": None,
|
||||||
|
}
|
||||||
|
|
||||||
def __init__(self, ui, opts):
|
def __init__(self, ui, opts):
|
||||||
try:
|
try:
|
||||||
prober = Prober(opts)
|
prober = Prober(opts)
|
||||||
|
@ -45,15 +57,6 @@ class Controller:
|
||||||
"prober": prober,
|
"prober": prober,
|
||||||
"loop": None
|
"loop": None
|
||||||
}
|
}
|
||||||
self.controllers = {
|
|
||||||
"Welcome": None,
|
|
||||||
"Installpath": None,
|
|
||||||
"Network": None,
|
|
||||||
"Filesystem": None,
|
|
||||||
"Identity": None,
|
|
||||||
"InstallProgress": None,
|
|
||||||
"Login": None,
|
|
||||||
}
|
|
||||||
self.common['controllers'] = self.controllers
|
self.common['controllers'] = self.controllers
|
||||||
|
|
||||||
def _connect_base_signals(self):
|
def _connect_base_signals(self):
|
||||||
|
@ -118,7 +121,7 @@ class Controller:
|
||||||
for k in self.controllers.keys():
|
for k in self.controllers.keys():
|
||||||
log.debug("Importing controller: {}".format(k))
|
log.debug("Importing controller: {}".format(k))
|
||||||
klass = import_object(
|
klass = import_object(
|
||||||
"subiquitycore.controllers.{}Controller".format(
|
("%s.controllers.{}Controller" % self.project).format(
|
||||||
k))
|
k))
|
||||||
self.controllers[k] = klass(self.common)
|
self.controllers[k] = klass(self.common)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue