[elbe-devel] [PATCH v2 1/3] finetuning: Add command action in image context

Olivier Dion dion at linutronix.de
Mon Jun 29 21:00:39 CEST 2020


The command is executed with ELBE_MNT set to the mount point of the
target partition.

Note that the action is of type 'FinetuningAction' instead of
'ImageFinetuningAction'.  Since the latter constructor call the former
constructor directly, it doesn't change anything at this level.
However, if this change is not done, Python will for some reason get
confused about the type of the object (for 'command' node) and you
will get traceback saying that 'self.node' is not part of the object.

Signed-off-by: Olivier Dion <dion at linutronix.de>
---
 elbepack/finetuning.py | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/elbepack/finetuning.py b/elbepack/finetuning.py
index cfcb5af1..e48c4e01 100644
--- a/elbepack/finetuning.py
+++ b/elbepack/finetuning.py
@@ -383,6 +383,19 @@ class CmdAction(FinetuningAction):
     def __init__(self, node):
         FinetuningAction.__init__(self, node)
 
+    def execute_img(self, _buildenv, _target, builddir, loop_dev):
+
+        script = '\n'.join(line.lstrip(" \t")
+                           for line
+                           in self.node.et.text.strip("\n").splitlines())
+
+        mnt   = os.path.join(builddir, 'imagemnt')
+        dev   = "%sp%s" % (loop_dev, self.node.et.attrib["part"])
+
+        with ImgMountFilesystem(mnt, dev) as fs:
+            do("/bin/sh", stdin=script,
+               env_add={"ELBE_MNT": fs.path})
+
     def execute(self, _buildenv, target):
         with target:
             chroot(target.path, "/bin/sh", stdin=self.node.et.text)
@@ -538,7 +551,7 @@ class LosetupAction(FinetuningAction):
         loop_dev = get_command_out(cmd).strip()
         try:
             for i in self.node:
-                action = ImageFinetuningAction(i)
+                action = FinetuningAction(i)
                 action.execute_img(buildenv, target, builddir, loop_dev)
         finally:
             cmd = 'losetup --detach "%s"' % loop_dev
-- 
2.27.0



More information about the elbe-devel mailing list