[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen-unstable] pygrub: introduce easier to parse output format
# HG changeset patch # User Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx> # Date 1279121783 -3600 # Node ID acd99661ba05e81e8734d2fb446d9645bacf4e07 # Parent 63edd429cf4231748af81cd739370586fb762c12 pygrub: introduce easier to parse output format libxl would rather like to parse the output of pygrub. Rather than implement an SXP parser in libxl add a --output-format option to pygrub which can select an alternative, simpler to parse, format. Available formats are: sxp: current SXP output format; simple: simple key+value output with \n separating item ( for debugging). key and value are separated by a single space (and key therefore cannot contain a space); simple0: as simple but with \0 as a separator; Also add --output-directory to allow temporary files to be placed somewhere other than /var/run/xend/boot. Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx> --- tools/pygrub/src/pygrub | 57 +++++++++++++++++++++++++++++++++++++----------- 1 files changed, 44 insertions(+), 13 deletions(-) diff -r 63edd429cf42 -r acd99661ba05 tools/pygrub/src/pygrub --- a/tools/pygrub/src/pygrub Wed Jul 14 16:32:47 2010 +0100 +++ b/tools/pygrub/src/pygrub Wed Jul 14 16:36:23 2010 +0100 @@ -630,16 +630,34 @@ def sniff_netware(fs, cfg): return cfg +def format_sxp(kernel, ramdisk, args): + s = "linux (kernel %s)" % kernel + if ramdisk: + s += "(ramdisk %s)" % ramdisk + if args: + s += "(args \"%s\")" % args + return s + +def format_simple(kernel, ramdisk, args, sep): + s = ("kernel %s" % kernel) + sep + if ramdisk: + s += ("ramdisk %s" % ramdisk) + sep + if args: + s += ("args %s" % args) + sep + s += sep + return s + if __name__ == "__main__": sel = None def usage(): - print >> sys.stderr, "Usage: %s [-q|--quiet] [-i|--interactive] [-n|--not-really] [--output=] [--kernel=] [--ramdisk=] [--args=] [--entry=] <image>" %(sys.argv[0],) + print >> sys.stderr, "Usage: %s [-q|--quiet] [-i|--interactive] [-n|--not-really] [--output=] [--kernel=] [--ramdisk=] [--args=] [--entry=] [--output-directory=] [--output-format=sxp|simple|simple0] <image>" %(sys.argv[0],) try: opts, args = getopt.gnu_getopt(sys.argv[1:], 'qinh::', - ["quiet", "interactive", "not-really", - "help", "output=", "entry=", "kernel=", + ["quiet", "interactive", "not-really", "help", + "output=", "output-format=", "output-directory=", + "entry=", "kernel=", "ramdisk=", "args=", "isconfig"]) except getopt.GetoptError: usage() @@ -655,6 +673,8 @@ if __name__ == "__main__": interactive = True isconfig = False not_really = False + output_format = "sxp" + output_directory = "/var/run/xend/boot" # what was passed in incfg = { "kernel": None, "ramdisk": None, "args": "" } @@ -687,6 +707,14 @@ if __name__ == "__main__": interactive = False elif o in ("--isconfig",): isconfig = True + elif o in ("--output-format",): + if a not in ["sxp", "simple", "simple0"]: + print "unkonwn output format %s" % a + usage() + sys.exit(1) + output_format = a + elif o in ("--output-directory",): + output_directory = a if output is None or output == "-": fd = sys.stdout.fileno() @@ -723,7 +751,7 @@ if __name__ == "__main__": else: data = fs.open_file(chosencfg["kernel"]).read() (tfd, bootcfg["kernel"]) = tempfile.mkstemp(prefix="boot_kernel.", - dir="/var/run/xend/boot") + dir=output_directory) os.write(tfd, data) os.close(tfd) @@ -733,26 +761,29 @@ if __name__ == "__main__": else: data = fs.open_file(chosencfg["ramdisk"],).read() (tfd, bootcfg["ramdisk"]) = tempfile.mkstemp( - prefix="boot_ramdisk.", dir="/var/run/xend/boot") + prefix="boot_ramdisk.", dir=output_directory) os.write(tfd, data) os.close(tfd) else: initrd = None - sxp = "linux (kernel %s)" % bootcfg["kernel"] - if bootcfg["ramdisk"]: - sxp += "(ramdisk %s)" % bootcfg["ramdisk"] + args = None if chosencfg["args"]: zfsinfo = fsimage.getbootstring(fs) - if zfsinfo is None: - sxp += "(args \"%s\")" % chosencfg["args"] - else: + if zfsinfo is not None: e = re.compile("zfs-bootfs=[\w\-\.\:@/]+" ) (chosencfg["args"],count) = e.subn(zfsinfo, chosencfg["args"]) if count == 0: chosencfg["args"] += " -B %s" % zfsinfo - sxp += "(args \"%s\")" % (chosencfg["args"]) + args = chosencfg["args"] + + if output_format == "sxp": + ostring = format_sxp(bootcfg["kernel"], bootcfg["ramdisk"], args) + elif output_format == "simple": + ostring = format_simple(bootcfg["kernel"], bootcfg["ramdisk"], args, "\n") + elif output_format == "simple0": + ostring = format_simple(bootcfg["kernel"], bootcfg["ramdisk"], args, "\0") sys.stdout.flush() - os.write(fd, sxp) + os.write(fd, ostring) _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |