[Fedora-livecd-list] [PATCH] Enable reading of SquashFS compression type

Frederick Grose fgrose at gmail.com
Tue Feb 8 08:05:39 UTC 2011


Please review.  I'm not familiar with the preferred exception
reporting formats.
                          --Fred

Author: Frederick Grose <fgrose at gmail.com>
Date:   Tue Feb 8 02:47:25 2011 -0500

    Enable reading of SquashFS compression type.

    Support edit-livecd & livecd-creator base_on image options by
    adding the capability in fs.py to read the base_on image
    compression type.  Specifying a compressor type will override
    the default; specifying 'None' will trigger reading and using
    the base_on image's compression type.

diff --git a/docs/livecd-creator.pod b/docs/livecd-creator.pod
index 1827728..ce7b94e 100644
--- a/docs/livecd-creator.pod
+++ b/docs/livecd-creator.pod
@@ -47,6 +47,7 @@ xz is the default and works with 2.6.38 and later kernels.
 gzip works with all kernels.
 lzo works with 2.6.36 and later kernels.
 lzma will only work with custom kernels.
+Set to 'None' to force reading the compressor used in BASE_ON.
 If gzip is used, the -comp option is not passed to mksquashfs to allow the
use of older versions of mksquashfs.

 =item --releasever=VER
diff --git a/imgcreate/fs.py b/imgcreate/fs.py
index de61c7b..d5307a2 100644
--- a/imgcreate/fs.py
+++ b/imgcreate/fs.py
@@ -41,6 +41,35 @@ def makedirs(dirname):
         if e.errno != errno.EEXIST:
             raise

+def squashfs_compression_type(sqfs_img):
+    """Check the compression type of a SquashFS image. If the type cannot
be
+    ascertained, return 'undetermined'. The calling code must decide what
to
+    do."""
+
+    env = os.environ.copy()
+    env['LC_ALL'] = 'C'
+    args = ['/usr/sbin/unsquashfs', '-s', sqfs_img]
+    try:
+        p = subprocess.Popen(args, stdout=subprocess.PIPE,
+                             stderr=subprocess.PIPE, env=env)
+        out, err = p.communicate()
+    except OSError, e:
+        raise SquashfsError(u"Error white stat-ing '%s'\n'%s'" % (args, e))
+    except:
+        raise SquashfsError(u"Error while stat-ing '%s'" % args)
+    else:
+        if p.returncode != 0:
+            raise SquashfsError(
+                u"Error while stat-ing '%s'\n'%s'\nreturncode: '%s'" %
+                (args, err, p.returncode))
+        else:
+            compress_type = 'undetermined'
+            for l in out.splitlines():
+                if l.split(None, 1)[0] == 'Compression':
+                    compress_type = l.split()[1]
+                    break
+    return compress_type
+
 def mksquashfs(in_img, out_img, compress_type):
 # Allow gzip to work for older versions of mksquashfs
     if compress_type == "gzip":
diff --git a/imgcreate/live.py b/imgcreate/live.py
old mode 100644
new mode 100755
index bf3a4dd..f388825
--- a/imgcreate/live.py
+++ b/imgcreate/live.py
@@ -152,6 +152,12 @@ class LiveImageCreatorBase(LoopImageCreator):

         squashloop = DiskMount(LoopbackDisk(squashimg, 0), self._mkdtemp(),
"squashfs")

+        # 'self.compress_type = None' will force reading it from base_on.
+        if self.compress_type is None:
+            self.compress_type = squashfs_compression_type(squashimg)
+            if self.compress_type == 'undetermined':
+                # Default to 'gzip' for compatibility with older versions.
+                self.compress_type = 'gzip'
         try:
             if not squashloop.disk.exists():
                 raise CreatorError("'%s' is not a valid live CD ISO : "
diff --git a/tools/livecd-creator b/tools/livecd-creator
index 3424636..d997095 100755
--- a/tools/livecd-creator
+++ b/tools/livecd-creator
@@ -48,7 +48,11 @@ def parse_options(args):
     imgopt.add_option("", "--image-type", type="string", dest="image_type",
                       help=optparse.SUPPRESS_HELP)
     imgopt.add_option("", "--compression-type", type="string",
dest="compress_type",
-                      help="Compression type recognized by mksquashfs
(default xz needs a 2.6.38+ kernel, gzip works with all kernels, lzo needs a
2.6.36+ kernel, lzma needs custom kernel)",
+                      help="Compression type recognized by mksquashfs "
+                           "(default xz needs a 2.6.38+ kernel, gzip works
"
+                           "with all kernels, lzo needs a 2.6.36+ kernel,
lzma "
+                           "needs custom kernel.) Set to 'None' to force
read "
+                           "from base_on.",
                       default="xz")
     imgopt.add_option("", "--releasever", type="string", dest="releasever",
                       default=None,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.fedoraproject.org/pipermail/livecd/attachments/20110208/bcb30b98/attachment-0001.html 


More information about the livecd mailing list