<font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><div>Please review.  I&#39;m not familiar with the preferred exception</div><div>reporting formats.</div><div>                          --Fred</div><div>

<br></div><div>Author: Frederick Grose &lt;<a href="mailto:fgrose@gmail.com">fgrose@gmail.com</a>&gt;</div><div>Date:   Tue Feb 8 02:47:25 2011 -0500</div><div><br></div><div>    Enable reading of SquashFS compression type.</div>

<div>    </div><div>    Support edit-livecd &amp; livecd-creator base_on image options by</div><div>    adding the capability in fs.py to read the base_on image</div><div>    compression type.  Specifying a compressor type will override</div>

<div>    the default; specifying &#39;None&#39; will trigger reading and using</div><div>    the base_on image&#39;s compression type.</div><div><br></div><div>diff --git a/docs/livecd-creator.pod b/docs/livecd-creator.pod</div>

<div>index 1827728..ce7b94e 100644</div><div>--- a/docs/livecd-creator.pod</div><div>+++ b/docs/livecd-creator.pod</div><div>@@ -47,6 +47,7 @@ xz is the default and works with 2.6.38 and later kernels.</div><div> gzip works with all kernels.</div>

<div> lzo works with 2.6.36 and later kernels.</div><div> lzma will only work with custom kernels.</div><div>+Set to &#39;None&#39; to force reading the compressor used in BASE_ON.</div><div> If gzip is used, the -comp option is not passed to mksquashfs to allow the use of older versions of mksquashfs.</div>

<div> </div><div> =item --releasever=VER</div><div>diff --git a/imgcreate/fs.py b/imgcreate/fs.py</div><div>index de61c7b..d5307a2 100644</div><div>--- a/imgcreate/fs.py</div><div>+++ b/imgcreate/fs.py</div><div>@@ -41,6 +41,35 @@ def makedirs(dirname):</div>

<div>         if e.errno != errno.EEXIST:</div><div>             raise</div><div> </div><div>+def squashfs_compression_type(sqfs_img):</div><div>+    &quot;&quot;&quot;Check the compression type of a SquashFS image. If the type cannot be</div>

<div>+    ascertained, return &#39;undetermined&#39;. The calling code must decide what to</div><div>+    do.&quot;&quot;&quot;</div><div>+</div><div>+    env = os.environ.copy()</div><div>+    env[&#39;LC_ALL&#39;] = &#39;C&#39;</div>

<div>+    args = [&#39;/usr/sbin/unsquashfs&#39;, &#39;-s&#39;, sqfs_img]</div><div>+    try:</div><div>+        p = subprocess.Popen(args, stdout=subprocess.PIPE,</div><div>+                             stderr=subprocess.PIPE, env=env)</div>

<div>+        out, err = p.communicate()</div><div>+    except OSError, e:</div><div>+        raise SquashfsError(u&quot;Error white stat-ing &#39;%s&#39;\n&#39;%s&#39;&quot; % (args, e))</div><div>+    except:</div><div>

+        raise SquashfsError(u&quot;Error while stat-ing &#39;%s&#39;&quot; % args)</div><div>+    else:</div><div>+        if p.returncode != 0:</div><div>+            raise SquashfsError(</div><div>+                u&quot;Error while stat-ing &#39;%s&#39;\n&#39;%s&#39;\nreturncode: &#39;%s&#39;&quot; %</div>

<div>+                (args, err, p.returncode))</div><div>+        else:</div><div>+            compress_type = &#39;undetermined&#39;</div><div>+            for l in out.splitlines():</div><div>+                if l.split(None, 1)[0] == &#39;Compression&#39;:</div>

<div>+                    compress_type = l.split()[1]</div><div>+                    break</div><div>+    return compress_type</div><div>+</div><div> def mksquashfs(in_img, out_img, compress_type):</div><div> # Allow gzip to work for older versions of mksquashfs</div>

<div>     if compress_type == &quot;gzip&quot;:</div><div>diff --git a/imgcreate/live.py b/imgcreate/live.py</div><div>old mode 100644</div><div>new mode 100755</div><div>index bf3a4dd..f388825</div><div>--- a/imgcreate/live.py</div>

<div>+++ b/imgcreate/live.py</div><div>@@ -152,6 +152,12 @@ class LiveImageCreatorBase(LoopImageCreator):</div><div>             </div><div>         squashloop = DiskMount(LoopbackDisk(squashimg, 0), self._mkdtemp(), &quot;squashfs&quot;)</div>

<div> </div><div>+        # &#39;self.compress_type = None&#39; will force reading it from base_on.</div><div>+        if self.compress_type is None:</div><div>+            self.compress_type = squashfs_compression_type(squashimg)</div>

<div>+            if self.compress_type == &#39;undetermined&#39;:</div><div>+                # Default to &#39;gzip&#39; for compatibility with older versions.</div><div>+                self.compress_type = &#39;gzip&#39;</div>

<div>         try:</div><div>             if not squashloop.disk.exists():</div><div>                 raise CreatorError(&quot;&#39;%s&#39; is not a valid live CD ISO : &quot;</div><div>diff --git a/tools/livecd-creator b/tools/livecd-creator</div>

<div>index 3424636..d997095 100755</div><div>--- a/tools/livecd-creator</div><div>+++ b/tools/livecd-creator</div><div>@@ -48,7 +48,11 @@ def parse_options(args):</div><div>     imgopt.add_option(&quot;&quot;, &quot;--image-type&quot;, type=&quot;string&quot;, dest=&quot;image_type&quot;,</div>

<div>                       help=optparse.SUPPRESS_HELP)</div><div>     imgopt.add_option(&quot;&quot;, &quot;--compression-type&quot;, type=&quot;string&quot;, dest=&quot;compress_type&quot;,</div><div>-                      help=&quot;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)&quot;,</div>

<div>+                      help=&quot;Compression type recognized by mksquashfs &quot;</div><div>+                           &quot;(default xz needs a 2.6.38+ kernel, gzip works &quot;</div><div>+                           &quot;with all kernels, lzo needs a 2.6.36+ kernel, lzma &quot;</div>

<div>+                           &quot;needs custom kernel.) Set to &#39;None&#39; to force read &quot;</div><div>+                           &quot;from base_on.&quot;,</div><div>                       default=&quot;xz&quot;)</div>

<div>     imgopt.add_option(&quot;&quot;, &quot;--releasever&quot;, type=&quot;string&quot;, dest=&quot;releasever&quot;,</div><div>                       default=None,</div></font>