2006-04-25 02:34:01 +05:30
|
|
|
copy = """#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
|
|
|
# Copyright (C) 2006 Donald N. Allingham
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
"""
|
|
|
|
|
|
|
|
from xml.parsers.expat import ExpatError, ParserCreate
|
|
|
|
|
|
|
|
class SchemaHandler:
|
|
|
|
|
|
|
|
def __init__(self):
|
2006-04-26 07:14:03 +05:30
|
|
|
self.list = []
|
|
|
|
self.clean()
|
|
|
|
|
|
|
|
def clean(self):
|
2006-04-25 02:34:01 +05:30
|
|
|
self.tlist = []
|
|
|
|
self.type = ""
|
|
|
|
self.default = ""
|
|
|
|
self.key = ""
|
2006-04-26 07:14:03 +05:30
|
|
|
self.include = False
|
2006-04-25 02:34:01 +05:30
|
|
|
self.short = ""
|
2006-04-26 07:14:03 +05:30
|
|
|
self.long = ""
|
2006-04-25 02:34:01 +05:30
|
|
|
|
|
|
|
def startElement(self,tag,attrs):
|
2006-04-26 07:14:03 +05:30
|
|
|
pass
|
2006-04-25 02:34:01 +05:30
|
|
|
|
|
|
|
def endElement(self,tag):
|
2006-04-26 07:14:03 +05:30
|
|
|
data = ''.join(self.tlist).strip()
|
2006-04-25 02:34:01 +05:30
|
|
|
if tag == "type":
|
|
|
|
self.type = data
|
|
|
|
elif tag == "default":
|
|
|
|
self.default = data
|
2006-04-26 07:14:03 +05:30
|
|
|
elif tag == "include":
|
|
|
|
self.include = int(data)
|
|
|
|
elif tag == "short":
|
|
|
|
self.short = data
|
|
|
|
elif tag == "long":
|
|
|
|
self.long = data.replace('\n','')
|
2006-04-25 02:34:01 +05:30
|
|
|
elif tag == "applyto":
|
|
|
|
self.key = data
|
|
|
|
elif tag == "schema":
|
2006-04-26 07:14:03 +05:30
|
|
|
self.list.append((self.key, self.type, self.default,
|
|
|
|
self.long, self.short, self.include))
|
|
|
|
self.clean()
|
|
|
|
self.tlist = []
|
2006-04-25 02:34:01 +05:30
|
|
|
|
|
|
|
def characters(self, data):
|
|
|
|
self.tlist.append(data)
|
|
|
|
|
|
|
|
def parse(self, name):
|
|
|
|
|
|
|
|
f = open(name)
|
|
|
|
|
|
|
|
self.p = ParserCreate()
|
|
|
|
self.p.StartElementHandler = self.startElement
|
|
|
|
self.p.EndElementHandler = self.endElement
|
|
|
|
self.p.CharacterDataHandler = self.characters
|
|
|
|
self.p.ParseFile(f)
|
|
|
|
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
import sys
|
|
|
|
|
|
|
|
type_map = { 'bool' : 0, 'int' : 1 , 'string' : 2 }
|
|
|
|
|
|
|
|
parser = SchemaHandler()
|
|
|
|
parser.parse(sys.argv[1])
|
2006-04-26 07:14:03 +05:30
|
|
|
|
|
|
|
f = open("_GrampsConfigKeys","w")
|
|
|
|
|
|
|
|
for (key, key_type, default, long, short, include) in parser.list:
|
2006-04-25 02:34:01 +05:30
|
|
|
data = key.split('/')
|
|
|
|
category = data[3]
|
|
|
|
token = data[4]
|
2006-04-26 07:14:03 +05:30
|
|
|
tkey = token.upper().replace('-','_')
|
|
|
|
tmap = type_map[key_type]
|
2006-04-25 02:34:01 +05:30
|
|
|
|
2006-04-26 07:14:03 +05:30
|
|
|
f.write("%-20s = ('%s','%s', %d)\n" % (tkey,
|
|
|
|
category,
|
|
|
|
token,
|
|
|
|
tmap))
|
2006-04-25 02:34:01 +05:30
|
|
|
|
2006-04-26 07:14:03 +05:30
|
|
|
f.write('\n\ndefault_value = {\n')
|
|
|
|
for (key, key_type, default, long, short, include) in parser.list:
|
2006-04-25 02:34:01 +05:30
|
|
|
data = key.split('/')
|
|
|
|
category = data[3]
|
|
|
|
token = data[4]
|
|
|
|
tkey = token.upper().replace('-','_')
|
|
|
|
if key_type == 'bool':
|
|
|
|
if default == "1":
|
2006-04-26 07:14:03 +05:30
|
|
|
f.write(" %-20s : True,\n" % tkey)
|
2006-04-25 02:34:01 +05:30
|
|
|
else:
|
2006-04-26 07:14:03 +05:30
|
|
|
f.write(" %-20s : False,\n" % tkey)
|
2006-04-25 02:34:01 +05:30
|
|
|
elif key_type == "int":
|
2006-04-26 07:14:03 +05:30
|
|
|
f.write(" %-20s : %s,\n" % (tkey,default))
|
2006-04-25 02:34:01 +05:30
|
|
|
else:
|
2006-04-26 07:14:03 +05:30
|
|
|
f.write(" %-20s : '%s',\n" % (tkey,default))
|
2006-04-25 02:34:01 +05:30
|
|
|
|
2006-04-26 07:14:03 +05:30
|
|
|
f.write('}\n')
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
f = open("schema.xml.in","w")
|
|
|
|
|
|
|
|
f.write('<gconfschemafile>\n')
|
|
|
|
f.write(' <schemalist>\n')
|
|
|
|
for (key, key_type, default, long, short, include) in parser.list:
|
|
|
|
f.write(' <schema>\n')
|
|
|
|
f.write(' <key>/schemas%s</key>\n' % key)
|
|
|
|
f.write(' <applyto>/schemas%s</applyto>\n' % key)
|
|
|
|
f.write(' <owner>gramps</owner>\n')
|
|
|
|
f.write(' <type>%s</owner>\n' % type)
|
|
|
|
f.write(' <default>%s</default>\n' % default)
|
|
|
|
f.write(' <locale name="C">\n')
|
|
|
|
f.write(' <short>%s</short>\n' % short)
|
|
|
|
f.write(' <long>%s</long>\n' % long)
|
|
|
|
f.write(' </locale>\n')
|
|
|
|
f.write(' </schema>\n')
|
|
|
|
f.write(' </schemalist>\n')
|
|
|
|
f.write('</gconfschemafile>\n')
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
f = open("ConfigInterface.py","w")
|
|
|
|
for (key, key_type, default, long, short, include) in parser.list:
|
|
|
|
if not include:
|
|
|
|
continue
|
|
|
|
data = key.split('/')
|
|
|
|
category = data[3]
|
|
|
|
token = data[4]
|
|
|
|
tkey = token.upper().replace('-','_')
|
|
|
|
if key_type == "bool":
|
|
|
|
f.write("GrampsConfigCheckBox(_('%s'),Config.%s)\n" % (short,tkey))
|
|
|
|
f.close()
|