From 0c385b2eff8ba3cfeec367d70a26e68e860fa4bb Mon Sep 17 00:00:00 2001 From: Michael Young Date: Tue, 25 Oct 2011 19:20:06 +0100 Subject: pygrub: cope with configurations with submenus 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 Acked-by: Ian Campbell --- tools/pygrub/src/GrubConf.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'tools/pygrub') diff --git a/tools/pygrub/src/GrubConf.py b/tools/pygrub/src/GrubConf.py index 26861af24f..a31e30a46f 100644 --- a/tools/pygrub/src/GrubConf.py +++ b/tools/pygrub/src/GrubConf.py @@ -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 -- cgit v1.2.3