Complete remove of GCONF settings and upgrade possibility
Note: Gconf still used in GNOME for thumbnailers svn: r11444
This commit is contained in:
parent
c2c4fe3786
commit
0d084cc677
@ -7,7 +7,6 @@ pkgdatadir = $(datadir)/@PACKAGE@/Config
|
|||||||
|
|
||||||
pkgdata_PYTHON = \
|
pkgdata_PYTHON = \
|
||||||
__init__.py\
|
__init__.py\
|
||||||
_GrampsGconfKeys.py\
|
|
||||||
_GrampsConfigKeys.py\
|
_GrampsConfigKeys.py\
|
||||||
_GrampsIniKeys.py
|
_GrampsIniKeys.py
|
||||||
|
|
||||||
@ -19,10 +18,6 @@ MOSTLYCLEANFILES = *pyc *pyo
|
|||||||
|
|
||||||
GRAMPS_PY_MODPATH = "../"
|
GRAMPS_PY_MODPATH = "../"
|
||||||
|
|
||||||
keys:
|
|
||||||
echo "Re-generating the _GrampsConfigKeys.py file..." ;
|
|
||||||
python gen_schema_keys.py ../../data/gramps.schemas.in
|
|
||||||
|
|
||||||
pycheck:
|
pycheck:
|
||||||
(export PYTHONPATH=$(GRAMPS_PY_MODPATH); \
|
(export PYTHONPATH=$(GRAMPS_PY_MODPATH); \
|
||||||
pychecker $(pkgdata_PYTHON));
|
pychecker $(pkgdata_PYTHON));
|
||||||
|
@ -1,173 +0,0 @@
|
|||||||
#
|
|
||||||
# Gramps - a GTK+/GNOME based genealogy program
|
|
||||||
#
|
|
||||||
# Copyright (C) 2004-2005 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
|
|
||||||
#
|
|
||||||
|
|
||||||
# $Id$
|
|
||||||
|
|
||||||
"""
|
|
||||||
gconf is no longer supported. This functino serves only to provide an upgrade
|
|
||||||
path to the new system.
|
|
||||||
"""
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
|
||||||
#
|
|
||||||
# GConf
|
|
||||||
#
|
|
||||||
#-------------------------------------------------------------------------
|
|
||||||
# SUSE calls the gconf module "gnome.gconf"
|
|
||||||
try:
|
|
||||||
import gconf
|
|
||||||
except ImportError:
|
|
||||||
import gnome.gconf
|
|
||||||
gconf = gnome.gconf
|
|
||||||
|
|
||||||
import Errors
|
|
||||||
from _GrampsConfigKeys import default_value
|
|
||||||
|
|
||||||
client = gconf.client_get_default()
|
|
||||||
client.add_dir("/apps/gramps", gconf.CLIENT_PRELOAD_NONE)
|
|
||||||
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
|
||||||
#
|
|
||||||
# Functions to obtain values from gconf keys
|
|
||||||
# and store values into gconf keys
|
|
||||||
#
|
|
||||||
# All gramps keys should be accessed through these functions!
|
|
||||||
#
|
|
||||||
#-------------------------------------------------------------------------
|
|
||||||
|
|
||||||
def get_date_format(date_format_list):
|
|
||||||
return get_int("/apps/gramps/preferences/date-format",
|
|
||||||
range(len(date_format_list)))
|
|
||||||
|
|
||||||
def save_date_format(val, date_format_list):
|
|
||||||
set_int("/apps/gramps/preferences/date-format", val,
|
|
||||||
range(len(date_format_list)))
|
|
||||||
|
|
||||||
def get_name_format(_name_format_list):
|
|
||||||
return get_int("/apps/gramps/preferences/name-format",
|
|
||||||
range(len(_name_format_list)))
|
|
||||||
|
|
||||||
def save_name_format(val, _name_format_list):
|
|
||||||
set_int("/apps/gramps/preferences/name-format", val,
|
|
||||||
range(len(_name_format_list)))
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
|
||||||
#
|
|
||||||
# Low-level grabbing and saving keys with error checking.
|
|
||||||
#
|
|
||||||
#-------------------------------------------------------------------------
|
|
||||||
|
|
||||||
def set(key, value):
|
|
||||||
token = "/apps/gramps/%s/%s" % (key[0], key[1])
|
|
||||||
if key[2] == 0:
|
|
||||||
set_bool(token, value)
|
|
||||||
elif key[2] == 1:
|
|
||||||
set_int(token, value)
|
|
||||||
else:
|
|
||||||
set_string(token, value)
|
|
||||||
|
|
||||||
def get(key):
|
|
||||||
token = "/apps/gramps/%s/%s" % (key[0], key[1])
|
|
||||||
if key[2] == 0:
|
|
||||||
try:
|
|
||||||
val = get_bool(token)
|
|
||||||
except:
|
|
||||||
val = default_value[key]
|
|
||||||
elif key[2] == 1:
|
|
||||||
try:
|
|
||||||
val = get_int(token)
|
|
||||||
except:
|
|
||||||
val = default_value[key]
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
val = get_string(token)
|
|
||||||
except:
|
|
||||||
val = default_value[key]
|
|
||||||
if val is None:
|
|
||||||
val = default_value[key]
|
|
||||||
return val
|
|
||||||
|
|
||||||
def get_bool(key):
|
|
||||||
val = client.get(key)
|
|
||||||
if val is None:
|
|
||||||
return None
|
|
||||||
val = client.get_bool(key)
|
|
||||||
if val in (True, False):
|
|
||||||
return val
|
|
||||||
else:
|
|
||||||
val = client.get_default_from_schema(key)
|
|
||||||
if val is None:
|
|
||||||
raise Errors.GConfSchemaError("No default value for key "+key)
|
|
||||||
return val.get_bool()
|
|
||||||
|
|
||||||
def set_bool(key, val):
|
|
||||||
if val in (True, False):
|
|
||||||
client.set_bool(key, val)
|
|
||||||
|
|
||||||
def get_int(key, correct_tuple=None):
|
|
||||||
val = client.get(key)
|
|
||||||
if val is None:
|
|
||||||
return None
|
|
||||||
val = client.get_int(key)
|
|
||||||
if not correct_tuple or val in correct_tuple:
|
|
||||||
return val
|
|
||||||
else:
|
|
||||||
val = client.get_default_from_schema(key)
|
|
||||||
if val is None:
|
|
||||||
raise Errors.GConfSchemaError("No default value for key "+key)
|
|
||||||
return val.get_int()
|
|
||||||
|
|
||||||
def set_int(key, val, correct_tuple=None):
|
|
||||||
if not correct_tuple or val in correct_tuple:
|
|
||||||
client.set_int(key, val)
|
|
||||||
|
|
||||||
def get_string(key, test_func=None):
|
|
||||||
val = client.get(key)
|
|
||||||
if val is None:
|
|
||||||
return None
|
|
||||||
val = client.get_string(key)
|
|
||||||
if not test_func or test_func(val):
|
|
||||||
return val
|
|
||||||
else:
|
|
||||||
val = client.get_default_from_schema(key)
|
|
||||||
if val is None:
|
|
||||||
raise Errors.GConfSchemaError("No default value for key "+key)
|
|
||||||
return val.get_string()
|
|
||||||
|
|
||||||
def set_string(key, val, test_func=None):
|
|
||||||
if not test_func or test_func(val):
|
|
||||||
client.set_string(key, val)
|
|
||||||
|
|
||||||
def sync():
|
|
||||||
client.suggest_sync()
|
|
||||||
|
|
||||||
def get_default(key, sample=''):
|
|
||||||
token = "/apps/gramps/%s/%s" % (key[0], key[1])
|
|
||||||
value = client.get_default_from_schema(token)
|
|
||||||
if value is None:
|
|
||||||
raise Errors.GConfSchemaError("No default value for key "+key[1])
|
|
||||||
if isinstance(sample, basestring):
|
|
||||||
return value.get_string()
|
|
||||||
elif isinstance(sample, int):
|
|
||||||
return value.get_int()
|
|
||||||
elif isinstance(sample, bool):
|
|
||||||
return value.get_bool()
|
|
||||||
return None
|
|
@ -29,21 +29,3 @@ It provides the choice between different storage backends.
|
|||||||
from _GrampsConfigKeys import *
|
from _GrampsConfigKeys import *
|
||||||
from _GrampsIniKeys import *
|
from _GrampsIniKeys import *
|
||||||
|
|
||||||
import os
|
|
||||||
|
|
||||||
def __upgrade_gconf():
|
|
||||||
import _GrampsGconfKeys as GconfKeys
|
|
||||||
print "Upgrading INI file"
|
|
||||||
for key in default_value.keys():
|
|
||||||
data = GconfKeys.get(key)
|
|
||||||
set(key, data)
|
|
||||||
|
|
||||||
if not os.path.exists(INIFILE):
|
|
||||||
try:
|
|
||||||
__upgrade_gconf()
|
|
||||||
except ImportError:
|
|
||||||
print "Cannot upgrade GCONF settings"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,126 +0,0 @@
|
|||||||
copy = """#
|
|
||||||
# Gramps - a GTK+/GNOME based genealogy program
|
|
||||||
#
|
|
||||||
# Copyright (C) 2006-2007 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
|
|
||||||
#
|
|
||||||
|
|
||||||
# $Id$
|
|
||||||
|
|
||||||
# NOTE: This file is autogenerated by gen_schema_keys.py script
|
|
||||||
# from the data/gramps.schemas.in file. To generate, run:
|
|
||||||
# python gen_schema_keys.py ../../data/gramps.schemas.in
|
|
||||||
# in the src/Config directory.
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
from xml.parsers.expat import ParserCreate
|
|
||||||
|
|
||||||
class SchemaHandler:
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
self.list = []
|
|
||||||
self.clean()
|
|
||||||
|
|
||||||
def clean(self):
|
|
||||||
self.tlist = []
|
|
||||||
self.type = ""
|
|
||||||
self.default = ""
|
|
||||||
self.key = ""
|
|
||||||
self.include = False
|
|
||||||
self.short = ""
|
|
||||||
self.long = ""
|
|
||||||
|
|
||||||
def startElement(self,tag,attrs):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def endElement(self,tag):
|
|
||||||
data = ''.join(self.tlist).strip()
|
|
||||||
if tag == "type":
|
|
||||||
self.type = data
|
|
||||||
elif tag == "default":
|
|
||||||
self.default = data
|
|
||||||
elif tag == "include":
|
|
||||||
self.include = int(data)
|
|
||||||
elif tag == "short":
|
|
||||||
self.short = data
|
|
||||||
elif tag == "long":
|
|
||||||
self.long = data.replace('\n','')
|
|
||||||
elif tag == "applyto":
|
|
||||||
self.key = data
|
|
||||||
elif tag == "schema":
|
|
||||||
self.list.append((self.key, self.type, self.default,
|
|
||||||
self.long, self.short, self.include))
|
|
||||||
self.clean()
|
|
||||||
self.tlist = []
|
|
||||||
|
|
||||||
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])
|
|
||||||
|
|
||||||
f = open("_GrampsConfigKeys.py","w")
|
|
||||||
f.write(copy)
|
|
||||||
|
|
||||||
for (key, key_type, default, long, short, include) in parser.list:
|
|
||||||
data = key.split('/')
|
|
||||||
category = data[3]
|
|
||||||
token = data[4]
|
|
||||||
tkey = token.upper().replace('-','_')
|
|
||||||
tmap = type_map[key_type]
|
|
||||||
|
|
||||||
f.write("%-20s = ('%s','%s', %d)\n" % (tkey,
|
|
||||||
category,
|
|
||||||
token,
|
|
||||||
tmap))
|
|
||||||
|
|
||||||
f.write('\n\ndefault_value = {\n')
|
|
||||||
for (key, key_type, default, long, short, include) in parser.list:
|
|
||||||
data = key.split('/')
|
|
||||||
category = data[3]
|
|
||||||
token = data[4]
|
|
||||||
tkey = token.upper().replace('-','_')
|
|
||||||
if key_type == 'bool':
|
|
||||||
if default == "1":
|
|
||||||
f.write(" %-20s : True,\n" % tkey)
|
|
||||||
else:
|
|
||||||
f.write(" %-20s : False,\n" % tkey)
|
|
||||||
elif key_type == "int":
|
|
||||||
f.write(" %-20s : %s,\n" % (tkey,default))
|
|
||||||
else:
|
|
||||||
f.write(" %-20s : '%s',\n" % (tkey,default))
|
|
||||||
|
|
||||||
f.write('}\n')
|
|
||||||
f.close()
|
|
Loading…
Reference in New Issue
Block a user