All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Novotny <minovotn@redhat.com>
To: xen-devel@lists.xensource.com
Subject: Re: [PATCH] pyGrub: Use proper bootloader class when entering command manually
Date: Tue, 25 May 2010 17:13:46 +0200	[thread overview]
Message-ID: <4BFBE92A.7040603@redhat.com> (raw)
In-Reply-To: <4BFBE114.20208@redhat.com>

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

Ok, I found that the infrastructure of ExtLinuxImage and LiloImage is 
different so I rewrote it a little (but according to the code the old 
behaviour should be preserved) and also fixed the isconfig bug (since no 
img.initrd is accessible that time).

So please ignore the previous version of my patch and use this one.

Thanks,
Michal

Signed-off-by: Michal Novotny <minovotn@redhat.com>

On 05/25/2010 04:39 PM, Michal Novotny wrote:
> Hi,
> this is the patch to use the proper bootloader class when entering the 
> boot commands manually (i.e. using the 'c' option). Before this patch 
> the bootloader was always treated to be Grub but when user is using 
> Grub2/ExtLinux or Lilo it's rather confusing. After applying this 
> patch the proper bootloader image class is being used, e.g. Grub2Image 
> for Grub2 etc. when you define the boot commands manually using the 
> 'c' command in pyGrub.
>
> Also, fix for using isconfig has been applied since if there is not fs 
> set in the run_grub() method the read_config() would fail since it's 
> trying to access undefined self.cf which is now being set to parser() 
> from cfg_list.
>
> Signed-off-by: Michal Novotny <minovotn@redhat.com>
>
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xensource.com
> http://lists.xensource.com/xen-devel
>    


-- 
Michal Novotny<minovotn@redhat.com>, RHCE
Virtualization Team (xen userspace), Red Hat


[-- Attachment #2: xen-pygrub-command-use-proper-bootloader-class.patch --]
[-- Type: text/x-patch, Size: 5469 bytes --]

diff -r 10ad9b50b4ca tools/pygrub/src/ExtLinuxConf.py
--- a/tools/pygrub/src/ExtLinuxConf.py	Tue May 25 11:28:58 2010 +0100
+++ b/tools/pygrub/src/ExtLinuxConf.py	Tue May 25 17:10:32 2010 +0200
@@ -16,8 +16,8 @@ import GrubConf
 import GrubConf
 
 class ExtLinuxImage(object):
-    def __init__(self, lines, path):
-        self.reset(lines, path)
+    def __init__(self, title, lines, path = ""):
+        self.reset(lines, title, path)
 
     def __repr__(self):
         return ("title: %s\n"
@@ -26,10 +26,10 @@ class ExtLinuxImage(object):
                 "  args: %s\n"
                 "  initrd: %s\n" %(self.title, self.root, self.kernel,
                                    self.args, self.initrd))
-    def reset(self, lines, path):
+    def reset(self, lines, title, path):
         self._initrd = self._kernel = self._readonly = None
         self._args = ""
-        self.title = ""
+        self.title = title
         self.lines = []
         self.path = path
         self.root = ""
@@ -143,7 +143,7 @@ class ExtLinuxConfigFile(object):
             # new image
             if l.lower().startswith("label"):
                 if len(img) > 0:
-                    self.add_image(ExtLinuxImage(img, path))
+                    self.add_image(ExtLinuxImage("", img, path))
                 img = [l]
                 continue
 
@@ -162,7 +162,7 @@ class ExtLinuxConfigFile(object):
                 logging.warning("Unknown directive %s" %(com,))
 
         if len(img) > 0:
-            self.add_image(ExtLinuxImage(img, path))
+            self.add_image(ExtLinuxImage("", img, path))
 
     def hasPassword(self):
         return False
diff -r 10ad9b50b4ca tools/pygrub/src/LiloConf.py
--- a/tools/pygrub/src/LiloConf.py	Tue May 25 11:28:58 2010 +0100
+++ b/tools/pygrub/src/LiloConf.py	Tue May 25 17:10:32 2010 +0200
@@ -7,8 +7,8 @@ import GrubConf
 import GrubConf
 
 class LiloImage(object):
-    def __init__(self, lines, path):
-        self.reset(lines, path)
+    def __init__(self, title, lines, path = ""):
+        self.reset(lines, title, path)
 
     def __repr__(self):
         return ("title: %s\n"
@@ -17,10 +17,10 @@ class LiloImage(object):
                 "  args: %s\n"
                 "  initrd: %s\n" %(self.title, self.root, self.kernel,
                                    self.args, self.initrd))
-    def reset(self, lines, path):
+    def reset(self, lines, title, path):
         self._initrd = self._kernel = self._readonly = None
         self._args = ""
-        self.title = ""
+        self.title = title
         self.lines = []
         self.path = path
         self.root = ""
@@ -118,7 +118,7 @@ class LiloConfigFile(object):
             # new image
             if l.startswith("image"):
                 if len(img) > 0:
-                    self.add_image(LiloImage(img, path))
+                    self.add_image(LiloImage("", img, path))
                 img = [l]
                 continue
 
@@ -136,7 +136,7 @@ class LiloConfigFile(object):
                 logging.warning("Unknown directive %s" %(com,))
 
         if len(img) > 0:
-            self.add_image(LiloImage(img, path))
+            self.add_image(LiloImage("", img, path))
 
     def hasPassword(self):
         return False
diff -r 10ad9b50b4ca tools/pygrub/src/pygrub
--- a/tools/pygrub/src/pygrub	Tue May 25 11:28:58 2010 +0100
+++ b/tools/pygrub/src/pygrub	Tue May 25 17:10:32 2010 +0200
@@ -356,7 +356,7 @@ class Grub:
                     continue
 
                 # if we got boot, then we want to boot the entered image 
-                img = grub.GrubConf.GrubImage(lines)
+                img = self.imgcl("entered", lines)
                 self.cf.add_image(img)
                 self.selected_image = len(self.cf.images) - 1
                 self.isdone = True
@@ -392,15 +392,28 @@ class Grub:
 
         if not fs:
             # set the config file and parse it
-            self.cf.filename = fn
-            self.cf.parse()
-            return
+            for f,parser in cfg_list:
+                self.cf = parser()
+                self.cf.filename = fn
+                self.cf.parse()
+                return
 
         for f,parser in cfg_list:
             if fs.file_exists(f):
                 print >>sys.stderr, "Using %s to parse %s" % (parser,f)
                 self.cf = parser()
                 self.cf.filename = f
+
+                # Get the bootloader image file constructor to imgcl
+                if type(self.cf) == grub.LiloConf.LiloConfigFile:
+                    self.imgcl = grub.LiloConf.LiloImage
+                elif type(self.cf) == grub.GrubConf.Grub2ConfigFile:
+                    self.imgcl = grub.GrubConf.Grub2Image
+                elif type(self.cf) == grub.ExtLinuxConf.ExtLinuxConfigFile:
+                    self.imgcl = grub.ExtLinuxConf.ExtLinuxImage
+                else:
+                    self.imgcl = grub.GrubConf.GrubImage
+
                 break
         if self.__dict__.get('cf', None) is None:
             raise RuntimeError, "couldn't find bootloader config file in the image provided."
@@ -689,7 +702,7 @@ if __name__ == "__main__":
     if isconfig:
         chosencfg = run_grub(file, entry, fs, incfg["args"])
         print "  kernel: %s" % chosencfg["kernel"]
-        if img.initrd:
+        if chosencfg["ramdisk"]:
             print "  initrd: %s" % chosencfg["ramdisk"]
         print "  args: %s" % chosencfg["args"]
         sys.exit(0)

[-- 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:[~2010-05-25 15:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-25 14:39 [PATCH] pyGrub: Use proper bootloader class when entering command manually Michal Novotny
2010-05-25 15:13 ` Michal Novotny [this message]
2010-05-25 16:22   ` Ian Campbell
2010-05-26  9:27     ` Michal Novotny
2010-05-26  9:29       ` Ian Campbell

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=4BFBE92A.7040603@redhat.com \
    --to=minovotn@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.