<font class="Apple-style-span" face="'courier new', monospace"><div>Please review. I'm not familiar with the preferred exception</div><div>reporting formats.</div><div> --Fred</div><div>
<br></div><div>Author: Frederick Grose <<a href="mailto:fgrose@gmail.com">fgrose@gmail.com</a>></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 & 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 'None' will trigger reading and using</div><div> the base_on image'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 'None' 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>+ """Check the compression type of a SquashFS image. If the type cannot be</div>
<div>+ ascertained, return 'undetermined'. The calling code must decide what to</div><div>+ do."""</div><div>+</div><div>+ env = os.environ.copy()</div><div>+ env['LC_ALL'] = 'C'</div>
<div>+ args = ['/usr/sbin/unsquashfs', '-s', 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"Error white stat-ing '%s'\n'%s'" % (args, e))</div><div>+ except:</div><div>
+ raise SquashfsError(u"Error while stat-ing '%s'" % args)</div><div>+ else:</div><div>+ if p.returncode != 0:</div><div>+ raise SquashfsError(</div><div>+ u"Error while stat-ing '%s'\n'%s'\nreturncode: '%s'" %</div>
<div>+ (args, err, p.returncode))</div><div>+ else:</div><div>+ compress_type = 'undetermined'</div><div>+ for l in out.splitlines():</div><div>+ if l.split(None, 1)[0] == 'Compression':</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 == "gzip":</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(), "squashfs")</div>
<div> </div><div>+ # 'self.compress_type = None' 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 == 'undetermined':</div><div>+ # Default to 'gzip' for compatibility with older versions.</div><div>+ self.compress_type = 'gzip'</div>
<div> try:</div><div> if not squashloop.disk.exists():</div><div> raise CreatorError("'%s' is not a valid live CD ISO : "</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("", "--image-type", type="string", dest="image_type",</div>
<div> help=optparse.SUPPRESS_HELP)</div><div> imgopt.add_option("", "--compression-type", type="string", dest="compress_type",</div><div>- 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)",</div>
<div>+ help="Compression type recognized by mksquashfs "</div><div>+ "(default xz needs a 2.6.38+ kernel, gzip works "</div><div>+ "with all kernels, lzo needs a 2.6.36+ kernel, lzma "</div>
<div>+ "needs custom kernel.) Set to 'None' to force read "</div><div>+ "from base_on.",</div><div> default="xz")</div>
<div> imgopt.add_option("", "--releasever", type="string", dest="releasever",</div><div> default=None,</div></font>