mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 02:30:03 +01:00
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>
This commit is contained in:
1 parent
1142ec6cf0
commit
ccc76c47de
2 files changed
+19
-18
No files matched your search
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||