From e1112ee3d8712c9b777a92657e5da50ba1339641 Mon Sep 17 00:00:00 2001 From: Gui Chen Date: Wed, 11 Jul 2012 10:43:00 +0800 Subject: [PATCH] add choice for msger and ask user to choose root partition fix mic ch raw image failure 'cause of the order of partition Signed-off-by: Gui Chen --- mic/msger.py | 22 ++++++++++++++++++++++ plugins/imager/raw_plugin.py | 19 ++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/mic/msger.py b/mic/msger.py index 48bc40c..ab94e9e 100644 --- a/mic/msger.py +++ b/mic/msger.py @@ -234,6 +234,28 @@ def ask(msg, default=True): sys.stdout.write('\n') sys.exit(2) +def choice(msg, choices, default=0): + if default >= len(choices): + return None + _general_print('\rQ', ASK_COLOR, '') + try: + msg += " [%s] " % '/'.join(choices) + if INTERACTIVE: + while True: + repl = raw_input(msg) + if repl in choices: + return repl + elif not repl.strip(): + return choices[default] + else: + msg += choices[default] + _general_print('', NO_COLOR, msg) + + return choices[default] + except KeyboardInterrupt: + sys.stdout.write('\n') + sys.exit(2) + def pause(msg=None): if INTERACTIVE: _general_print('\rQ', ASK_COLOR, '') diff --git a/plugins/imager/raw_plugin.py b/plugins/imager/raw_plugin.py index c8385a4..1e481e7 100644 --- a/plugins/imager/raw_plugin.py +++ b/plugins/imager/raw_plugin.py @@ -134,6 +134,20 @@ class RawPlugin(ImagerPlugin): imgloop = PartitionedMount({'/dev/sdb':disk}, imgmnt, skipformat = True) img_fstype = "ext3" + msger.info("Partition Table:") + partnum = [] + for line in runner.outs([partedcmd, "-s", img, "print"]).splitlines(): + # no use strip to keep line output here + if "Number" in line: + msger.raw(line) + if line.strip() and line.strip()[0].isdigit(): + partnum.append(line.strip()[0]) + msger.raw(line) + + rootpart = None + if len(partnum) > 1: + rootpart = msger.choice("please choose root partition", partnum) + # Check the partitions from raw disk. root_mounted = False partition_mounts = 0 @@ -173,7 +187,10 @@ class RawPlugin(ImagerPlugin): else: raise errors.CreatorError("Could not recognize partition fs type '%s'." % partition_info[5]) - if not root_mounted and fstype in ["ext2","ext3","ext4","btrfs"]: + if rootpart == line[0]: + mountpoint = '/' + root_mounted = True + 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 -- 2.7.4