summaryrefslogtreecommitdiff
path: root/src/configgen.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/configgen.py')
-rwxr-xr-xsrc/configgen.py157
1 files changed, 93 insertions, 64 deletions
diff --git a/src/configgen.py b/src/configgen.py
index 910b6af..ab4cfda 100755
--- a/src/configgen.py
+++ b/src/configgen.py
@@ -17,6 +17,24 @@ import sys
import re
import textwrap
from xml.dom import minidom, Node
+import io
+
+messages = {}
+
+# wrapper class to write to file/output in UTF-8 format
+class OutputWriter:
+ def __init__(self,writer) :
+ self.writer = io.open(writer.fileno(), 'w', encoding='utf8')
+
+ def write(self, text) :
+ if sys.version_info.major == 2:
+ self.writer.write(unicode(text))
+ else:
+ self.writer.write(text)
+
+ def flush(self):
+ self.writer.flush()
+
def transformDocs(doc):
# join lines, unless it is an empty line
@@ -153,29 +171,27 @@ def prepCDocs(node):
doc += parseDocs(n)
if (type == 'enum'):
values = collectValues(node)
- doc += "<br/>Possible values are: "
+ doc += "<br/>" + messages['possible']
rng = len(values)
for i in range(rng):
val = values[i]
if i == rng - 2:
- doc += "%s and " % (val)
+ doc += "%s%s"%(val,messages['andtxt'])
elif i == rng - 1:
doc += "%s." % (val)
else:
doc += "%s, " % (val)
if (defval != ""):
- doc += "<br/>The default value is: <code>%s</code>." % (defval)
+ doc += "<br/>" + messages['defvalcode'].format(defval)
elif (type == 'int'):
minval = node.getAttribute('minval')
maxval = node.getAttribute('maxval')
- doc += "<br/>%s: %s, %s: %s, %s: %s." % (" Minimum value", minval,
- "maximum value", maxval,
- "default value", defval)
+ doc += messages['minmaxdef'].format(minval, maxval, defval)
elif (type == 'bool'):
if (node.hasAttribute('altdefval')):
- doc += "<br/>%s: %s." % ("The default value is", "system dependent")
+ doc += "<br/>" + messages['defvaltxt'].format(messages['sysdep'])
else:
- doc += "<br/>%s: %s." % ("The default value is", "YES" if (defval == "1") else "NO")
+ doc += "<br/>" + messages['defvaltxt'].format("YES" if (defval == "1") else "NO")
elif (type == 'list'):
if format == 'string':
values = collectValues(node)
@@ -183,7 +199,7 @@ def prepCDocs(node):
for i in range(rng):
val = values[i]
if i == rng - 2:
- doc += "%s and " % (val)
+ doc += "%s%s"%(val,messages['andtxt'])
elif i == rng - 1:
doc += "%s." % (val)
else:
@@ -191,43 +207,34 @@ def prepCDocs(node):
elif (type == 'string'):
if format == 'dir':
if defval != '':
- doc += "<br/>The default directory is: <code>%s</code>." % (
- defval)
+ doc += "<br/>" + messages['defdir'].format(defval)
elif format == 'file':
abspath = node.getAttribute('abspath')
if defval != '':
if abspath != '1':
- doc += "<br/>The default file is: <code>%s</code>." % (
- defval)
+ doc += "<br/>" + messages['deffile'].format(defval)
else:
- doc += "<br/>%s: %s%s%s." % (
- "The default file (with absolute path) is",
- "<code>",defval,"</code>")
+ doc += "<br/>" + messages['deffileabs'].format(defval)
else:
if abspath == '1':
- doc += "<br/>The file has to be specified with full path."
+ doc += "<br/>" + messages['deffilefull']
elif format =='image':
abspath = node.getAttribute('abspath')
if defval != '':
if abspath != '1':
- doc += "<br/>The default image is: <code>%s</code>." % (
- defval)
+ doc += "<br/>" + messages['defimg'].format(defval)
else:
- doc += "<br/>%s: %s%s%s." % (
- "The default image (with absolute path) is",
- "<code>",defval,"</code>")
+ doc += "<br/>" + messages['defimgabs'].format(defval)
else:
if abspath == '1':
- doc += "<br/>The image has to be specified with full path."
+ doc += "<br/>" + messages['defimgfull']
else: # format == 'string':
if defval != '':
- doc += "<br/>The default value is: <code>%s</code>." % (
- defval)
+ doc += "<br/>" + messages['defvalcode'].format(defval)
# depends handling
if (node.hasAttribute('depends')):
depends = node.getAttribute('depends')
- doc += "<br/>%s \\ref cfg_%s \"%s\" is set to \\c YES." % (
- "This tag requires that the tag", depends.lower(), depends.upper())
+ doc += "<br/>" + messages['depstxt'].format(depends.lower(), depends.upper())
docC = transformDocs(doc)
return docC;
@@ -236,6 +243,8 @@ def prepCDocs(node):
def parseOption(node):
# Handling part for Doxyfile
name = node.getAttribute('id')
+ if len(name)>23:
+ raise Exception('Option name {0} too long ({1}, where max is 23 characters)'.format(name,len(name)))
type = node.getAttribute('type')
format = node.getAttribute('format')
defval = node.getAttribute('defval')
@@ -327,10 +336,16 @@ def parseOption(node):
rng = len(docC)
for i in range(rng):
line = docC[i]
- if i != rng - 1: # since we go from 0 to rng-1
- print(" \"%s\\n\"" % (line))
- else:
- print(" \"%s\"" % (line))
+ try:
+ if i != rng - 1: # since we go from 0 to rng-1
+ print(" \"%s\\n\"" % (line))
+ else:
+ print(" \"%s\"" % (line))
+ except Exception as inst:
+ sys.stdout = sys.stderr
+ print("")
+ print(inst)
+ print("")
print(" );")
addValues("cl", node)
if depends != '':
@@ -495,7 +510,7 @@ def getEnum2BoolMapping(node):
bool_rep = nv.getAttribute("bool_representation")
if name and bool_rep:
bool_value = "true" if bool_rep and bool_rep.upper() == 'YES' else "false"
- mapping.append( "{{ \"{0}\", \"{1}\" }}".format(escape(name),bool_value))
+ mapping.append( "{{ \"{0}\", {1} }}".format(escape(name),bool_value))
return mapping
def parseGroupMapInit(node):
@@ -563,12 +578,12 @@ def parseOptionDoc(node, first):
if (type == 'enum'):
values = collectValues(node)
print("")
- print("Possible values are: ")
+ print(messages['possible'])
rng = len(values)
for i in range(rng):
val = values[i]
if i == rng - 2:
- print("%s and " % (val))
+ print("%s%s" % (val,messages['andtxt']))
elif i == rng - 1:
print("%s." % (val))
else:
@@ -576,26 +591,22 @@ def parseOptionDoc(node, first):
if (defval != ""):
print("")
print("")
- print("The default value is: <code>%s</code>." % (defval))
+ print(messages['defvalcode'].format(defval))
print("")
elif (type == 'int'):
minval = node.getAttribute('minval')
maxval = node.getAttribute('maxval')
print("")
print("")
- print("%s: %s%s%s, %s: %s%s%s, %s: %s%s%s." % (
- " Minimum value", "<code>", minval, "</code>",
- "maximum value", "<code>", maxval, "</code>",
- "default value", "<code>", defval, "</code>"))
+ print(messages['minmaxdefcode'].format(minval, maxval,defval))
print("")
elif (type == 'bool'):
print("")
print("")
if (node.hasAttribute('altdefval')):
- print("The default value is: system dependent.")
+ print(messages['defvaltxt'].format(messages['sysdep']))
else:
- print("The default value is: <code>%s</code>." % (
- "YES" if (defval == "1") else "NO"))
+ print(messages['defvalcode'].format("YES" if (defval == "1") else "NO"))
print("")
elif (type == 'list'):
if format == 'string':
@@ -604,7 +615,7 @@ def parseOptionDoc(node, first):
for i in range(rng):
val = values[i]
if i == rng - 2:
- print("%s and " % (val))
+ print("%s%s" % (val,messages['andtxt']))
elif i == rng - 1:
print("%s." % (val))
else:
@@ -614,50 +625,41 @@ def parseOptionDoc(node, first):
if format == 'dir':
if defval != '':
print("")
- print("The default directory is: <code>%s</code>." % (
- defval))
+ print(messages['defdir'].format(defval))
elif format == 'file':
abspath = node.getAttribute('abspath')
if defval != '':
print("")
if abspath != '1':
- print("The default file is: <code>%s</code>." % (
- defval))
+ print(messages['deffile'].format(defval))
else:
- print("%s: %s%s%s." % (
- "The default file (with absolute path) is",
- "<code>",defval,"</code>"))
+ print(messages['deffileabs'].format(defval))
else:
if abspath == '1':
print("")
- print("The file has to be specified with full path.")
+ print(messages['deffilefull'])
elif format =='image':
abspath = node.getAttribute('abspath')
if defval != '':
print("")
if abspath != '1':
- print("The default image is: <code>%s</code>." % (
- defval))
+ print(messages['defimg'].format(defval))
else:
- print("%s: %s%s%s." % (
- "The default image (with absolute path) is",
- "<code>",defval,"</code>"))
+ print(messages['defimgabs'].format(defval))
else:
if abspath == '1':
print("")
- print("The image has to be specified with full path.")
+ print(messages['defimgfull'])
else: # format == 'string':
if defval != '':
print("")
- print("The default value is: <code>%s</code>." % (
- defval.replace('\\','\\\\')))
+ print(messages['defvalcode'].format(defval.replace('\\','\\\\')))
print("")
# depends handling
if (node.hasAttribute('depends')):
depends = node.getAttribute('depends')
print("")
- print("%s \\ref cfg_%s \"%s\" is set to \\c YES." % (
- "This tag requires that the tag", depends.lower(), depends.upper()))
+ print(messages['depstxt'].format(depends.lower(), depends.upper()))
return False
@@ -692,7 +694,7 @@ def parseDocs(node):
for n in node.childNodes:
if n.nodeType == Node.TEXT_NODE:
doc += n.nodeValue.strip()
- if n.nodeType == Node.CDATA_SECTION_NODE:
+ elif n.nodeType == Node.CDATA_SECTION_NODE:
doc += n.nodeValue.rstrip("\r\n ").lstrip("\r\n")
#doc += "<br>"
return doc
@@ -718,11 +720,30 @@ def parseFooterDoc(node):
print(doc)
+def parseGenerator(node):
+ for n in node.childNodes:
+ if n.nodeType == Node.ELEMENT_NODE:
+ if (n.nodeName == "message"):
+ name = n.getAttribute('name')
+ doc = ""
+ for n1 in n.childNodes:
+ if n1.nodeType == Node.TEXT_NODE:
+ doc += n1.nodeValue.strip()
+ elif n1.nodeType == Node.CDATA_SECTION_NODE:
+ doc += n1.nodeValue.rstrip("\r\n").lstrip("\r\n")
+ messages[name] = doc
+
def main():
if len(sys.argv)<3 or (not sys.argv[1] in ['-doc','-cpp','-wiz','-maph','-maps']):
sys.exit('Usage: %s -doc|-cpp|-wiz|-maph|-maps config.xml' % sys.argv[0])
try:
- doc = xml.dom.minidom.parse(sys.argv[2])
+ configFile = sys.argv[2]
+ if sys.version_info.major == 2:
+ fh = open(configFile,'r')
+ else:
+ fh = open(configFile,'r',encoding='utf8')
+ sys.stdout = OutputWriter(sys.stdout)
+ doc = xml.dom.minidom.parse(fh)
except Exception as inst:
sys.stdout = sys.stderr
print("")
@@ -730,6 +751,14 @@ def main():
print("")
sys.exit(1)
elem = doc.documentElement
+
+ for n in elem.childNodes:
+ if n.nodeType == Node.ELEMENT_NODE:
+ if (n.nodeName == "generator"):
+ parseGenerator(n)
+ if len(messages)==0:
+ sys.exit('<generator> section missing in %s' % configFile)
+
if (sys.argv[1] == "-doc"):
print("/* WARNING: This file is generated!")
print(" * Do not edit this file, but edit config.xml instead and run")
@@ -802,7 +831,7 @@ def main():
print(" using Enum2BoolMap = std::unordered_map<std::string,bool>;");
print(" Info(Type t,bool ConfigValues::*b) : type(t), value(b) {}")
print(" Info(Type t,int ConfigValues::*i) : type(t), value(i) {}")
- print(" Info(Type t,QCString ConfigValues::*s, Enum2BoolMap boolMap = {}) : type(t), value(s), m_boolMap(boolMap) {}")
+ print(" Info(Type t,QCString ConfigValues::*s, const Enum2BoolMap &boolMap = {}) : type(t), value(s), m_boolMap(boolMap) {}")
print(" Info(Type t,StringVector ConfigValues::*l) : type(t), value(l) {}")
print(" Type type;")
print(" union Item")