Add lzop compress format
authorSun Lihong <lihongx.sun@intel.com>
Fri, 21 Mar 2014 07:30:37 +0000 (15:30 +0800)
committerSun Lihong <lihongx.sun@intel.com>
Fri, 11 Apr 2014 04:26:10 +0000 (12:26 +0800)
Add '.lzo' compression format to option '--compress-image' and
'--compress-disk-image' of 'raw' and 'loop' type image.

Fixes: #1282

Change-Id: Ic19faa2b9c2ee13a74a6cd2ce9153ce7feea276c

etc/bash_completion.d/mic.sh
etc/zsh_completion.d/_mic
mic/utils/misc.py
plugins/imager/loop_plugin.py
plugins/imager/raw_plugin.py

index 91ea3c0..d7a4fa6 100644 (file)
@@ -140,10 +140,12 @@ __mic_complete_val()
     compress_image_values="
         gz
         bz2
+        lzo
     "
     compress_disk_image_values="
         gz
         bz2
+        lzo
     "
 
     declare -F _split_longopt &>/dev/null && _split_longopt
index 65e3433..46867a8 100644 (file)
@@ -117,8 +117,8 @@ _mic() {
                   _arguments \
                     $common_ops \
                     '--shrink[Whether to shrink loop images to minimal size]' \
-                    "--compress-image=[Compress all loop images with \'gz\' or \'bz2\']: :(gz bz2)" \
-                    "--compress-disk-image=[Same with --compress-image]: :(gz bz2)" \
+                    "--compress-image=[Compress all loop images with \'gz\' or \'bz2\' or \'lzo\']: :(gz bz2 lzo)" \
+                    "--compress-disk-image=[Same with --compress-image]: :(gz bz2 lzo)" \
                       && ret=0
                   ;;
                 (raw)
@@ -126,8 +126,8 @@ _mic() {
                     $common_ops \
                     "--fstab-entry=[Set fstab entry, \'name\' means using device names, \'uuid\' means using filesystem uuid]: :(name uuid)" \
                     '--generate-bmap[also generate the block map file]' \
-                    '--compress-image=[Compress all raw images before package]: :(gz bz2)' \
-                    '--compress-disk-image=[Same with --compress-image]: :(gz bz2)' \
+                    '--compress-image=[Compress all raw images before package]: :(gz bz2 lzo)' \
+                    '--compress-disk-image=[Same with --compress-image]: :(gz bz2 lzo)' \
                     && ret=0
                   ;;
                 (help)
index 243051e..df9d49b 100644 (file)
@@ -191,6 +191,7 @@ def compressing(fpath, method):
     comp_map = {
         "gz": ["pgzip", "pigz", "gzip"],
         "bz2": ["pbzip2", "bzip2"],
+        "lzo": ["lzop"],
     }
     if method not in comp_map:
         raise CreatorError("Unsupport compress format: %s, valid values: %s"
@@ -204,7 +205,10 @@ def compressing(fpath, method):
             pass
     if not cmd:
         raise CreatorError("Command %s not available" % cmdname)
-    rc = runner.show([cmd, "-f", fpath])
+    if 'lzop' in cmd:
+        rc = runner.show([cmd, "-Uf", fpath])
+    else:
+        rc = runner.show([cmd, "-f", fpath])
     if rc:
         raise CreatorError("Failed to %s file: %s" % (comp_map[method], fpath))
 
index 3641ec9..2a283ef 100644 (file)
@@ -31,12 +31,14 @@ class LoopPlugin(ImagerPlugin):
 
     @classmethod
     @cmdln.option("--compress-disk-image", dest="compress_image",
-                  type='choice', choices=("gz", "bz2"), default=None,
+                  type='choice', choices=("gz", "bz2", "lzo"), default=None,
                   help="Same with --compress-image")
                   # alias to compress-image for compatibility
     @cmdln.option("--compress-image", dest="compress_image",
-                  type='choice', choices=("gz", "bz2"), default=None,
-                  help="Compress all loop images with 'gz' or 'bz2'")
+                  type='choice', choices=("gz", "bz2", "lzo"), default=None,
+                  help="Compress all loop images with 'gz' or 'bz2' or 'lzo',"
+                  "Note: if you want to use 'lzo', package 'lzop' is needed to"
+                  "be installed manually.")
     @cmdln.option("--shrink", action='store_true', default=False,
                   help="Whether to shrink loop images to minimal size")
     def do_create(self, subcmd, opts, *args):
index bb8c7f0..905a7d0 100644 (file)
@@ -34,11 +34,12 @@ class RawPlugin(ImagerPlugin):
 
     @classmethod
     @cmdln.option("--compress-disk-image", dest="compress_image", type='choice',
-                  choices=("gz", "bz2"), default=None,
+                  choices=("gz", "bz2", "lzo"), default=None,
                   help="Same with --compress-image")
     @cmdln.option("--compress-image", dest="compress_image", type='choice',
-                  choices=("gz", "bz2"), default = None,
-                  help="Compress all raw images before package")
+                  choices=("gz", "bz2", "lzo"), default=None,
+                  help="Compress all raw images before package, Note: if you want "
+                  "to use 'lzo', package 'lzop' is needed to be installed manually.")
     @cmdln.option("--generate-bmap", action="store_true", default = None,
                   help="also generate the block map file")
     @cmdln.option("--fstab-entry", dest="fstab_entry", type='choice',