[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] pygrub: track the title of an item as an independant field



# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1258963579 0
# Node ID 6e32b7a3e80202ed6c4d09a1211e14c786cb3731
# Parent  086a6a0c3f377829408e77c4cc8ca7ead919bef0
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@xxxxxxxxxx>
---
 tools/pygrub/src/GrubConf.py |   27 ++++++++++++++-------------
 tools/pygrub/src/pygrub      |   10 +++++-----
 2 files changed, 19 insertions(+), 18 deletions(-)

diff -r 086a6a0c3f37 -r 6e32b7a3e802 tools/pygrub/src/GrubConf.py
--- a/tools/pygrub/src/GrubConf.py      Mon Nov 23 08:05:49 2009 +0000
+++ b/tools/pygrub/src/GrubConf.py      Mon Nov 23 08:06:19 2009 +0000
@@ -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 -r 086a6a0c3f37 -r 6e32b7a3e802 tools/pygrub/src/pygrub
--- a/tools/pygrub/src/pygrub   Mon Nov 23 08:05:49 2009 +0000
+++ b/tools/pygrub/src/pygrub   Mon Nov 23 08:06:19 2009 +0000
@@ -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
 

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.