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

[Xen-devel] [PATCH 4 of 5] pygrub: track the title of an item as an independant field



# HG changeset patch
# User Ian Campbell <ijc@xxxxxxxxxxxxxx>
# Date 1258917181 0
# Node ID 69d318d58ed3e4266bfb76f514d90b69270aed9a
# Parent  d641f06a4889748dc7efec62398b5d333ad0df87
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>

diff -r d641f06a4889 -r 69d318d58ed3 tools/pygrub/src/GrubConf.py
--- a/tools/pygrub/src/GrubConf.py      Sun Nov 22 19:13:01 2009 +0000
+++ b/tools/pygrub/src/GrubConf.py      Sun Nov 22 19:13:01 2009 +0000
@@ -79,8 +79,9 @@
     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 @@
 
     def reset(self, lines):
         self._root = self._initrd = self._kernel = self._args = None
-        self.title = ""
         self.lines = []
         self._parse(lines)
 
@@ -126,8 +126,8 @@
     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 @@
             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 @@
         else:
             lines = buf.split("\n")
 
-        img = []
+        img = None
+        title = ""
         for l in lines:
             l = l.strip()
             # skip blank lines
@@ -273,12 +273,13 @@
                 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 @@
             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 d641f06a4889 -r 69d318d58ed3 tools/pygrub/src/pygrub
--- a/tools/pygrub/src/pygrub   Sun Nov 22 19:13:01 2009 +0000
+++ b/tools/pygrub/src/pygrub   Sun Nov 22 19:13:01 2009 +0000
@@ -259,13 +259,13 @@
             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 @@
                 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 @@
                     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-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

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