Skip to content

Commit

Permalink
tweak ControllerSet
Browse files Browse the repository at this point in the history
 * add a way to load just one controller
 * fetch the RepeatedController class from a projet specific location

neither used yet, but soon
  • Loading branch information
mwhudson committed Dec 19, 2019
1 parent b1fb405 commit ab6fdeb
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 20 deletions.
6 changes: 6 additions & 0 deletions subiquity/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from subiquitycore.controller import (
BaseController,
RepeatedController,
Skip,
)

Expand All @@ -39,3 +40,8 @@ def start_ui(self):

def cancel(self):
pass


class RepeatedController(RepeatedController):

pass
2 changes: 2 additions & 0 deletions subiquity/controllers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from .mirror import MirrorController
from .network import NetworkController
from .refresh import RefreshController
from ..controller import RepeatedController
from .reporting import ReportingController
from .snaplist import SnapListController
from .ssh import SSHController
Expand All @@ -37,6 +38,7 @@
'MirrorController',
'NetworkController',
'RefreshController',
'RepeatedController',
'ReportingController',
'SnapListController',
'SSHController',
Expand Down
47 changes: 27 additions & 20 deletions subiquitycore/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
Context,
)
from subiquitycore.controller import (
RepeatedController,
Skip,
)
from subiquitycore.signals import Signal
Expand Down Expand Up @@ -289,27 +288,35 @@ class ControllerSet:

def __init__(self, app, names):
self.app = app
self.controller_names = names
self.controller_names = names[:]
self.index = -1
self.instances = []

def load(self):
controllers_mod = __import__(
self.controllers_mod = __import__(
'{}.controllers'.format(self.app.project), None, None, [''])
for name in self.controller_names:
log.debug("Importing controller: %s", name)
klass = getattr(controllers_mod, name+"Controller")
if hasattr(self, name):
c = 1
for instance in self.instances:
if isinstance(instance, klass):
c += 1
inst = RepeatedController(getattr(self, name), c)
name = inst.name
else:
inst = klass(self.app)
setattr(self, name, inst)
self.instances.append(inst)

def _get_controller_class(self, name):
return getattr(self.controllers_mod, name+"Controller")

def load(self, name):
self.controller_names.remove(name)
log.debug("Importing controller: %s", name)
klass = self._get_controller_class(name)
if hasattr(self, name):
c = 1
for instance in self.instances:
if isinstance(instance, klass):
c += 1
rep_cls = self._get_controller_class("Repeated")
inst = rep_cls(getattr(self, name), c)
name = inst.name
else:
inst = klass(self.app)
setattr(self, name, inst)
self.instances.append(inst)

def load_all(self):
while self.controller_names:
self.load(self.controller_names[0])

@property
def cur(self):
Expand Down Expand Up @@ -635,7 +642,7 @@ def run(self):
if self.opts.scripts:
self.run_scripts(self.opts.scripts)

self.controllers.load()
self.controllers.load_all()

initial_controller_index = 0

Expand Down

0 comments on commit ab6fdeb

Please sign in to comment.