diff options
author | arch import user (historical) <svn@openbios.org> | 2005-07-06 16:57:34 +0000 |
---|---|---|
committer | arch import user (historical) <svn@openbios.org> | 2005-07-06 16:57:34 +0000 |
commit | 8c8cbac3c3c5db374b640e9f9770b76b5078398e (patch) | |
tree | c0b7a6176b4ff574a2adc916cb6a7e2cac5eb19e /util/optionlist/mkOptionList.py | |
parent | 2305364397f9d4b4722e594069d4e2960cc35911 (diff) | |
download | coreboot-8c8cbac3c3c5db374b640e9f9770b76b5078398e.tar.xz |
Revision: linuxbios@linuxbios.org--devel/freebios--devel--2.0--patch-12
Creator: Stefan Reinauer <stepan@openbios.org>
Add timestamp to mkOptionList.py
mkOptionList.py: add timestamp
git-svn-id: svn://svn.coreboot.org/coreboot/trunk@1930 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Diffstat (limited to 'util/optionlist/mkOptionList.py')
-rwxr-xr-x | util/optionlist/mkOptionList.py | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/util/optionlist/mkOptionList.py b/util/optionlist/mkOptionList.py new file mode 100755 index 0000000000..c91f11aa22 --- /dev/null +++ b/util/optionlist/mkOptionList.py @@ -0,0 +1,123 @@ +#!/usr/bin/python + +def xmlString(string): + for i in range(len(string)-1): + if string[i] == "&": + string = string[:i] + "&" + string[i+1:] + if string[i] == "<": + string = string[:i] + "<" + string[i+1:] + if string[i] == ">": + string = string[:i] + ">" + string[i+1:] + return string + +def openInfile(filename): + "getting the input from the inputfile (e.g. Options.lb)" + infile = open(filename, "r") + infile.seek(0) + input = infile.readlines() + infile.close() + return input + +def prepInput(input): + "preparing the input for parsing (not really neccessary, but makes things simpler and doesnt take too long)" + i = -1 + while True: + i += 1 + if i >= len(input): break + if input[i] == ("" or "\n"): + input.pop(i) + if input[i][0:1] == "\t": + input[i] = input[i][1:] + i = -1 + return input + +def parseInput(input): + "parse the output" + output = "" + for line in input: + line = xmlString(line) + if line[:6] == "define": + output = output + '<option name="' + line[7:-1] + '">' + "\n" + elif line[:3] == "end": + output = output + '</option>' + "\n\n" + elif line[:7] == "default": + output = output + '<default>' + line[8:-1] + '</default>' + "\n" + elif line[:6] == "format": + output = output + '<format>' + line[7:-1] + '</format>' + "\n" + elif line[:6] == "export": + output = output + '<export>' + line[7:-1] + '</export>' + "\n" + elif line[:7] == "comment": + output = output + '<comment>' + line[8:-1] + '</comment>' + "\n" + + return output + +def parseArgv(): + "parse the given arguments" + import sys + + In = Out = False + + if len(sys.argv) >= 2: + if sys.argv[1] == ("-h" or "--help"): + print "Syntax: mkOptionList.py [infile] [outfile]" + else: + In = True + inFilename = sys.argv[1] + if len(sys.argv) >= 3: + if sys.argv[2] == ("-h" or "--help"): + print "Syntax: mkOptionList.py [infile] [outfile]" + else: + Out = True + outFilename = sys.argv[2] + + if In and not Out: + return inFilename + elif In and Out: + return inFilename, outFilename + + +def main(): + import time + if not parseArgv(): + inFilename = "../../src/config/Options.lb" + outFilename = "Options.xml" + else: + inFilename, outFilename = parseArgv() + + input = openInfile(inFilename) + input = prepInput(input) + output = parseInput(input) + + print "mkOptionList.py: LinuxBIOS option list generator" + print " input file : ", inFilename + print " output file: ", outFilename + + #opening the output file + outfile = open(outFilename, "w", 0) + + #write the beginning of the XML to the output file + outfile.write('<?xml version="1.0"?>') + outfile.write("\n") + outfile.write('<?xml-stylesheet type="text/xsl" href="Options.xsl"?>') + outfile.write("\n") + outfile.write('<options>') + outfile.write("\n") + outfile.write('<creationdate>') + outfile.write(time.strftime('%Y/%m/%d %H:%M:%S')) + outfile.write('</creationdate>') + outfile.write("\n") + + + #write the parsed file to the output file + outfile.write(output) + + #write closing tags to the output file and close it + outfile.write('</options>') + outfile.write("\n") + outfile.flush() + outfile.close() + + print "Done!" + +if __name__ == "__main__": + main() |