summaryrefslogtreecommitdiff
path: root/morphlib/builder2.py
diff options
context:
space:
mode:
authorLars Wirzenius <lars.wirzenius@codethink.co.uk>2012-07-19 18:37:54 +0100
committerLars Wirzenius <lars.wirzenius@codethink.co.uk>2012-07-26 11:59:13 +0100
commite28059250484aefc2cefcbe1316b709ee26bcf5b (patch)
tree12661891770c3faec5812862d1b8b37e065b1517 /morphlib/builder2.py
parent82ae6038c00ca7ceb0e1ed206bd07157e1658f50 (diff)
downloadmorph-e28059250484aefc2cefcbe1316b709ee26bcf5b.tar.gz
Refactor system building to use syskind specific class
Diffstat (limited to 'morphlib/builder2.py')
-rw-r--r--morphlib/builder2.py52
1 files changed, 50 insertions, 2 deletions
diff --git a/morphlib/builder2.py b/morphlib/builder2.py
index 2ae8785f..9bef5db7 100644
--- a/morphlib/builder2.py
+++ b/morphlib/builder2.py
@@ -467,9 +467,19 @@ class StratumBuilder(BuilderBase):
return [artifact]
-class SystemBuilder(BuilderBase): # pragma: no cover
+class SystemKindBuilder(BuilderBase): # pragma: no cover
+
+ '''Build a specific kind of a system.
+
+ Subclasses should set the ``system_kind`` attribute to the kind of
+ system they build.
+
+ '''
- '''Build system image artifacts.'''
+
+class SyslinuxDiskBuilder(SystemKindBuilder): # pragma: no cover
+
+ system_kind = 'syslinux-disk'
def build_and_cache(self):
with self.build_watch('overall-build'):
@@ -700,6 +710,44 @@ class SystemBuilder(BuilderBase): # pragma: no cover
morphlib.fsutils.undo_device_mapping(self.app.runcmd, image_name)
+
+class SystemKindBuilderFactory(object): # pragma: no cover
+
+ '''A factory class for SystemKindBuilder objects.'''
+
+ def __init__(self):
+ self.system_kinds = [
+ SyslinuxDiskBuilder,
+ ]
+
+ def register(self, klass):
+ self.system_kinds.append(klass)
+
+ def new(self, system_kind, args, kwargs):
+ for klass in self.system_kinds:
+ if klass.system_kind == system_kind:
+ return klass(*args, **kwargs)
+ raise morphlib.Error("Don't know how to build system kind %s" %
+ system_kind)
+
+
+class SystemBuilder(BuilderBase): # pragma: no cover
+
+ '''Build system image artifacts.'''
+
+ def __init__(self, *args, **kwargs):
+ BuilderBase.__init__(self, *args, **kwargs)
+ self.args = args
+ self.kwargs = kwargs
+
+ def build_and_cache(self):
+ system_kind = self.artifact.source.morphology['system-kind']
+ builder = self.app.system_kind_builder_factory.new(
+ system_kind, self.args, self.kwargs)
+ logging.debug('Building system with %s' % repr(builder))
+ return builder.build_and_cache()
+
+
class Builder(object): # pragma: no cover
'''Helper class to build with the right BuilderBase subclass.'''