All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Novotny <minovotn@redhat.com>
To: Ian Campbell <Ian.Campbell@citrix.com>
Cc: "xen-devel@lists.xensource.com" <xen-devel@lists.xensource.com>,
	Keir Fraser <keir.fraser@eu.citrix.com>
Subject: Re: [PATCH] pyGrub: Use proper bootloader class when entering command manually
Date: Wed, 26 May 2010 11:27:29 +0200	[thread overview]
Message-ID: <4BFCE981.6020103@redhat.com> (raw)
In-Reply-To: <1274804553.24218.7232.camel@zakaz.uk.xensource.com>

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

Yeah, that's right Ian. However adding a new method called new_image() 
to all of the boot loader configuration classes (*ConfigFile classes) 
will still be necessary. I wrote a new version of my patch to add 
support for new_image() method all the existing classes and did the 
modifications to pygrub.

As in previous version of my patch, the isconfig debug option has been 
fixed too.

Keir, please use this version to be committed.

Thanks,
Michal

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

On 05/25/2010 06:22 PM, Ian Campbell wrote:
> On Tue, 2010-05-25 at 16:13 +0100, Michal Novotny wrote:
>    
>> 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.
>>      
> Perhaps instead of these two hunks:
>
> --- 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
>
> [...]
>                   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."
>
> We could add a method to each of the self.cf classes which returns a new
> image from the title+lines given. Then the first hunk becomes something
> like:
>
> -                img = grub.GrubConf.GrubImage(lines)
> +                img = self.cf.new_image("entered", lines)
>
> and the second bit goes away. This would be nice since it avoids
> hardcoding another list of bootloaders.
>
> Ian.
>
>    


-- 
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: 3590 bytes --]

diff -r 15f4ead9e686 tools/pygrub/src/ExtLinuxConf.py
--- a/tools/pygrub/src/ExtLinuxConf.py	Wed May 26 08:15:31 2010 +0100
+++ b/tools/pygrub/src/ExtLinuxConf.py	Wed May 26 11:22:43 2010 +0200
@@ -118,6 +118,12 @@ class ExtLinuxConfigFile(object):
 
         if fn is not None:
             self.parse()
+
+    def new_image(self, title, lines):
+        # ExtLinuxImage constructor doesn't have title but since path
+        # is being used by get_{kernel|initrd} functions we pass
+        # empty string rather than None (see lines above)
+        return ExtLinuxImage(lines, "")
 
     def parse(self, buf = None):
         if buf is None:
diff -r 15f4ead9e686 tools/pygrub/src/GrubConf.py
--- a/tools/pygrub/src/GrubConf.py	Wed May 26 08:15:31 2010 +0100
+++ b/tools/pygrub/src/GrubConf.py	Wed May 26 11:22:43 2010 +0200
@@ -252,6 +252,9 @@ class GrubConfigFile(_GrubConfigFile):
     def __init__(self, fn = None):
         _GrubConfigFile.__init__(self,fn)
         
+    def new_image(self, title, lines):
+        return GrubImage(title, lines)
+
     def parse(self, buf = None):
         if buf is None:
             if self.filename is None:
@@ -345,7 +348,10 @@ class Grub2ConfigFile(_GrubConfigFile):
 class Grub2ConfigFile(_GrubConfigFile):
     def __init__(self, fn = None):
         _GrubConfigFile.__init__(self, fn)
-        
+       
+    def new_image(self, title, lines):
+        return Grub2Image(title, lines)
+ 
     def parse(self, buf = None):
         if buf is None:
             if self.filename is None:
diff -r 15f4ead9e686 tools/pygrub/src/LiloConf.py
--- a/tools/pygrub/src/LiloConf.py	Wed May 26 08:15:31 2010 +0100
+++ b/tools/pygrub/src/LiloConf.py	Wed May 26 11:22:43 2010 +0200
@@ -147,6 +147,12 @@ class LiloConfigFile(object):
     def add_image(self, image):
         self.images.append(image)
 
+    def new_image(self, title, lines):
+        # LiloImage constructor doesn't have title but since path
+        # is being used by get_{kernel|initrd} functions we pass
+        # empty string rather than None (see lines above)
+        return LiloImage(lines, "")
+
     def _get_default(self):
         for i in range(len(self.images)):
             if self.images[i].title == self._default:
diff -r 15f4ead9e686 tools/pygrub/src/pygrub
--- a/tools/pygrub/src/pygrub	Wed May 26 08:15:31 2010 +0100
+++ b/tools/pygrub/src/pygrub	Wed May 26 11:22:43 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.cf.new_image("entered", lines)
                 self.cf.add_image(img)
                 self.selected_image = len(self.cf.images) - 1
                 self.isdone = True
@@ -392,9 +392,11 @@ 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):
@@ -689,7 +691,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-26  9:27 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
2010-05-25 16:22   ` Ian Campbell
2010-05-26  9:27     ` Michal Novotny [this message]
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=4BFCE981.6020103@redhat.com \
    --to=minovotn@redhat.com \
    --cc=Ian.Campbell@citrix.com \
    --cc=keir.fraser@eu.citrix.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.