From 3faf55319dff01b47669da10d6cd834d95b651e3 Mon Sep 17 00:00:00 2001 From: Michael Young Date: Tue, 10 Jan 2012 17:08:22 +0000 Subject: [PATCH] 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 xen-unstable changeset: 24001:152049468175 Backport-requested-by: Pasi Karkkainen Committed-by: Ian Jackson --- tools/pygrub/src/GrubConf.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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 -- 2.39.5