All of lore.kernel.org
 help / color / mirror / Atom feed
From: aq <aquynh@gmail.com>
To: Jeremy Katz <katzj@redhat.com>,
	"xen-devel@lists.xensource.com" <xen-devel@lists.xensource.com>
Subject: [PATCH] xen-booloader: grub parser improvement & bug fix
Date: Fri, 29 Apr 2005 12:22:06 +0900	[thread overview]
Message-ID: <9cde8bff05042820223edda65@mail.gmail.com> (raw)

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

Hello,

Here is a patch to fix a bug and improve grub parser of xen-booloader.
Please apply this on top of the last Jeremy's patch.

List of changes:
- More tolerant when dealing with some grub directive which has no
parameter, like "savedefault", "boot"
- Support few more grub directives like "boot", "savedefault"
- Set first item as default boot option if "saved" boot option is
indicated (the oiginal choice is to raise error)
- Fix bug on sys.argv
- Insert and remove few blank lines for more readable.

$ diffstat GrubConf.aq.patch 
 GrubConf.py |   43 ++++++++++++++++++++++++++++++++-----------
 1 files changed, 32 insertions(+), 11 deletions(-)

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

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

--- unstable.27.3.org/tools/pygrub/src/GrubConf.py	2005-04-29 12:01:07.207028000 +0900
+++ unstable.27.3/tools/pygrub/src/GrubConf.py	2005-04-29 11:44:30.807028000 +0900
@@ -27,7 +27,7 @@ def grub_split(s, maxsplit = -1):
     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)
@@ -58,29 +58,37 @@ class GrubDiskPart(object):
 
     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,))
@@ -97,8 +105,10 @@ class GrubImage(object):
 
     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 +119,23 @@ class GrubImage(object):
         (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 +145,9 @@ class GrubImage(object):
                  "kernel": "self.kernel",
                  "initrd": "self.initrd",
                  "chainloader": None,
-                 "module": None}
+                 "module": None,
+                 "boot": None,
+                 "savedefault": None}
         
 
 class GrubConfigFile(object):
@@ -185,26 +203,29 @@ class GrubConfigFile(object):
                     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):
         return self._default
+
     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)
 
     def set_splash(self, val):
         self._splash = get_path(val)
+
     def get_splash(self):
         return self._splash
+
     splash = property(get_splash, set_splash)
 
     # set up command handlers
@@ -222,8 +243,8 @@ class GrubConfigFile(object):
 
 
 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

                 reply	other threads:[~2005-04-29  3:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9cde8bff05042820223edda65@mail.gmail.com \
    --to=aquynh@gmail.com \
    --cc=katzj@redhat.com \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.