[elbe-devel] [PATCH v2 5/8] finetuning: implement <losetup> action
Torben Hohn
torben.hohn at linutronix.de
Wed Dec 5 09:54:09 CET 2018
<losetup> is an action for <project-finetuning>
it nests around other actions, which are ImageFinetuning
actions. These have an execute_img() method which adds
the name of the loop_device to the parameter list.
example:
<losetup img="sda.img">
<extract_partition part="2">sda2.img</extract_partition>
</losetup>
the extract partition action is implemented in a followup patch.
Signed-off-by: Torben Hohn <torben.hohn at linutronix.de>
---
elbepack/finetuning.py | 44 ++++++++++++++++++++++++++++++++++++++++++++
schema/dbsfed.xsd | 33 +++++++++++++++++++++++++++++++++
2 files changed, 77 insertions(+)
diff --git a/elbepack/finetuning.py b/elbepack/finetuning.py
index e2ad0c8c..a499b56e 100644
--- a/elbepack/finetuning.py
+++ b/elbepack/finetuning.py
@@ -44,6 +44,21 @@ class FinetuningAction(object):
self.execute(log, buildenv, target)
+class ImageFinetuningAction(FinetuningAction):
+
+ tag = 'image_finetuning'
+
+ def __init__(self, node):
+ FinetuningAction.__init__(self, node)
+
+ def execute(self, _log, _buildenv, _target):
+ raise NotImplementedError("<%s> may only be "
+ "used in <image-finetuning>" % self.tag)
+
+ def execute_img(self, _log, _buildenv, _target, _builddir, _loop_dev):
+ raise NotImplementedError('execute_img() not implemented')
+
+
class RmAction(FinetuningAction):
tag = 'rm'
@@ -525,6 +540,35 @@ class RmArtifactAction(FinetuningAction):
FinetuningAction.register(ArtifactAction)
+class LosetupAction(FinetuningAction):
+
+ tag = 'losetup'
+
+ def __init__(self, node):
+ FinetuningAction.__init__(self, node)
+
+ def execute(self, _log, _buildenv, _target):
+ raise NotImplementedError("<losetup> may only be "
+ "used in <project-finetuning>")
+
+ def execute_prj(self, log, buildenv, target, builddir):
+ imgname = self.node.et.attrib['img']
+ imgpath = os.path.join(builddir, imgname)
+ cmd = 'losetup --find --show --partscan "%s"' % imgpath
+
+ loop_dev = log.get_command_out(cmd).strip()
+ try:
+ for i in self.node:
+ action = ImageFinetuningAction(i)
+ action.execute_img(log, buildenv, target, builddir, loop_dev)
+ finally:
+ cmd = 'losetup --detach "%s"' % loop_dev
+ log.do(cmd)
+
+
+FinetuningAction.register(LosetupAction)
+
+
def do_finetuning(xml, log, buildenv, target):
if not xml.has('target/finetuning'):
diff --git a/schema/dbsfed.xsd b/schema/dbsfed.xsd
index 55b1bb6d..88f4d9cf 100644
--- a/schema/dbsfed.xsd
+++ b/schema/dbsfed.xsd
@@ -1907,6 +1907,39 @@
</documentation>
</annotation>
</element>
+ <element name="losetup" type="rfs:losetup" minOccurs="0">
+ <annotation>
+ <documentation>
+ Setup the loop device with an image file. This node wraps image_finetuning
+ Actions, which access the loop device then.
+ </documentation>
+ </annotation>
+ </element>
+ </choice>
+ </group>
+
+ <complexType name="losetup">
+ <annotation>
+ <documentation>
+ Container for image_finetuning commands; these commands are executed in the
+ project directory, while a drive image is setup as a loop device.
+ The loop device id is passed to the individual actions.
+ </documentation>
+ </annotation>
+ <sequence>
+ <group ref="rfs:image_action" minOccurs="0" maxOccurs="unbounded" />
+ </sequence>
+ <attribute ref="xml:base"/>
+ <attribute name="img" type="string" use="required" />
+ </complexType>
+
+ <group name="image_action">
+ <annotation>
+ <documentation>
+ definition of image finetuning commands
+ </documentation>
+ </annotation>
+ <choice>
</choice>
</group>
--
2.11.0
More information about the elbe-devel
mailing list