[elbe-devel] [PATCH 6/9] finetuning: implement <mount_drive> action
Torben Hohn
torben.hohn at linutronix.de
Wed Nov 28 17:29:01 CET 2018
<mount_drive> 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:
<mount_drive img="sda.img">
<extract_partition part="2">sda2.img</extract_partition>
</mount_drive>
the extract partition action is implemented in a followup patch.
---
elbepack/finetuning.py | 44 ++++++++++++++++++++++++++++++++++++++++++++
schema/dbsfed.xsd | 33 +++++++++++++++++++++++++++++++++
2 files changed, 77 insertions(+)
diff --git a/elbepack/finetuning.py b/elbepack/finetuning.py
index 1aaeda67..c53b13c6 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 MountDriveImageAction(FinetuningAction):
+
+ tag = 'mount_drive'
+
+ def __init__(self, node):
+ FinetuningAction.__init__(self, node)
+
+ def execute(self, _log, _buildenv, _target):
+ raise NotImplementedError("<mount_drive> 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(MountDriveImageAction)
+
+
def do_finetuning(xml, log, buildenv, target):
if not xml.has('target/finetuning'):
diff --git a/schema/dbsfed.xsd b/schema/dbsfed.xsd
index e0b6eecb..d9317c72 100644
--- a/schema/dbsfed.xsd
+++ b/schema/dbsfed.xsd
@@ -1890,6 +1890,39 @@
</documentation>
</annotation>
</element>
+ <element name="mount_drive" type="rfs:mount_drive" 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="mount_drive">
+ <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