3 # Copyright (C) 2005 Florian Zeitz <florian-zeitz@lycos.de>
4 # Copyright (C) 2005 Stefan Reinauer <stepan@coresystems.de>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 def xmlString(string):
22 for i in range(len(string)-1):
24 string = string[:i] + "&" + string[i+1:]
26 string = string[:i] + "<" + string[i+1:]
28 string = string[:i] + ">" + string[i+1:]
31 def openInfile(filename):
32 "getting the input from the inputfile (e.g. Options.lb)"
33 infile = open(filename, "r")
35 input = infile.readlines()
40 "preparing the input for parsing (not really neccessary, but makes things simpler and doesnt take too long)"
44 if i >= len(input): break
45 if input[i] == ("" or "\n"):
47 if input[i][0:1] == "\t":
48 input[i] = input[i][1:]
52 def parseInput(input):
56 line = xmlString(line)
57 if line[:6] == "define":
58 output = output + '<option name="' + line[7:-1] + '">' + "\n"
59 elif line[:3] == "end":
60 output = output + '</option>' + "\n\n"
61 elif line[:7] == "default":
62 output = output + '<default>' + line[8:-1] + '</default>' + "\n"
63 elif line[:6] == "format":
64 output = output + '<format>' + line[7:-1] + '</format>' + "\n"
65 elif line[:6] == "export":
66 output = output + '<export>' + line[7:-1] + '</export>' + "\n"
67 elif line[:7] == "comment":
68 output = output + '<comment>' + line[8:-1] + '</comment>' + "\n"
73 "parse the given arguments"
78 if len(sys.argv) >= 2:
79 if sys.argv[1] == ("-h" or "--help"):
80 print "Syntax: mkOptionList.py [infile] [outfile]"
83 inFilename = sys.argv[1]
84 if len(sys.argv) >= 3:
85 if sys.argv[2] == ("-h" or "--help"):
86 print "Syntax: mkOptionList.py [infile] [outfile]"
89 outFilename = sys.argv[2]
94 return inFilename, outFilename
100 inFilename = "../../src/config/Options.lb"
101 outFilename = "Options.xml"
103 inFilename, outFilename = parseArgv()
105 input = openInfile(inFilename)
106 input = prepInput(input)
107 output = parseInput(input)
109 print "mkOptionList.py: coreboot option list generator"
110 print " input file : ", inFilename
111 print " output file: ", outFilename
113 #opening the output file
114 outfile = open(outFilename, "w", 0)
116 #write the beginning of the XML to the output file
117 outfile.write('<?xml version="1.0"?>')
119 outfile.write('<?xml-stylesheet type="text/xsl" href="Options.xsl"?>')
121 outfile.write('<options>')
123 outfile.write('<creationdate>')
124 outfile.write(time.strftime('%Y/%m/%d %H:%M:%S'))
125 outfile.write('</creationdate>')
129 #write the parsed file to the output file
130 outfile.write(output)
132 #write closing tags to the output file and close it
133 outfile.write('</options>')
140 if __name__ == "__main__":