diff options
Diffstat (limited to 'plugins/imager/raw_plugin.py')
-rwxr-xr-x[-rw-r--r--] | plugins/imager/raw_plugin.py | 57 |
1 files changed, 21 insertions, 36 deletions
diff --git a/plugins/imager/raw_plugin.py b/plugins/imager/raw_plugin.py index 1b9631d..09a9714 100644..100755 --- a/plugins/imager/raw_plugin.py +++ b/plugins/imager/raw_plugin.py @@ -21,7 +21,7 @@ import re import tempfile from mic import chroot, msger, rt_util -from mic.utils import misc, fs_related, errors, runner, cmdln +from mic.utils import misc, fs_related, errors, runner from mic.conf import configmgr from mic.plugin import pluginmgr from mic.utils.partitionedfs import PartitionedMount @@ -33,19 +33,7 @@ class RawPlugin(ImagerPlugin): name = 'raw' @classmethod - @cmdln.option("--compress-disk-image", dest="compress_image", type='choice', - choices=("gz", "bz2"), 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") - @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', - choices=("name", "uuid"), default="uuid", - help="Set fstab entry, 'name' means using device names, " - "'uuid' means using filesystem uuid") - def do_create(self, subcmd, opts, *args): + def do_create(self, args): """${cmd_name}: create raw image Usage: @@ -54,11 +42,8 @@ class RawPlugin(ImagerPlugin): ${cmd_option_list} """ - if len(args) != 1: - raise errors.Usage("Extra arguments given") - creatoropts = configmgr.create - ksconf = args[0] + ksconf = args.ksfile if creatoropts['runtime'] == "bootstrap": configmgr._ksconf = ksconf @@ -76,10 +61,6 @@ class RawPlugin(ImagerPlugin): configmgr._ksconf = ksconf - # Called After setting the configmgr._ksconf as the creatoropts['name'] is reset there. - if creatoropts['release'] is not None: - creatoropts['outdir'] = "%s/%s/images/%s/" % (creatoropts['outdir'], creatoropts['release'], creatoropts['name']) - # try to find the pkgmgr pkgmgr = None backends = pluginmgr.get_plugins('backend') @@ -100,8 +81,8 @@ class RawPlugin(ImagerPlugin): (creatoropts['pkgmgr'], ','.join(backends.keys()))) - creator = raw.RawImageCreator(creatoropts, pkgmgr, opts.compress_image, - opts.generate_bmap, opts.fstab_entry) + creator = raw.RawImageCreator(creatoropts, pkgmgr, args.compress_image, + args.generate_bmap, args.fstab_entry) if len(recording_pkgs) > 0: creator._recording_pkgs = recording_pkgs @@ -121,9 +102,10 @@ class RawPlugin(ImagerPlugin): creator.copy_kernel() creator.unmount() creator.generate_bmap() - creator.package(creatoropts["outdir"]) + creator.package(creatoropts["destdir"]) + creator.create_manifest() if creatoropts['release'] is not None: - creator.release_output(ksconf, creatoropts['outdir'], creatoropts['release']) + creator.release_output(ksconf, creatoropts['destdir'], creatoropts['release']) creator.print_outimage_info() except errors.CreatorError: @@ -166,7 +148,7 @@ class RawPlugin(ImagerPlugin): else: root_mounted = False partition_mounts = 0 - for line in runner.outs([partedcmd,"-s",img,"unit","B","print"]).splitlines(): + for line in runner.outs([ partedcmd, "-s", img, "unit", "B", "print" ]).splitlines(): line = line.strip() # Lines that start with number are the partitions, @@ -178,12 +160,12 @@ class RawPlugin(ImagerPlugin): line = line.replace(",","") # Example of parted output lines that are handled: - # Number Start End Size Type File system Flags + # Number Start End Size Type File system Flags # 1 512B 3400000511B 3400000000B primary # 2 3400531968B 3656384511B 255852544B primary linux-swap(v1) - # 3 3656384512B 3720347647B 63963136B primary fat16 boot, lba + # 3 3656384512B 3720347647B 63963136B primary fat16 boot, lba - partition_info = re.split("\s+",line) + partition_info = re.split("\s+", line) size = partition_info[3].split("B")[0] @@ -193,18 +175,19 @@ class RawPlugin(ImagerPlugin): # not recognize properly. # TODO: Can we make better assumption? fstype = "btrfs" - elif partition_info[5] in ["ext2","ext3","ext4","btrfs"]: + elif partition_info[5] in [ "ext2", "ext3", "ext4", "btrfs" ]: fstype = partition_info[5] - elif partition_info[5] in ["fat16","fat32"]: + elif partition_info[5] in [ "fat16", "fat32" ]: fstype = "vfat" elif "swap" in partition_info[5]: fstype = "swap" else: - raise errors.CreatorError("Could not recognize partition fs type '%s'." % partition_info[5]) + raise errors.CreatorError("Could not recognize partition fs type '%s'." % + partition_info[5]) if rootpart and rootpart == line[0]: mountpoint = '/' - elif not root_mounted and fstype in ["ext2","ext3","ext4","btrfs"]: + elif not root_mounted and fstype in [ "ext2", "ext3", "ext4", "btrfs" ]: # TODO: Check that this is actually the valid root partition from /etc/fstab mountpoint = "/" root_mounted = True @@ -220,9 +203,11 @@ class RawPlugin(ImagerPlugin): else: boot = False - msger.verbose("Size: %s Bytes, fstype: %s, mountpoint: %s, boot: %s" % (size, fstype, mountpoint, boot)) + msger.verbose("Size: %s Bytes, fstype: %s, mountpoint: %s, boot: %s" % + (size, fstype, mountpoint, boot)) # TODO: add_partition should take bytes as size parameter. - imgloop.add_partition((int)(size)/1024/1024, "/dev/sdb", mountpoint, fstype = fstype, boot = boot) + imgloop.add_partition((int)(size)/1024/1024, "/dev/sdb", mountpoint, + fstype = fstype, boot = boot) try: imgloop.mount() |