xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Ian Campbell <Ian.Campbell@citrix.com>
To: xen-devel@lists.xensource.com
Subject: pygrub: further improve grub2 support
Date: Mon, 15 Mar 2010 08:56:22 +0000	[thread overview]
Message-ID: <1268643382.8652.2811.camel@localhost.localdomain> (raw)


Round 2 (3?) in the arms race against the Debian Squeeze grub packages.

      * 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>

Please include in 3.4 as well.

diff -r 4152a3ce90a7 tools/pygrub/src/GrubConf.py
--- a/tools/pygrub/src/GrubConf.py	Thu Mar 11 17:40:35 2010 +0000
+++ b/tools/pygrub/src/GrubConf.py	Mon Mar 15 08:51:07 2010 +0000
@@ -220,7 +220,6 @@
     def _get_default(self):
         return self._default
     def _set_default(self, val):
-        val = val.strip("\"")
         if val == "saved":
             self._default = 0
         else:
@@ -300,7 +299,15 @@
 
         if self.hasPassword():
             self.setPasswordAccess(False)
-    
+
+def grub2_handle_set(arg):
+    (com,arg) = grub_split(arg,2)
+    com="set:" + com
+    m = re.match("([\"\'])(.*)\\1", arg)
+    if m is not None:
+        arg=m.group(2) 
+    return (com,arg)
+
 class Grub2Image(_GrubImage):
     def __init__(self, title, lines):
         _GrubImage.__init__(self, title, lines)
@@ -309,9 +316,8 @@
         (com, arg) = grub_exact_split(line, 2)
 
         if com == "set":
-            (com,arg) = grub_split(arg,2)
-            com="set:" + com
-                
+            (com,arg) = grub2_handle_set(arg)
+            
         if self.commands.has_key(com):
             if self.commands[com] is not None:
                 setattr(self, self.commands[com], arg.strip())
@@ -373,17 +379,17 @@
                 continue
 
             # new image
-            title_match = re.match('^menuentry "(.*)" {', l)
+            title_match = re.match('^menuentry "(.*)" (.*){', l)
             if title_match:
                 if img is not None:
-                    raise RuntimeError, "syntax error 1 %d %s" % (len(img),img)
+                    raise RuntimeError, "syntax error: cannot nest menuentry (%d %s)" % (len(img),img)
                 img = []
                 title = title_match.group(1)
                 continue
             
             if l.startswith("}"):
                 if img is None:
-                    raise RuntimeError, "syntax error 2 %d %s" % (len(img),img)
+                    raise RuntimeError, "syntax error: closing brace without menuentry"
 
                 self.add_image(Grub2Image(title, img))
                 img = None
@@ -396,8 +402,7 @@
             (com, arg) = grub_exact_split(l, 2)
         
             if com == "set":
-                (com,arg) = grub_split(arg,2)
-                com="set:" + com
+                (com,arg) = grub2_handle_set(arg)
                 
             if self.commands.has_key(com):
                 if self.commands[com] is not None:
@@ -410,7 +415,7 @@
                 logging.warning("Unknown directive %s" %(com,))
             
         if img is not None:
-            raise RuntimeError, "syntax error 3 %d %s" % (len(img),img)
+            raise RuntimeError, "syntax error: end of file with open menuentry(%d %s)" % (len(img),img)
 
         if self.hasPassword():
             self.setPasswordAccess(False)

             reply	other threads:[~2010-03-15  8:56 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-15  8:56 Ian Campbell [this message]
2010-03-26 10:41 ` pygrub: further improve grub2 support Boris Derzhavets
2010-03-26 10:49   ` Ian Campbell
2010-03-26 10:57     ` Boris Derzhavets
2010-03-26 12:06       ` Boris Derzhavets
2010-03-26 16:52       ` Boris Derzhavets
2010-03-26 16:55         ` Ian Campbell
2010-03-26 17:04           ` Boris Derzhavets

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1268643382.8652.2811.camel@localhost.localdomain \
    --to=ian.campbell@citrix.com \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).