* src/GrampsDb/_GrampsDbBase.py: fix typo

* src/GrampsDb/_GrampsDBDir.py: check for writability, otherwise open as readonly
	* src/DbManager.py: use single, user configurable database path
	* data/gramps.schemas.in: set default path to ~/.gramps/grampsdb
	
2007-06-16  Don Allingham  <don@gramps-project.org>


svn: r8566
This commit is contained in:
Don Allingham 2007-06-17 00:57:21 +00:00
parent 10430f3321
commit 7da9ba3e6a
5 changed files with 36 additions and 24 deletions

View File

@ -1,6 +1,12 @@
2007-06-16 Alex Roitman <shura@gramps-project.org> 2007-06-16 Alex Roitman <shura@gramps-project.org>
* src/GrampsDbUtils/_ReadXML.py (start_url): Correctly parse url type. * src/GrampsDbUtils/_ReadXML.py (start_url): Correctly parse url type.
2007-06-16 Don Allingham <don@gramps-project.org>
* src/GrampsDb/_GrampsDbBase.py: fix typo
* src/GrampsDb/_GrampsDBDir.py: check for writability, otherwise open as readonly
* src/DbManager.py: use single, user configurable database path
* data/gramps.schemas.in: set default path to ~/.gramps/grampsdb
2007-06-16 Don Allingham <don@gramps-project.org> 2007-06-16 Don Allingham <don@gramps-project.org>
* src/GrampsCfg.py: additional database path * src/GrampsCfg.py: additional database path
* src/Config/_GrampsConfigKeys.py: additional database path * src/Config/_GrampsConfigKeys.py: additional database path

View File

@ -603,7 +603,7 @@
<applyto>/apps/gramps/behavior/database-path</applyto> <applyto>/apps/gramps/behavior/database-path</applyto>
<owner>gramps</owner> <owner>gramps</owner>
<type>string</type> <type>string</type>
<default></default> <default>~/.gramps/grampsdb</default>
<locale name="C"> <locale name="C">
<short>Additional path where the databases may reside</short> <short>Additional path where the databases may reside</short>
<long>Additional path where the databases may reside</long> <long>Additional path where the databases may reside</long>

View File

@ -225,24 +225,19 @@ class DbManager:
self.model = gtk.ListStore(str, str, str, str, int, bool, str) self.model = gtk.ListStore(str, str, str, str, int, bool, str)
# make the default directory if it does not exist # make the default directory if it does not exist
dbdir = os.path.expanduser(Config.get(Config.DATABASE_PATH))
try: try:
if not os.path.isdir(DEFAULT_DIR): if not os.path.isdir(dbdir):
os.mkdir(DEFAULT_DIR) os.mkdir(dbdir)
except (IOError, OSError), msg: except (IOError, OSError), msg:
LOG.error(_("Could not make database directory: ") + str(msg)) LOG.error(_("Could not make database directory: ") + str(msg))
additional = Config.get(Config.DATABASE_PATH).strip()
pathlist = [ DEFAULT_DIR ]
if os.path.isdir(additional):
pathlist.append(additional)
self.current_names = [] self.current_names = []
for path in pathlist: for dpath in os.listdir(dbdir):
for dpath in os.listdir(path): dirpath = os.path.join(dbdir, dpath)
dirpath = os.path.join(path, dpath)
path_name = os.path.join(dirpath, NAME_FILE) path_name = os.path.join(dirpath, NAME_FILE)
if os.path.isfile(path_name): if os.path.isfile(path_name):
name = file(path_name).readline().strip() name = file(path_name).readline().strip()
@ -252,7 +247,7 @@ class DbManager:
self.dbstate.db.is_open()) self.dbstate.db.is_open())
self.current_names.append( self.current_names.append(
(name, os.path.join(DEFAULT_DIR, dpath), path_name, (name, os.path.join(dbdir, dpath), path_name,
last, tval, enable, stock_id)) last, tval, enable, stock_id))
self.current_names.sort() self.current_names.sort()

View File

@ -433,11 +433,22 @@ class GrampsDBDir(GrampsDbBase,UpdateCallback):
def load(self, name, callback, mode="w"): def load(self, name, callback, mode="w"):
try: try:
if self.__check_readonly(name):
mode = "r"
return self.__load(name, callback, mode) return self.__load(name, callback, mode)
except DBERRS, msg: except DBERRS, msg:
print name
self.__log_error() self.__log_error()
raise Errors.DbError(msg) raise Errors.DbError(msg)
def __check_readonly(self, name):
for base in [ FAMILY_TBL, PLACES_TBL, SOURCES_TBL, MEDIA_TBL, EVENTS_TBL,
PERSON_TBL, REPO_TBL, NOTE_TBL, REF_MAP, META ]:
path = os.path.join(name, base + ".db")
if not os.access(path, os.W_OK):
return True
return False
def __load(self, name, callback, mode="w"): def __load(self, name, callback, mode="w"):
if self.db_is_open: if self.db_is_open:

View File

@ -748,7 +748,7 @@ class GrampsDbBase(GrampsDBCallback):
return index return index
def __get_from_handle(self, handle, class_type, data_map): def __get_from_handle(self, handle, class_type, data_map):
data = data_map.get(str(handle),txn=self.txn) data = data_map.get(str(handle))
if data: if data:
newobj = class_type() newobj = class_type()
newobj.unserialize(data) newobj.unserialize(data)