From: "Takahashi Tomohiro" Subject: [PATCH][RFC] Fix pygrub for IA64 support. Date: Wed, 11 Apr 2007 16:48:32 +0900 Message-ID: <013f01c77c0d$ddf1aa10$ecb1220a@fj98229700> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_013C_01C77C59.3D785BA0" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-ia64-devel@lists.xensource.com, xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org This is a multi-part message in MIME format. ------=_NextPart_000_013C_01C77C59.3D785BA0 Content-Type: text/plain; format=flowed; charset="iso-2022-jp"; reply-type=original Content-Transfer-Encoding: 7bit Hi, I made a patch that fixed pygrub for IA64 support. This patch purposes to support pygrub on IA64. I just do fix pygrub and add LiloConf.py. (since IA64 uses elilo.conf) The discussion point is elilo.conf path. I use "/efi/redhat/elilo.conf" But this is distributer specific(for example Redhat). Is any idea to fix this issue? Signed-off-by: Shinya Kuwamura Signed-off-by: Tomohiro Takahashi Thanks, Tomohiro Takahashi. ------=_NextPart_000_013C_01C77C59.3D785BA0 Content-Type: application/octet-stream; name="pygrub_ia64.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="pygrub_ia64.patch" diff -r 1bde28f762a6 -r 8e08fd1ffa24 tools/pygrub/src/pygrub --- a/tools/pygrub/src/pygrub Mon Apr 09 13:40:25 2007 -0600 +++ b/tools/pygrub/src/pygrub Tue Apr 10 20:30:05 2007 +0900 @@ -16,6 +16,7 @@ import os, sys, string, struct, tempfile import os, sys, string, struct, tempfile, re import copy import logging +import platform import curses, _curses, curses.wrapper, curses.textpad, curses.ascii import getopt @@ -24,6 +25,7 @@ sys.path =3D [ '/usr/lib/python' ] + sys.p import fsimage import grub.GrubConf +import grub.LiloConf PYGRUB_VER =3D 0.5 @@ -346,7 +355,10 @@ class Grub: if not os.access(fn, os.R_OK): raise RuntimeError, "Unable to access %s" %(fn,) - self.cf =3D grub.GrubConf.GrubConfigFile() + if platform.machine() =3D=3D 'ia64': + self.cf =3D grub.LiloConf.LiloConfigFile() + else: + self.cf =3D grub.GrubConf.GrubConfigFile() if not fs: # set the config file and parse it @@ -356,9 +368,11 @@ class Grub: grubfile =3D None for f in ("/boot/grub/menu.lst", "/boot/grub/grub.conf", - "/grub/menu.lst", "/grub/grub.conf"): + "/grub/menu.lst", "/grub/grub.conf", + "/efi/redhat/elilo.conf"): if fs.file_exists(f): grubfile =3D f + self.cf.filename =3D f # for LiloConfigFile break if grubfile is None: raise RuntimeError, "we couldn't find grub config file in = the image provided." diff -r 1bde28f762a6 -r 8e08fd1ffa24 tools/pygrub/src/LiloConf.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/pygrub/src/LiloConf.py Tue Apr 10 20:30:05 2007 +0900 @@ -0,0 +1,147 @@ +# +#LiloConf.py +# + +import sys, re, os +import logging +import GrubConf + +class LiloImage(object): + def __init__(self, lines, path): + self.reset(lines, path) + + def __repr__(self): + return ("title: %s\n" + " root: %s\n" + " kernel: %s\n" + " args: %s\n" + " initrd: %s\n" %(self.title, self.root, self.kernel, + self.args, self.initrd)) + def reset(self, lines, path): + self._root =3D self._initrd =3D self._kernel =3D self._args =3D = None + self.title =3D "" + self.lines =3D [] + self.path =3D path + map(self.set_from_line, lines) + self.root =3D "" # dummy + + def set_from_line(self, line, replace =3D None): + (com, arg) =3D GrubConf.grub_exact_split(line, 2) + + if self.commands.has_key(com): + if self.commands[com] is not None: + exec("%s =3D r\'%s\'" %(self.commands[com], = re.sub('^"(.+)"$', r"\1", arg.strip()))) + else: + logging.info("Ignored image directive %s" %(com,)) + else: + logging.warning("Unknown image directive %s" %(com,)) + + # now put the line in the list of lines + if replace is None: + self.lines.append(line) + else: + self.lines.pop(replace) + self.lines.insert(replace, line) + + def set_kernel(self, val): + self._kernel =3D (None, self.path + "/" + val) + def get_kernel(self): + return self._kernel + kernel =3D property(get_kernel, set_kernel) + + def set_initrd(self, val): + self._initrd =3D (None, self.path + "/" + val) + def get_initrd(self): + return self._initrd + initrd =3D property(get_initrd, set_initrd) + + # set up command handlers + commands =3D { "label": "self.title", + "root": "self.root", + "rootnoverify": "self.root", + "image": "self.kernel", + "initrd": "self.initrd", + "append": "self.args", + "read-only": None, + "chainloader": None, + "module": None} + +class LiloConfigFile(object): + def __init__(self, fn =3D None): + self.filename =3D fn + self.images =3D [] + self.timeout =3D -1 + self._default =3D 0 + + if fn is not None: + self.parse() + + def parse(self, buf =3D None): + if buf is None: + if self.filename is None: + raise ValueError, "No config file defined to parse!" + + f =3D open(self.filename, 'r') + lines =3D f.readlines() + f.close() + else: + lines =3D buf.split("\n") + + path =3D os.path.dirname(self.filename) + img =3D [] + for l in lines: + l =3D l.strip() + # skip blank lines + if len(l) =3D=3D 0: + continue + # skip comments + if l.startswith('#'): + continue + # new image + if l.startswith("image"): + if len(img) > 0: + self.add_image(LiloImage(img, path)) + img =3D [l] + continue + + if len(img) > 0: + img.append(l) + continue + + (com, arg) =3D GrubConf.grub_exact_split(l, 2) + if self.commands.has_key(com): + if self.commands[com] is not None: + exec("%s =3D r\"%s\"" %(self.commands[com], = arg.strip())) + else: + logging.info("Ignored directive %s" %(com,)) + else: + logging.warning("Unknown directive %s" %(com,)) + + if len(img) > 0: + self.add_image(LiloImage(img, path)) + + def add_image(self, image): + self.images.append(image) + + def _get_default(self): + for i in range(0, len(self.images) - 1): + if self.images[i].title =3D=3D self._default: + return i + return 0 + def _set_default(self, val): + self._default =3D val + default =3D property(_get_default, _set_default) + + commands =3D { "default": "self.default", + "timeout": "self.timeout", + "prompt": None, + "relocatable": None, + } + +if __name__ =3D=3D "__main__": + if sys.argv < 2: + raise RuntimeError, "Need a grub.conf to read" + g =3D LiloConfigFile(sys.argv[1]) + for i in g.images: + print i #, i.title, i.root, i.kernel, i.args, i.initrd + print g.default ------=_NextPart_000_013C_01C77C59.3D785BA0 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel ------=_NextPart_000_013C_01C77C59.3D785BA0--