* src/GrampsGconfKeys.py (get_bool,get_int,get_string): Raise exception when default value could not be get from gconf schema

* src/const.py.in: Add custom exception "ErrorSchemaInvalid"
* src/GrampsMime.py (mime_type_is_defined): New method that returns True/False
* src/gramps_main.py (__init__) Catch "ErrorSchemaInvalid" exception and check for installed MIME-type. Show error because installation is incomplete.


svn: r4200
This commit is contained in:
Martin Hawlisch 2005-03-17 19:28:00 +00:00
parent d105ef6be0
commit 3dfcf51269
5 changed files with 74 additions and 19 deletions

View File

@ -1,3 +1,13 @@
2005-03-17 Martin Hawlisch <Martin.Hawlisch@gmx.de>
* src/GrampsGconfKeys.py (get_bool,get_int,get_string): Raise
exception when default value could not be get from gconf schema
* src/const.py.in: Add custom exception "ErrorSchemaInvalid"
* src/GrampsMime.py (mime_type_is_defined): New method that returns
True/False
* src/gramps_main.py (__init__) Catch "ErrorSchemaInvalid" exception
and check for installed MIME-type. Show error because installation is
incomplete.
2005-03-17 Alex Roitman <shura@gramps-project.org>
* acinclude.m4: Add macro for defining SHARED_MIME_DIR.
* configure.in: Use AM_SHARED_MIME macro.

View File

@ -38,10 +38,12 @@ except ImportError:
import gobject
import os
from const import ErrorSchemaInvalid
client = gconf.client_get_default()
client.add_dir("/apps/gramps",gconf.CLIENT_PRELOAD_NONE)
#-------------------------------------------------------------------------
#
# Functions to obtain values from gconf keys
@ -345,7 +347,10 @@ def get_bool(key):
if val in (True,False):
return val
else:
return client.get_default_from_schema(key).get_bool()
val = client.get_default_from_schema(key)
if val == None:
raise ErrorSchemaInvalid, "No default value for key "+key
return val.get_bool()
def set_bool(key,val):
if val in (True,False):
@ -359,7 +364,10 @@ def get_int(key,correct_tuple=None):
if not correct_tuple or val in correct_tuple:
return val
else:
return client.get_default_from_schema(key).get_int()
val = client.get_default_from_schema(key)
if val == None:
raise ErrorSchemaInvalid, "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:
@ -373,7 +381,10 @@ def get_string(key,test_func=None):
if not test_func or test_func(val):
return val
else:
return client.get_default_from_schema(key).get_string()
val = client.get_default_from_schema(key)
if val == None:
raise ErrorSchemaInvalid, "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):
@ -398,4 +409,3 @@ def set_string_as_id_prefix(key,val):
def sync():
client.suggest_sync()

View File

@ -51,3 +51,11 @@ def get_type(file):
return get_mime_type(file)
except:
return _('unknown')
def mime_type_is_defined(type):
""""Return True if a description for a mime type exists"""
try:
type = get_mime_type(file)
return True
except:
return False

View File

@ -154,6 +154,13 @@ documenters = [
translators = _('TRANSLATORS: Translate this to your name in your native language')
#-------------------------------------------------------------------------
#
# custom exception
#
#-------------------------------------------------------------------------
ErrorSchemaInvalid = "GConf schema not properly installed"
#-------------------------------------------------------------------------
#
# Constants

View File

@ -77,6 +77,8 @@ import RelImage
import RecentFiles
import NameDisplay
from GrampsMime import mime_type_is_defined
from QuestionDialog import *
from bsddb import db
@ -131,21 +133,39 @@ class Gramps:
self.db = GrampsBSDDB.GrampsBSDDB()
GrampsCfg.loadConfig()
if GrampsKeys.get_betawarn() == 0:
WarningDialog(_("Use at your own risk"),
_("This is an unstable development version of GRAMPS. "
"It is intended as a technology preview. Do not trust your "
"family database to this development version. This version may "
"contain bugs which could corrupt your database."))
GrampsKeys.save_betawarn(1)
GrampsKeys.sync()
self.RelClass = PluginMgr.relationship_class
self.relationship = self.RelClass(self.db)
self.gtop = gtk.glade.XML(const.gladeFile, "gramps", "gramps")
self.init_interface()
try:
GrampsCfg.loadConfig()
if GrampsKeys.get_betawarn() == 0:
WarningDialog(_("Use at your own risk"),
_("This is an unstable development version of GRAMPS. "
"It is intended as a technology preview. Do not trust your "
"family database to this development version. This version may "
"contain bugs which could corrupt your database."))
GrampsKeys.save_betawarn(1)
GrampsKeys.sync()
self.RelClass = PluginMgr.relationship_class
self.relationship = self.RelClass(self.db)
self.gtop = gtk.glade.XML(const.gladeFile, "gramps", "gramps")
self.init_interface()
except const.ErrorSchemaInvalid, val:
ErrorDialog(_("Configuration error"),
val + _("\n\nPossibly the installation of GRAMPS was incomplete."
" Make sure the GConf schema of GRAMPS is properly installed."))
gtk.main_quit()
return
if not mime_type_is_defined(const.app_gramps):
ErrorDialog(_("Configuration error"),
_("A definition for the MIME-type %s could not be found"
"\n\nPossibly the installation of GRAMPS was incomplete."
" Make sure the MIME-types of GRAMPS are properly installed.") % const.app_gramps)
gtk.main_quit()
return
ArgHandler.ArgHandler(self,args)