ia64/xen-unstable
changeset 14809:6cd828db1a5d
Fix pygrub for IA64 support.
Signed-off-by: Shinya Kuwamura <kuwa@jp.fujitsu.com>
Signed-off-by: Tomohiro Takahashi <takatom@jp.fujitsu.com>
Signed-off-by: Shinya Kuwamura <kuwa@jp.fujitsu.com>
Signed-off-by: Tomohiro Takahashi <takatom@jp.fujitsu.com>
author | kfraser@localhost.localdomain |
---|---|
date | Wed Apr 11 15:36:04 2007 +0100 (2007-04-11) |
parents | ed78f08aad61 |
children | 0d92cd901f80 |
files | tools/pygrub/src/LiloConf.py tools/pygrub/src/pygrub |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/tools/pygrub/src/LiloConf.py Wed Apr 11 15:36:04 2007 +0100 1.3 @@ -0,0 +1,147 @@ 1.4 +# 1.5 +#LiloConf.py 1.6 +# 1.7 + 1.8 +import sys, re, os 1.9 +import logging 1.10 +import GrubConf 1.11 + 1.12 +class LiloImage(object): 1.13 + def __init__(self, lines, path): 1.14 + self.reset(lines, path) 1.15 + 1.16 + def __repr__(self): 1.17 + return ("title: %s\n" 1.18 + " root: %s\n" 1.19 + " kernel: %s\n" 1.20 + " args: %s\n" 1.21 + " initrd: %s\n" %(self.title, self.root, self.kernel, 1.22 + self.args, self.initrd)) 1.23 + def reset(self, lines, path): 1.24 + self._root = self._initrd = self._kernel = self._args = None 1.25 + self.title = "" 1.26 + self.lines = [] 1.27 + self.path = path 1.28 + map(self.set_from_line, lines) 1.29 + self.root = "" # dummy 1.30 + 1.31 + def set_from_line(self, line, replace = None): 1.32 + (com, arg) = GrubConf.grub_exact_split(line, 2) 1.33 + 1.34 + if self.commands.has_key(com): 1.35 + if self.commands[com] is not None: 1.36 + exec("%s = r\'%s\'" %(self.commands[com], re.sub('^"(.+)"$', r"\1", arg.strip()))) 1.37 + else: 1.38 + logging.info("Ignored image directive %s" %(com,)) 1.39 + else: 1.40 + logging.warning("Unknown image directive %s" %(com,)) 1.41 + 1.42 + # now put the line in the list of lines 1.43 + if replace is None: 1.44 + self.lines.append(line) 1.45 + else: 1.46 + self.lines.pop(replace) 1.47 + self.lines.insert(replace, line) 1.48 + 1.49 + def set_kernel(self, val): 1.50 + self._kernel = (None, self.path + "/" + val) 1.51 + def get_kernel(self): 1.52 + return self._kernel 1.53 + kernel = property(get_kernel, set_kernel) 1.54 + 1.55 + def set_initrd(self, val): 1.56 + self._initrd = (None, self.path + "/" + val) 1.57 + def get_initrd(self): 1.58 + return self._initrd 1.59 + initrd = property(get_initrd, set_initrd) 1.60 + 1.61 + # set up command handlers 1.62 + commands = { "label": "self.title", 1.63 + "root": "self.root", 1.64 + "rootnoverify": "self.root", 1.65 + "image": "self.kernel", 1.66 + "initrd": "self.initrd", 1.67 + "append": "self.args", 1.68 + "read-only": None, 1.69 + "chainloader": None, 1.70 + "module": None} 1.71 + 1.72 +class LiloConfigFile(object): 1.73 + def __init__(self, fn = None): 1.74 + self.filename = fn 1.75 + self.images = [] 1.76 + self.timeout = -1 1.77 + self._default = 0 1.78 + 1.79 + if fn is not None: 1.80 + self.parse() 1.81 + 1.82 + def parse(self, buf = None): 1.83 + if buf is None: 1.84 + if self.filename is None: 1.85 + raise ValueError, "No config file defined to parse!" 1.86 + 1.87 + f = open(self.filename, 'r') 1.88 + lines = f.readlines() 1.89 + f.close() 1.90 + else: 1.91 + lines = buf.split("\n") 1.92 + 1.93 + path = os.path.dirname(self.filename) 1.94 + img = [] 1.95 + for l in lines: 1.96 + l = l.strip() 1.97 + # skip blank lines 1.98 + if len(l) == 0: 1.99 + continue 1.100 + # skip comments 1.101 + if l.startswith('#'): 1.102 + continue 1.103 + # new image 1.104 + if l.startswith("image"): 1.105 + if len(img) > 0: 1.106 + self.add_image(LiloImage(img, path)) 1.107 + img = [l] 1.108 + continue 1.109 + 1.110 + if len(img) > 0: 1.111 + img.append(l) 1.112 + continue 1.113 + 1.114 + (com, arg) = GrubConf.grub_exact_split(l, 2) 1.115 + if self.commands.has_key(com): 1.116 + if self.commands[com] is not None: 1.117 + exec("%s = r\"%s\"" %(self.commands[com], arg.strip())) 1.118 + else: 1.119 + logging.info("Ignored directive %s" %(com,)) 1.120 + else: 1.121 + logging.warning("Unknown directive %s" %(com,)) 1.122 + 1.123 + if len(img) > 0: 1.124 + self.add_image(LiloImage(img, path)) 1.125 + 1.126 + def add_image(self, image): 1.127 + self.images.append(image) 1.128 + 1.129 + def _get_default(self): 1.130 + for i in range(0, len(self.images) - 1): 1.131 + if self.images[i].title == self._default: 1.132 + return i 1.133 + return 0 1.134 + def _set_default(self, val): 1.135 + self._default = val 1.136 + default = property(_get_default, _set_default) 1.137 + 1.138 + commands = { "default": "self.default", 1.139 + "timeout": "self.timeout", 1.140 + "prompt": None, 1.141 + "relocatable": None, 1.142 + } 1.143 + 1.144 +if __name__ == "__main__": 1.145 + if sys.argv < 2: 1.146 + raise RuntimeError, "Need a grub.conf to read" 1.147 + g = LiloConfigFile(sys.argv[1]) 1.148 + for i in g.images: 1.149 + print i #, i.title, i.root, i.kernel, i.args, i.initrd 1.150 + print g.default
2.1 --- a/tools/pygrub/src/pygrub Wed Apr 11 15:27:14 2007 +0100 2.2 +++ b/tools/pygrub/src/pygrub Wed Apr 11 15:36:04 2007 +0100 2.3 @@ -16,6 +16,7 @@ 2.4 import os, sys, string, struct, tempfile, re 2.5 import copy 2.6 import logging 2.7 +import platform 2.8 2.9 import curses, _curses, curses.wrapper, curses.textpad, curses.ascii 2.10 import getopt 2.11 @@ -24,6 +25,7 @@ sys.path = [ '/usr/lib/python' ] + sys.p 2.12 2.13 import fsimage 2.14 import grub.GrubConf 2.15 +import grub.LiloConf 2.16 2.17 PYGRUB_VER = 0.5 2.18 2.19 @@ -353,7 +355,13 @@ class Grub: 2.20 if not os.access(fn, os.R_OK): 2.21 raise RuntimeError, "Unable to access %s" %(fn,) 2.22 2.23 - self.cf = grub.GrubConf.GrubConfigFile() 2.24 + if platform.machine() == 'ia64': 2.25 + self.cf = grub.LiloConf.LiloConfigFile() 2.26 + file_list = ("/efi/redhat/elilo.conf",) 2.27 + else: 2.28 + self.cf = grub.GrubConf.GrubConfigFile() 2.29 + file_list = ("/boot/grub/menu.lst", "/boot/grub/grub.conf", 2.30 + "/grub/menu.lst", "/grub/grub.conf") 2.31 2.32 if not fs: 2.33 # set the config file and parse it 2.34 @@ -361,18 +369,15 @@ class Grub: 2.35 self.cf.parse() 2.36 return 2.37 2.38 - grubfile = None 2.39 - for f in ("/boot/grub/menu.lst", "/boot/grub/grub.conf", 2.40 - "/grub/menu.lst", "/grub/grub.conf"): 2.41 + for f in file_list: 2.42 if fs.file_exists(f): 2.43 - grubfile = f 2.44 + self.cf.filename = f 2.45 break 2.46 - if grubfile is None: 2.47 - raise RuntimeError, "we couldn't find grub config file in the image provided." 2.48 - f = fs.open_file(grubfile) 2.49 + if self.cf.filename is None: 2.50 + raise RuntimeError, "couldn't find bootloader config file in the image provided." 2.51 + f = fs.open_file(self.cf.filename) 2.52 buf = f.read() 2.53 del f 2.54 - # then parse the grub config 2.55 self.cf.parse(buf) 2.56 2.57 def run(self):