Simplify defining core with only the general flow.

Signed-off-by: Mathieu Trudel-Lapierre <mathieu.trudel-lapierre@canonical.com>
This commit is contained in:
Mathieu Trudel-Lapierre 2016-06-30 14:50:21 -04:00
parent e85859fa62
commit f6bb666c4d
2 changed files with 20 additions and 73 deletions

View File

@ -26,69 +26,13 @@ from subiquitycore.core import CoreControllerError, Controller as ControllerBase
log = logging.getLogger('console_conf.core')
class CoreControllerError(Exception):
""" Basecontroller exception """
pass
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 = {
"ui": ui,
"opts": opts,
"signal": Signal(),
"prober": prober,
"loop": None
}
self.controllers = {
"Welcome": None,
"Network": None,
"Identity": None,
"Login": None,
}
self.common['controllers'] = self.controllers
project = "console_conf"
controllers = {
"Welcome": None,
"Network": None,
"Identity": None,
"Login": None,
}
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

View File

@ -30,6 +30,18 @@ class CoreControllerError(Exception):
class Controller:
project = "subiquitycore"
controllers = {
"Welcome": None,
"Installpath": None,
"Network": None,
"Filesystem": None,
"Identity": None,
"InstallProgress": None,
"Login": None,
}
def __init__(self, ui, opts):
try:
prober = Prober(opts)
@ -45,15 +57,6 @@ class Controller:
"prober": prober,
"loop": None
}
self.controllers = {
"Welcome": None,
"Installpath": None,
"Network": None,
"Filesystem": None,
"Identity": None,
"InstallProgress": None,
"Login": None,
}
self.common['controllers'] = self.controllers
def _connect_base_signals(self):
@ -118,7 +121,7 @@ class Controller:
for k in self.controllers.keys():
log.debug("Importing controller: {}".format(k))
klass = import_object(
"subiquitycore.controllers.{}Controller".format(
("%s.controllers.{}Controller" % self.project).format(
k))
self.controllers[k] = klass(self.common)