mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 02:01:24 +01:00
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>
This commit is contained in:
1 parent
aec29abd5b
commit
d8f3a67bf9
1 file changed
+16
-11
@@ -220,7 +220,6 @@ class _GrubConfigFile(object):
|
|||||||
def _get_default(self):
|
def _get_default(self):
|
||||||
return self._default
|
return self._default
|
||||||
def _set_default(self, val):
|
def _set_default(self, val):
|
||||||
val = val.strip("\"")
|
|
||||||
if val == "saved":
|
if val == "saved":
|
||||||
self._default = 0
|
self._default = 0
|
||||||
else:
|
else:
|
||||||
@@ -300,7 +299,15 @@ class GrubConfigFile(_GrubConfigFile):
|
|||||||
|
|
||||||
if self.hasPassword():
|
if self.hasPassword():
|
||||||
self.setPasswordAccess(False)
|
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):
|
class Grub2Image(_GrubImage):
|
||||||
def __init__(self, title, lines):
|
def __init__(self, title, lines):
|
||||||
_GrubImage.__init__(self, title, lines)
|
_GrubImage.__init__(self, title, lines)
|
||||||
@@ -309,9 +316,8 @@ class Grub2Image(_GrubImage):
|
|||||||
(com, arg) = grub_exact_split(line, 2)
|
(com, arg) = grub_exact_split(line, 2)
|
||||||
|
|
||||||
if com == "set":
|
if com == "set":
|
||||||
(com,arg) = grub_split(arg,2)
|
(com,arg) = grub2_handle_set(arg)
|
||||||
com="set:" + com
|
|
||||||
|
|
||||||
if self.commands.has_key(com):
|
if self.commands.has_key(com):
|
||||||
if self.commands[com] is not None:
|
if self.commands[com] is not None:
|
||||||
setattr(self, self.commands[com], arg.strip())
|
setattr(self, self.commands[com], arg.strip())
|
||||||
@@ -373,17 +379,17 @@ class Grub2ConfigFile(_GrubConfigFile):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
# new image
|
# new image
|
||||||
title_match = re.match('^menuentry "(.*)" {', l)
|
title_match = re.match('^menuentry "(.*)" (.*){', l)
|
||||||
if title_match:
|
if title_match:
|
||||||
if img is not None:
|
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 = []
|
img = []
|
||||||
title = title_match.group(1)
|
title = title_match.group(1)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if l.startswith("}"):
|
if l.startswith("}"):
|
||||||
if img is None:
|
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))
|
self.add_image(Grub2Image(title, img))
|
||||||
img = None
|
img = None
|
||||||
@@ -396,8 +402,7 @@ class Grub2ConfigFile(_GrubConfigFile):
|
|||||||
(com, arg) = grub_exact_split(l, 2)
|
(com, arg) = grub_exact_split(l, 2)
|
||||||
|
|
||||||
if com == "set":
|
if com == "set":
|
||||||
(com,arg) = grub_split(arg,2)
|
(com,arg) = grub2_handle_set(arg)
|
||||||
com="set:" + com
|
|
||||||
|
|
||||||
if self.commands.has_key(com):
|
if self.commands.has_key(com):
|
||||||
if self.commands[com] is not None:
|
if self.commands[com] is not None:
|
||||||
@@ -410,7 +415,7 @@ class Grub2ConfigFile(_GrubConfigFile):
|
|||||||
logging.warning("Unknown directive %s" %(com,))
|
logging.warning("Unknown directive %s" %(com,))
|
||||||
|
|
||||||
if img is not None:
|
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():
|
if self.hasPassword():
|
||||||
self.setPasswordAccess(False)
|
self.setPasswordAccess(False)
|
||||||
|
|||||||