summaryrefslogtreecommitdiff
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
parent82ae6038c00ca7ceb0e1ed206bd07157e1658f50 (diff)
downloadmorph-e28059250484aefc2cefcbe1316b709ee26bcf5b.tar.gz
Refactor system building to use syskind specific class
-rwxr-xr-xmorphlib/app.py2
-rw-r--r--morphlib/builder2.py52
-rwxr-xr-xtests.as-root/arm-system-writes-kernel.script2
-rwxr-xr-xtests.as-root/setup2
-rwxr-xr-xtests.as-root/system-overlap.script2
-rwxr-xr-xtests.branching/setup2
-rwxr-xr-xtests/setup2
7 files changed, 57 insertions, 7 deletions
diff --git a/morphlib/app.py b/morphlib/app.py
index 86575fcd..3fa84ac9 100755
--- a/morphlib/app.py
+++ b/morphlib/app.py
@@ -476,6 +476,8 @@ class Morph(cliapp.Application):
self.hookmgr = cliapp.HookManager()
self.hookmgr.new('new-build-command', cliapp.FilterHook())
+ self.system_kind_builder_factory = \
+ morphlib.builder2.SystemKindBuilderFactory()
def _itertriplets(self, args):
'''Generate repo, ref, filename triples from args.'''
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.'''
diff --git a/tests.as-root/arm-system-writes-kernel.script b/tests.as-root/arm-system-writes-kernel.script
index b9ac95b3..2f6a5f69 100755
--- a/tests.as-root/arm-system-writes-kernel.script
+++ b/tests.as-root/arm-system-writes-kernel.script
@@ -30,7 +30,7 @@ cat <<EOF >arm-system.morph
{
"name": "arm-system",
"kind": "system",
- "system-kind": "dummy",
+ "system-kind": "syslinux-disk",
"arch": "arm",
"disk-size": "1G",
"strata": [
diff --git a/tests.as-root/setup b/tests.as-root/setup
index 542fb36f..7564292a 100755
--- a/tests.as-root/setup
+++ b/tests.as-root/setup
@@ -106,7 +106,7 @@ cat <<EOF > hello-system.morph
{
"name": "hello-system",
"kind": "system",
- "system-kind": "dummy",
+ "system-kind": "syslinux-disk",
"arch": "$(uname -m)",
"disk-size": "1G",
"strata": [
diff --git a/tests.as-root/system-overlap.script b/tests.as-root/system-overlap.script
index 1c2e1180..4b39aa04 100755
--- a/tests.as-root/system-overlap.script
+++ b/tests.as-root/system-overlap.script
@@ -30,7 +30,7 @@ cat <<EOF >overlap-system.morph
{
"name": "overlap-system",
"kind": "system",
- "system-kind": "dummy",
+ "system-kind": "syslinux-disk",
"arch": "$(uname -m)",
"disk-size": "1G",
"strata": [
diff --git a/tests.branching/setup b/tests.branching/setup
index 24627bce..d659b1d0 100755
--- a/tests.branching/setup
+++ b/tests.branching/setup
@@ -48,7 +48,7 @@ cat <<EOF > "$DATADIR/morphs/hello-system.morph"
{
"name": "hello-system",
"kind": "system",
- "system-kind": "dummy",
+ "system-kind": "syslinux-disk",
"disk-size": "1G",
"strata": [
"hello-stratum"
diff --git a/tests/setup b/tests/setup
index ce187065..8d3ab5b5 100755
--- a/tests/setup
+++ b/tests/setup
@@ -106,7 +106,7 @@ cat <<EOF > hello-system.morph
{
"name": "hello-system",
"kind": "system",
- "system-kind": "dummy",
+ "system-kind": "syslinux-disk",
"disk-size": "1G",
"strata": [
"hello-stratum"