]> xenbits.xensource.com Git - xen.git/commitdiff
pygrub: cope with configurations with submenus
authorMichael Young <m.a.young@durham.ac.uk>
Tue, 10 Jan 2012 17:08:22 +0000 (17:08 +0000)
committerMichael Young <m.a.young@durham.ac.uk>
Tue, 10 Jan 2012 17:08:22 +0000 (17:08 +0000)
The grub2 configuration file in Fedora 16 can have one or more
menuentrys in a submenu, with configuration of the form
    submenu "Xen 4.1" {
    menuentry ... {
    ...
    }
    }
(this example occurs when the xen hypervisor is installed on the
guest)

Ignore the submenu line and the corresponding }

Signed-off-by: Michael Young <m.a.young@durham.ac.uk>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
xen-unstable changeset: 24001:152049468175
Backport-requested-by: Pasi Karkkainen <pasik@iki.fi>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/pygrub/src/GrubConf.py

index 26861af24f2a8807c4249426541af74df7f8f6a8..a31e30a46f76bd3bf93bf49dc865d34beea5132b 100644 (file)
@@ -370,6 +370,7 @@ class Grub2ConfigFile(_GrubConfigFile):
         in_function = False
         img = None
         title = ""
+        menu_level=0
         for l in lines:
             l = l.strip()
             # skip blank lines
@@ -396,10 +397,18 @@ class Grub2ConfigFile(_GrubConfigFile):
                 img = []
                 title = title_match.group(1)
                 continue
-            
+
+            if l.startswith("submenu"):
+                menu_level += 1
+                continue
+
             if l.startswith("}"):
                 if img is None:
-                    raise RuntimeError, "syntax error: closing brace without menuentry"
+                    if menu_level > 0:
+                        menu_level -= 1
+                        continue
+                    else:
+                        raise RuntimeError, "syntax error: closing brace without menuentry"
 
                 self.add_image(Grub2Image(title, img))
                 img = None