debuggers.hg

changeset 21079:25446394d21f

pygrub: further improve grub2 support

* Improve syntax error messages to say what actually went wrong
instead of giving an arbitrary and basically useless
integer.
* Improve handling of quoted values used with the "set" command,
previously only the default variable was special cased to
handle quoting.
* Allow for extra options to the menuentry command, syntax now
appears to be
menuentry "TITLE" --option1 --option2 {...}

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Mar 15 13:23:07 2010 +0000 (2010-03-15)
parents a6ed354be9e3
children bc0087c3e75e
files tools/pygrub/src/GrubConf.py
line diff
     1.1 --- a/tools/pygrub/src/GrubConf.py	Mon Mar 15 13:22:06 2010 +0000
     1.2 +++ b/tools/pygrub/src/GrubConf.py	Mon Mar 15 13:23:07 2010 +0000
     1.3 @@ -220,7 +220,6 @@ class _GrubConfigFile(object):
     1.4      def _get_default(self):
     1.5          return self._default
     1.6      def _set_default(self, val):
     1.7 -        val = val.strip("\"")
     1.8          if val == "saved":
     1.9              self._default = 0
    1.10          else:
    1.11 @@ -300,7 +299,15 @@ class GrubConfigFile(_GrubConfigFile):
    1.12  
    1.13          if self.hasPassword():
    1.14              self.setPasswordAccess(False)
    1.15 -    
    1.16 +
    1.17 +def grub2_handle_set(arg):
    1.18 +    (com,arg) = grub_split(arg,2)
    1.19 +    com="set:" + com
    1.20 +    m = re.match("([\"\'])(.*)\\1", arg)
    1.21 +    if m is not None:
    1.22 +        arg=m.group(2) 
    1.23 +    return (com,arg)
    1.24 +
    1.25  class Grub2Image(_GrubImage):
    1.26      def __init__(self, title, lines):
    1.27          _GrubImage.__init__(self, title, lines)
    1.28 @@ -309,9 +316,8 @@ class Grub2Image(_GrubImage):
    1.29          (com, arg) = grub_exact_split(line, 2)
    1.30  
    1.31          if com == "set":
    1.32 -            (com,arg) = grub_split(arg,2)
    1.33 -            com="set:" + com
    1.34 -                
    1.35 +            (com,arg) = grub2_handle_set(arg)
    1.36 +            
    1.37          if self.commands.has_key(com):
    1.38              if self.commands[com] is not None:
    1.39                  setattr(self, self.commands[com], arg.strip())
    1.40 @@ -373,17 +379,17 @@ class Grub2ConfigFile(_GrubConfigFile):
    1.41                  continue
    1.42  
    1.43              # new image
    1.44 -            title_match = re.match('^menuentry "(.*)" {', l)
    1.45 +            title_match = re.match('^menuentry "(.*)" (.*){', l)
    1.46              if title_match:
    1.47                  if img is not None:
    1.48 -                    raise RuntimeError, "syntax error 1 %d %s" % (len(img),img)
    1.49 +                    raise RuntimeError, "syntax error: cannot nest menuentry (%d %s)" % (len(img),img)
    1.50                  img = []
    1.51                  title = title_match.group(1)
    1.52                  continue
    1.53              
    1.54              if l.startswith("}"):
    1.55                  if img is None:
    1.56 -                    raise RuntimeError, "syntax error 2 %d %s" % (len(img),img)
    1.57 +                    raise RuntimeError, "syntax error: closing brace without menuentry"
    1.58  
    1.59                  self.add_image(Grub2Image(title, img))
    1.60                  img = None
    1.61 @@ -396,8 +402,7 @@ class Grub2ConfigFile(_GrubConfigFile):
    1.62              (com, arg) = grub_exact_split(l, 2)
    1.63          
    1.64              if com == "set":
    1.65 -                (com,arg) = grub_split(arg,2)
    1.66 -                com="set:" + com
    1.67 +                (com,arg) = grub2_handle_set(arg)
    1.68                  
    1.69              if self.commands.has_key(com):
    1.70                  if self.commands[com] is not None:
    1.71 @@ -410,7 +415,7 @@ class Grub2ConfigFile(_GrubConfigFile):
    1.72                  logging.warning("Unknown directive %s" %(com,))
    1.73              
    1.74          if img is not None:
    1.75 -            raise RuntimeError, "syntax error 3 %d %s" % (len(img),img)
    1.76 +            raise RuntimeError, "syntax error: end of file with open menuentry(%d %s)" % (len(img),img)
    1.77  
    1.78          if self.hasPassword():
    1.79              self.setPasswordAccess(False)