[elbe-devel] [PATCH v2 4/8] hdimg efilesystem: compress images later in the process

Torben Hohn torben.hohn at linutronix.de
Wed Dec 5 09:54:08 CET 2018


Images are compressed directly in do_hdimg(). This is before
<project-finetuning> is executed.

To make it possible to mount an image in <project-finetuning> the
compression step needs to move to a step that is executed later.
While at it, prepare for different compressors.

Signed-off-by: Torben Hohn <torben.hohn at linutronix.de>
---
 elbepack/efilesystem.py | 14 ++++++++++++++
 elbepack/elbeproject.py |  2 ++
 elbepack/hdimg.py       | 13 +++----------
 3 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/elbepack/efilesystem.py b/elbepack/efilesystem.py
index e6a8c2ab..dd75cdd1 100644
--- a/elbepack/efilesystem.py
+++ b/elbepack/efilesystem.py
@@ -289,6 +289,7 @@ class TargetFs(ChRootFilesystem):
         self.log = log
         self.xml = xml
         self.images = []
+        self.image_packers = {}
 
     def write_fstab(self, xml):
         if not self.exists("etc"):
@@ -313,6 +314,9 @@ class TargetFs(ChRootFilesystem):
             grub_version,
             grub_fw_type)
 
+        for i in self.images:
+            self.image_packers[i] = ('gzip -f', '.gz')
+
         if self.xml.has("target/package/tar"):
             targz_name = self.xml.text("target/package/tar/name")
             try:
@@ -362,6 +366,16 @@ class TargetFs(ChRootFilesystem):
                 # error was logged; continue
                 pass
 
+    def pack_images(self, builddir):
+        for img, (packer, ending) in self.image_packers.items():
+            self.images.remove(img)
+            try:
+                self.log.do('%s "%s"' % (packer, os.path.join(builddir, img)))
+                # only add packed image when no exception is thrown
+                self.images.append(img + ending)
+            except CommandError:
+                pass
+
 
 class BuildImgFs(ChRootFilesystem):
     def __init__(self, path, interpreter):
diff --git a/elbepack/elbeproject.py b/elbepack/elbeproject.py
index 8f851562..709d9cb0 100644
--- a/elbepack/elbeproject.py
+++ b/elbepack/elbeproject.py
@@ -585,6 +585,8 @@ class ElbeProject (object):
                           self.targetfs,
                           self.builddir)
 
+        self.targetfs.pack_images(self.builddir)
+
         os.system('cat "%s"' % self.validationpath)
 
     def pdebuild_init(self):
diff --git a/elbepack/hdimg.py b/elbepack/hdimg.py
index 843c5f85..771c9a35 100644
--- a/elbepack/hdimg.py
+++ b/elbepack/hdimg.py
@@ -664,13 +664,6 @@ def do_hdimg(outf, xml, target, rfs, grub_version, grub_fw_type=None):
         if (i.tag == "msdoshd") or (i.tag == "gpthd"):
             add_binary_blob(outf, i, target)
 
-    gz_img_files = []
-    for i in set(img_files):
-        try:
-            outf.do('gzip -f "%s"' % os.path.join(target, i))
-            # only add gz to gz_img_files, if no exception is thrown
-            gz_img_files.append(i + ".gz")
-        except CommandError:
-            pass
-
-    return gz_img_files
+    # use set() to remove duplicates, but
+    # return a list
+    return list(set(img_files))
-- 
2.11.0




More information about the elbe-devel mailing list