[elbe-devel] [PATCH 4/6] finetuning: implement <copy_to|from_partition /> for <image-finetuning>

Torben Hohn torben.hohn at linutronix.de
Wed Dec 19 17:02:02 CET 2018


image-finetuning is in the body of an <losetup> block.
allow copying artifact from/to a filesystem residing on an image partition.

Signed-off-by: Torben Hohn <torben.hohn at linutronix.de>
---
 elbepack/finetuning.py | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++
 schema/dbsfed.xsd      | 48 ++++++++++++++++++++++++++++++++++++
 2 files changed, 115 insertions(+)

diff --git a/elbepack/finetuning.py b/elbepack/finetuning.py
index 324aebef..3ef273d8 100644
--- a/elbepack/finetuning.py
+++ b/elbepack/finetuning.py
@@ -20,6 +20,7 @@ from apt.package import FetchError
 from elbepack.repomanager import UpdateRepo
 from elbepack.rpcaptcache import get_rpcaptcache
 from elbepack.shellhelper import CommandError
+from elbepack.filesystem import Filesystem
 
 
 class FinetuningException(Exception):
@@ -623,6 +624,72 @@ class ExtractPartitionAction(ImageFinetuningAction):
 FinetuningAction.register(ExtractPartitionAction)
 
 
+class CopyFromPartition(ImageFinetuningAction):
+
+    tag = 'copy_from_partition'
+
+    def __init__(self, node):
+        ImageFinetuningAction.__init__(self, node)
+
+    def execute(self, _log, _buildenv, _target):
+        raise NotImplementedError("<copy_from_partition> may only be "
+                                  "used in <mount_drive>")
+
+    def execute_img(self, log, _buildenv, target, builddir, loop_dev):
+        part_nr = self.node.et.attrib['part']
+        aname = self.node.et.attrib['artifact']
+
+        img_mnt = os.path.join(builddir, 'imagemnt')
+        mnt_fs = Filesystem(img_mnt)
+        fname = mnt_fs.fname(self.node.et.text)
+
+        cmd = 'mount "%sp%s" "%s"' % (loop_dev, part_nr, img_mnt)
+        log.do(cmd)
+
+        try:
+            cmd = 'cp "%s" "%s"' % (fname, os.path.join(builddir, aname))
+            log.do(cmd)
+
+            target.images.append(aname)
+        finally:
+            log.do('umount "%s"' % img_mnt)
+
+
+FinetuningAction.register(CopyFromPartition)
+
+
+class CopyToPartition(ImageFinetuningAction):
+
+    tag = 'copy_to_partition'
+
+    def __init__(self, node):
+        ImageFinetuningAction.__init__(self, node)
+
+    def execute(self, _log, _buildenv, _target):
+        raise NotImplementedError("<copy_to_partition> may only be "
+                                  "used in <mount_drive>")
+
+    def execute_img(self, log, _buildenv, _target, builddir, loop_dev):
+        part_nr = self.node.et.attrib['part']
+        aname = self.node.et.attrib['artifact']
+
+        img_mnt = os.path.join(builddir, 'imagemnt')
+        mnt_fs = Filesystem(img_mnt)
+        fname = mnt_fs.fname(self.node.et.text)
+
+        cmd = 'mount "%sp%s" "%s"' % (loop_dev, part_nr, img_mnt)
+        log.do(cmd)
+
+        try:
+            cmd = 'cp "%s" "%s"' % (os.path.join(builddir, aname), fname)
+            log.do(cmd)
+        finally:
+            log.do('umount "%s"' % img_mnt)
+
+
+FinetuningAction.register(CopyToPartition)
+
+
 def do_finetuning(xml, log, buildenv, target):
 
     if not xml.has('target/finetuning'):
diff --git a/schema/dbsfed.xsd b/schema/dbsfed.xsd
index b1fb0f45..bdd3d013 100644
--- a/schema/dbsfed.xsd
+++ b/schema/dbsfed.xsd
@@ -1944,6 +1944,22 @@
           </documentation>
         </annotation>
       </element>
+      <element name="copy_from_partition" type="rfs:copy_from_partition" minOccurs="0">
+        <annotation>
+          <documentation>
+	    Copy a file from a partition. The partition is mounted, and the file is then
+	    copied from the mounted filesystem into the builddir. Its marked as an Artifact.
+          </documentation>
+        </annotation>
+      </element>
+      <element name="copy_to_partition" type="rfs:copy_to_partition" minOccurs="0">
+        <annotation>
+          <documentation>
+	    Copy an artifact onto a partition. The partition is mounted, and the file is then
+	    copied into the mounted filesystem.
+          </documentation>
+        </annotation>
+      </element>
     </choice>
   </group>
 
@@ -1962,6 +1978,38 @@
     </simpleContent>
   </complexType>
 
+  <complexType name="copy_from_partition">
+    <annotation>
+      <documentation>
+        Attribute 'part' describes the partition to be mounted (nr).
+	The value of the tag describes the filename to be copied from the
+	Filesystem, after it has been mounted.
+	Attribute 'artifact' is the artifact name.
+      </documentation>
+    </annotation>
+    <simpleContent>
+      <extension base="rfs:string">
+        <attribute name="part" type="integer" use="required" />
+        <attribute name="artifact" type="string" use="required" />
+      </extension>
+    </simpleContent>
+  </complexType>
+  <complexType name="copy_to_partition">
+    <annotation>
+      <documentation>
+        Attribute 'part' describes the partition to be mounted (nr).
+	The value of the tag describes the filename where the artifact shall
+	be copied to, onto the filesystem, after it has been mounted.
+	Attribute 'artifact' is the artifact name.
+      </documentation>
+    </annotation>
+    <simpleContent>
+      <extension base="rfs:string">
+        <attribute name="part" type="integer" use="required" />
+        <attribute name="artifact" type="string" use="required" />
+      </extension>
+    </simpleContent>
+  </complexType>
   <complexType name="addgroup">
     <annotation>
       <documentation>
-- 
2.11.0




More information about the elbe-devel mailing list