3
# A simple script that extracts config group entry names from a file,
4
# generates variable definitions for d-classes and replaces the strings of
5
# these entries with the defined variables. The result is stored in a new file.
6
# Expects a file name as argument
8
# author: Johannes Wienke <languitar at semipol dot de>
14
filename = sys.argv[1]
16
print("Opening file " + filename)
18
source = open(filename, "r")
19
lines = source.readlines()
21
expression = re.compile("readEntry\(\"([\s\w]+)\",")
25
def makeStringDefinition(key):
26
return '"' + key + '"'
28
def makeVariable(key):
29
key = key.replace(" ", "")
30
return "config" + key[0].capitalize() + key[1:] + "Entry";
33
match = expression.search(line)
38
configKey = match.group(1)
39
configKeys.append(configKey)
43
for key in configKeys:
44
print("\t" + makeVariable(key) + " = " + makeStringDefinition(key) + ";")
50
for key in configKeys:
51
print("\tQString " + makeVariable(key) + ";")
53
# generate output file
54
outname = filename + ".out"
55
print("writing replaced entries to " + outname)
58
contents = source.read()
60
for key in configKeys:
61
print("replacing " + makeStringDefinition(key) + " with d->" + makeVariable(key))
62
contents = contents.replace(makeStringDefinition(key), "d->" + makeVariable(key))
64
out = open(outname, "w")