diff options
author | Keir Fraser <keir.fraser@citrix.com> | 2010-01-26 15:54:40 +0000 |
---|---|---|
committer | Keir Fraser <keir.fraser@citrix.com> | 2010-01-26 15:54:40 +0000 |
commit | fd607bf0001547d1ee5e84ba7ed9977f631d0fb0 (patch) | |
tree | 5fe7c47f63b4ea95e7fc42c77f550963579aebb4 /tools/pygrub | |
parent | 83f510f16bd73a52cf1cc1e5864b2fb30eeb7b29 (diff) | |
download | xen-fd607bf0001547d1ee5e84ba7ed9977f631d0fb0.tar.gz xen-fd607bf0001547d1ee5e84ba7ed9977f631d0fb0.tar.bz2 xen-fd607bf0001547d1ee5e84ba7ed9977f631d0fb0.zip |
pygrub: improve grub 2 support
* The "default" value can be a quoted string (containing an integer)
so strip the quotes before interpreting.
* The "set" command takes a variable with an arbitrary name so instead
of whitelisting the ones to ignore simply silently accept any set
command with an unknown variable.
* Ignore the echo command.
* Handle the function { ... } syntax. Previously pygrub would error
out with a syntax error on the closing "}" because it thought it was
the closing bracket of a menuentry.
This makes pygrub2 work with the configuration files generated by
Debian Squeeze today.
Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Diffstat (limited to 'tools/pygrub')
-rw-r--r-- | tools/pygrub/src/GrubConf.py | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/tools/pygrub/src/GrubConf.py b/tools/pygrub/src/GrubConf.py index 074f3a2155..58a448ca20 100644 --- a/tools/pygrub/src/GrubConf.py +++ b/tools/pygrub/src/GrubConf.py @@ -219,6 +219,7 @@ class _GrubConfigFile(object): def _get_default(self): return self._default def _set_default(self, val): + val = val.strip("\"") if val == "saved": self._default = 0 else: @@ -315,6 +316,8 @@ class Grub2Image(_GrubImage): setattr(self, self.commands[com], arg.strip()) else: logging.info("Ignored image directive %s" %(com,)) + elif com.startswith('set:'): + pass else: logging.warning("Unknown image directive %s" %(com,)) @@ -328,6 +331,7 @@ class Grub2Image(_GrubImage): commands = {'set:root': 'root', 'linux': 'kernel', 'initrd': 'initrd', + 'echo': None, 'insmod': None, 'search': None} @@ -346,6 +350,7 @@ class Grub2ConfigFile(_GrubConfigFile): else: lines = buf.split("\n") + in_function = False img = None title = "" for l in lines: @@ -356,6 +361,16 @@ class Grub2ConfigFile(_GrubConfigFile): # skip comments if l.startswith('#'): continue + + # skip function declarations + if l.startswith('function'): + in_function = True + continue + if in_function: + if l.startswith('}'): + in_function = False + continue + # new image title_match = re.match('^menuentry "(.*)" {', l) if title_match: @@ -388,6 +403,8 @@ class Grub2ConfigFile(_GrubConfigFile): setattr(self, self.commands[com], arg.strip()) else: logging.info("Ignored directive %s" %(com,)) + elif com.startswith('set:'): + pass else: logging.warning("Unknown directive %s" %(com,)) @@ -400,11 +417,10 @@ class Grub2ConfigFile(_GrubConfigFile): commands = {'set:default': 'default', 'set:root': 'root', 'set:timeout': 'timeout', - 'set:gfxmode': None, - 'set:menu_color_normal': None, - 'set:menu_color_highlight': None, 'terminal': None, 'insmod': None, + 'load_env': None, + 'save_env': None, 'search': None, 'if': None, 'fi': None, |