pyGrub: Use proper bootloader class when entering command manually
authorKeir Fraser <keir.fraser@citrix.com>
Wed, 26 May 2010 09:52:15 +0000 (10:52 +0100)
committerKeir Fraser <keir.fraser@citrix.com>
Wed, 26 May 2010 09:52:15 +0000 (10:52 +0100)
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>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
tools/pygrub/src/ExtLinuxConf.py
tools/pygrub/src/GrubConf.py
tools/pygrub/src/LiloConf.py
tools/pygrub/src/pygrub

index 99f0990a904865103ce14990189cc0faadef2520..6be65cef1d6065a934faa6f59ea9241534c11ed0 100644 (file)
@@ -119,6 +119,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:
             if self.filename is None:
index 51d0c17a4e367ce1c8f663158073eeb3877a55fb..0b946d3e46d72d4281b841ff20248a60e6f9d1b7 100644 (file)
@@ -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 Grub2Image(_GrubImage):
 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:
index 8f029571cf9f47119c52b4d4bc105aab7a2c80ff..9858ae26f5f20c143150b1a089630ed57090f631 100644 (file)
@@ -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:
index 0973b8a9713b308dd3762291777e5cd0783384be..e52df7b5256ab19f50e4bcc1acd32c066ca0e13e 100644 (file)
@@ -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)