[elbe-devel] [PATCH v3 2/4] finetuning: implement <copy_to|from_partition /> for <image-finetuning>
Torben Hohn
torben.hohn at linutronix.de
Tue Jan 8 11:56:49 CET 2019
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 | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++
schema/dbsfed.xsd | 48 +++++++++++++++++++++++++++++++++++
2 files changed, 117 insertions(+)
diff --git a/elbepack/finetuning.py b/elbepack/finetuning.py
index 324aebef..3c9e9eef 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 ImgMountFilesystem
class FinetuningException(Exception):
@@ -623,6 +624,74 @@ 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')
+ device = "%sp%s" % (loop_dev, part_nr)
+
+ with ImgMountFilesystem(img_mnt, device, log) as mnt_fs:
+ fname = mnt_fs.glob(self.node.et.text)
+
+ if not fname:
+ log.printo('No file matching "%s" found' % self.node.et.text)
+ raise FinetuningException('No File found')
+
+ if len(fname) > 1:
+ log.printo('Pattern "%s" matches %d files' % (
+ self.node.et.text,
+ len(fname)))
+ raise FinetuningException('Patter matches too many files')
+
+ cmd = 'cp "%s" "%s"' % (fname[0], os.path.join(builddir, aname))
+ log.do(cmd)
+
+ target.images.append(aname)
+
+
+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')
+ device = "%sp%s" % (loop_dev, part_nr)
+
+ with ImgMountFilesystem(img_mnt, device, log) as mnt_fs:
+ fname = mnt_fs.fname(self.node.et.text)
+
+ cmd = 'cp "%s" "%s"' % (os.path.join(builddir, aname), fname)
+ log.do(cmd)
+
+
+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