All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] GrubConf improvements
@ 2005-05-23  1:10 aq
  2005-05-23  1:11 ` aq
  0 siblings, 1 reply; 3+ messages in thread
From: aq @ 2005-05-23  1:10 UTC (permalink / raw)
  To: xen-devel

here is a patch of GrubConf.py (tools/pygrub/src/GrubConf.py), which provides:

- support for menu color (would be used by pygrub)
- support for more grub directives
- fix a bug on checking length of sys.argv
- few cleanups

Signed-off-by: Nguyen Anh Quynh <aquynh@gmail.com>

$ diffstat GrubConf.patch 
 GrubConf.py |   93 +++++++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 73 insertions(+), 20 deletions(-)

-- 
regards,
aq

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] GrubConf improvements
  2005-05-23  1:10 [PATCH] GrubConf improvements aq
@ 2005-05-23  1:11 ` aq
  2005-05-27 11:05   ` aq
  0 siblings, 1 reply; 3+ messages in thread
From: aq @ 2005-05-23  1:11 UTC (permalink / raw)
  To: xen-devel

[-- Attachment #1: Type: text/plain, Size: 613 bytes --]

hello,

sorry that in the last patch i forgot the attachment. here it is.

On 5/23/05, aq <aquynh@gmail.com> wrote:
> here is a patch of GrubConf.py (tools/pygrub/src/GrubConf.py), which provides:
> 
> - support for menu color (would be used by pygrub)
> - support for more grub directives
> - fix a bug on checking length of sys.argv
> - few cleanups
> 
> Signed-off-by: Nguyen Anh Quynh <aquynh@gmail.com>
> 
> $ diffstat GrubConf.patch
>  GrubConf.py |   93 +++++++++++++++++++++++++++++++++++++++++++++++-------------
>  1 files changed, 73 insertions(+), 20 deletions(-)
> 

regards,
aq

[-- Attachment #2: GrubConf.patch --]
[-- Type: application/octet-stream, Size: 6865 bytes --]

===== tools/pygrub/src/GrubConf.py 1.2 vs edited =====
--- 1.2/tools/pygrub/src/GrubConf.py	2005-04-28 21:27:46 +09:00
+++ edited/tools/pygrub/src/GrubConf.py	2005-05-19 01:39:58 +09:00
@@ -12,8 +12,7 @@
 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 #
 
-import os, sys
-import logging
+import os, sys, logging
 
 def grub_split(s, maxsplit = -1):
     """Split a grub option screen separated with either '=' or whitespace."""
@@ -27,7 +26,7 @@
     if (tab != -1 and tab < sp) or (tab != -1 and sp == -1):
         sp = tab
 
-    if eq != -1 and eq < sp or (eq != -1 and sp == -1):
+    if (eq < sp) or (sp == -1):
         return s.split('=', maxsplit)
     else:
         return s.split(None, maxsplit)
@@ -42,6 +41,29 @@
     d = s[:idx]
     return (GrubDiskPart(d), s[idx + 1:])
 
+def get_color(s):
+    """Returns a tuple of ((fg,bg), (fg,bg)) corresponding to menu and item color."""
+    s.strip()
+    idx = s.find(' ')
+    if idx == -1:
+        return None
+    c = s.split(None, 1)
+    menucolor = c[0]
+    idx = menucolor.find('/')
+    if idx == -1:
+        return None
+    menufg = menucolor[:idx]
+    menubg = menucolor[idx + 1:]
+    if len(c) == 1:
+        return ((menufg, menubg))
+    itemcolor = c[1]
+    idx = itemcolor.find('/')
+    if idx == -1:
+        return None
+    itemfg = itemcolor[:idx]
+    itembg = itemcolor[idx + 1:]
+    return ((menufg, menubg), (itemfg, itembg))
+
 class GrubDiskPart(object):
     def __init__(self, str):
         if str.find(',') != -1:
@@ -58,29 +80,37 @@
 
     def get_disk(self):
         return self._disk
+
     def set_disk(self, val):
         val = val.replace("(", "").replace(")", "")
         self._disk = int(val[2:])
+
     disk = property(get_disk, set_disk)
 
     def get_part(self):
         return self._part
+
     def set_part(self, val):
         if val is None:
             self._part = val
             return
         val = val.replace("(", "").replace(")", "")
         self._part = int(val)
+
     part = property(get_part, set_part)
 
 class GrubImage(object):
     def __init__(self, lines):
         self._root = self._initrd = self._kernel = self._args = None
         for l in lines:
-            (com, arg) = grub_split(l, 1)
-
+            up = grub_split(l, 1)
+            if len(up) >1:
+                (com, arg) = up
+            else:
+                com = up[0]
+                arg = None
             if self.commands.has_key(com):
-                if self.commands[com] is not None:
+                if self.commands[com] is not None and arg is not None:
                     exec("%s = r\"%s\"" %(self.commands[com], arg.strip()))
                 else:
                     logging.info("Ignored image directive %s" %(com,))
@@ -92,13 +122,15 @@
                 "  root: %s\n"
                 "  kernel: %s\n"
                 "  args: %s\n"
-                "  initrd: %s" %(self.title, self.root, self.kernel,
+                "  initrd: %s\n" %(self.title, self.root, self.kernel,
                                    self.args, self.initrd))
 
     def set_root(self, val):
         self._root = GrubDiskPart(val)
+
     def get_root(self):
         return self._root
+
     root = property(get_root, set_root)
 
     def set_kernel(self, val):
@@ -109,17 +141,23 @@
         (kernel, args) = val.split(None, 1)
         self._kernel = get_path(kernel)
         self._args = args
+
     def get_kernel(self):
         return self._kernel
+
+    kernel = property(get_kernel, set_kernel)
+
     def get_args(self):
         return self._args
-    kernel = property(get_kernel, set_kernel)
+
     args = property(get_args)
 
     def set_initrd(self, val):
         self._initrd = get_path(val)
+
     def get_initrd(self):
         return self._initrd
+
     initrd = property(get_initrd, set_initrd)
 
     # set up command handlers
@@ -129,7 +167,11 @@
                  "kernel": "self.kernel",
                  "initrd": "self.initrd",
                  "chainloader": None,
-                 "module": None}
+                 "module": None,
+                 "boot": None,
+                 "pause": None,
+                 "lock": None,
+                 "savedefault": None }
         
 
 class GrubConfigFile(object):
@@ -155,6 +197,7 @@
         img = []
         for l in lines:
             l = l.strip()
+            l = l.strip('\x00')
             # skip blank lines
             if len(l) == 0:
                 continue
@@ -171,7 +214,6 @@
             if len(img) > 0:
                 img.append(l)
                 continue
-
             try:
                 (com, arg) = grub_split(l, 1)
             except ValueError:
@@ -185,45 +227,56 @@
                     logging.info("Ignored directive %s" %(com,))
             else:
                 logging.warning("Unknown directive %s" %(com,))
-                
         if len(img) > 0:
             self.images.append(GrubImage(img))
 
-    def _get_default(self):
+    def get_default(self):
         return self._default
-    def _set_default(self, val):
+
+    def set_default(self, val):
         if val == "saved":
-            self._default = -1
+            self._default = 0   # use the first item as default value
         else:
             self._default = int(val)
 
         if self._default < 0:
             raise ValueError, "default must be positive number"
-    default = property(_get_default, _set_default)
+
+    default = property(get_default, set_default)
 
     def set_splash(self, val):
         self._splash = get_path(val)
+
     def get_splash(self):
         return self._splash
+
     splash = property(get_splash, set_splash)
 
+    def set_color(self, val):
+        self._color = get_color(val)
+
+    def get_color(self):
+        return self._color
+
+    color = property(get_color, set_color)
+
     # set up command handlers
     commands = { "default": "self.default",
                  "timeout": "self.timeout",
                  "fallback": "self.fallback",
                  "hiddenmenu": "self.hiddenmenu",
                  "splashimage": "self.splash",
+                 "color": "self.color",
                  "password": "self.password" }
-    for c in ("bootp", "color", "device", "dhcp", "hide", "ifconfig",
+    for c in ("bootp", "device", "dhcp", "hide", "ifconfig",
               "pager", "partnew", "parttype", "rarp", "serial",
               "setkey", "terminal", "terminfo", "tftpserver", "unhide"):
         commands[c] = None
-    del c
 
 
 if __name__ == "__main__":
-    if sys.argv < 2:
-        raise RuntimeError, "Need a grub.conf to read"
+    if len(sys.argv) < 2:
+        raise RuntimeError, "Need a grub configuration file to read"
     g = GrubConfigFile(sys.argv[1])
     for i in g.images:
-        print i #, i.title, i.root, i.kernel, i.args, i.initrd
+        print i

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] GrubConf improvements
  2005-05-23  1:11 ` aq
@ 2005-05-27 11:05   ` aq
  0 siblings, 0 replies; 3+ messages in thread
From: aq @ 2005-05-27 11:05 UTC (permalink / raw)
  To: xen-devel

this patch got no comment. please consider applying/rejecting it.

-- 
regards,
aq


On 5/23/05, aq <aquynh@gmail.com> wrote:
> hello,
> 
> sorry that in the last patch i forgot the attachment. here it is.
> 
> On 5/23/05, aq <aquynh@gmail.com> wrote:
> > here is a patch of GrubConf.py (tools/pygrub/src/GrubConf.py), which provides:
> >
> > - support for menu color (would be used by pygrub)
> > - support for more grub directives
> > - fix a bug on checking length of sys.argv
> > - few cleanups
> >
> > Signed-off-by: Nguyen Anh Quynh <aquynh@gmail.com>
> >
> > $ diffstat GrubConf.patch
> >  GrubConf.py |   93 +++++++++++++++++++++++++++++++++++++++++++++++-------------
> >  1 files changed, 73 insertions(+), 20 deletions(-)
> >
> 
> regards,
> aq
> 
> 
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-05-27 11:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-23  1:10 [PATCH] GrubConf improvements aq
2005-05-23  1:11 ` aq
2005-05-27 11:05   ` aq

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.