add choice for msger and ask user to choose root partition
authorGui Chen <gui.chen@intel.com>
Wed, 11 Jul 2012 02:43:00 +0000 (10:43 +0800)
committerGui Chen <gui.chen@intel.com>
Wed, 11 Jul 2012 06:48:15 +0000 (14:48 +0800)
fix mic ch raw image failure 'cause of the order of partition

Signed-off-by: Gui Chen <gui.chen@intel.com>
mic/msger.py
plugins/imager/raw_plugin.py

index 48bc40c..ab94e9e 100644 (file)
@@ -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, '')
index c8385a4..1e481e7 100644 (file)
@@ -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