aboutsummaryrefslogtreecommitdiffstats
path: root/tools/pygrub
diff options
context:
space:
mode:
authorKeir Fraser <keir.fraser@citrix.com>2009-11-23 08:06:19 +0000
committerKeir Fraser <keir.fraser@citrix.com>2009-11-23 08:06:19 +0000
commitccc76c47dec5d7ea50cdeb153b4d60b4d7cbbc29 (patch)
tree1944b4d15bc88ae24d437ee0a269bb325af1efce /tools/pygrub
parent1142ec6cf0aabe8a3f95b4ac3f8105b21c302020 (diff)
downloadxen-ccc76c47dec5d7ea50cdeb153b4d60b4d7cbbc29.tar.gz
xen-ccc76c47dec5d7ea50cdeb153b4d60b4d7cbbc29.tar.bz2
xen-ccc76c47dec5d7ea50cdeb153b4d60b4d7cbbc29.zip
pygrub: track the title of an item as an independant field
separate to the other fields. This makes the list of lines within a GrubImage 0 based rather than 1 based therefore adjust the user interface parts to suit. This is in preparation for grub2 support where the syntax for the item title does not fit the existing usage. Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Diffstat (limited to 'tools/pygrub')
-rw-r--r--tools/pygrub/src/GrubConf.py27
-rw-r--r--tools/pygrub/src/pygrub10
2 files changed, 19 insertions, 18 deletions
diff --git a/tools/pygrub/src/GrubConf.py b/tools/pygrub/src/GrubConf.py
index 12f421996e..a36951ed2d 100644
--- a/tools/pygrub/src/GrubConf.py
+++ b/tools/pygrub/src/GrubConf.py
@@ -79,8 +79,9 @@ class GrubDiskPart(object):
part = property(get_part, set_part)
class _GrubImage(object):
- def __init__(self, lines):
+ def __init__(self, title, lines):
self.reset(lines)
+ self.title = title.strip()
def __repr__(self):
return ("title: %s\n"
@@ -94,7 +95,6 @@ class _GrubImage(object):
def reset(self, lines):
self._root = self._initrd = self._kernel = self._args = None
- self.title = ""
self.lines = []
self._parse(lines)
@@ -126,8 +126,8 @@ class _GrubImage(object):
initrd = property(get_initrd, set_initrd)
class GrubImage(_GrubImage):
- def __init__(self, lines):
- _GrubImage.__init__(self, lines)
+ def __init__(self, title, lines):
+ _GrubImage.__init__(self, title, lines)
def set_from_line(self, line, replace = None):
(com, arg) = grub_exact_split(line, 2)
@@ -148,8 +148,7 @@ class GrubImage(_GrubImage):
self.lines.insert(replace, line)
# set up command handlers
- commands = { "title": "title",
- "root": "root",
+ commands = { "root": "root",
"rootnoverify": "root",
"kernel": "kernel",
"initrd": "initrd",
@@ -262,7 +261,8 @@ class GrubConfigFile(_GrubConfigFile):
else:
lines = buf.split("\n")
- img = []
+ img = None
+ title = ""
for l in lines:
l = l.strip()
# skip blank lines
@@ -273,12 +273,13 @@ class GrubConfigFile(_GrubConfigFile):
continue
# new image
if l.startswith("title"):
- if len(img) > 0:
- self.add_image(GrubImage(img))
- img = [l]
+ if img is not None:
+ self.add_image(GrubImage(title, img))
+ img = []
+ title = l[6:]
continue
- if len(img) > 0:
+ if img is not None:
img.append(l)
continue
@@ -291,8 +292,8 @@ class GrubConfigFile(_GrubConfigFile):
else:
logging.warning("Unknown directive %s" %(com,))
- if len(img) > 0:
- self.add_image(GrubImage(img))
+ if img:
+ self.add_image(GrubImage(title, img))
if self.hasPassword():
self.setPasswordAccess(False)
diff --git a/tools/pygrub/src/pygrub b/tools/pygrub/src/pygrub
index 71dd086953..b4b2e1023a 100644
--- a/tools/pygrub/src/pygrub
+++ b/tools/pygrub/src/pygrub
@@ -259,13 +259,13 @@ class Grub:
self.text_win.move(y - 1, x - 1)
self.text_win.noutrefresh()
- curline = 1
+ curline = 0
img = copy.deepcopy(origimg)
while 1:
draw()
self.entry_win.erase()
self.entry_win.box()
- for idx in range(1, len(img.lines)):
+ for idx in range(0, len(img.lines)):
# current line should be highlighted
if idx == curline:
self.entry_win.attron(curses.A_REVERSE)
@@ -275,7 +275,7 @@ class Grub:
if len(l) > 70:
l = l[:69] + ">"
- self.entry_win.addstr(idx, 2, l)
+ self.entry_win.addstr(idx + 1, 2, l)
if idx == curline:
self.entry_win.attroff(curses.A_REVERSE)
self.entry_win.noutrefresh()
@@ -308,8 +308,8 @@ class Grub:
return
# bound at the top and bottom
- if curline < 1:
- curline = 1
+ if curline < 0:
+ curline = 0
elif curline >= len(img.lines):
curline = len(img.lines) - 1