2007-06-24 Alex Roitman <shura@gramps-project.org>

* src/plugins/ReadGrdb.py (importData): Rework to upgrade and
	import a copy of grdb file, leaving the original file untouched.
	* src/GrampsDb/_GrampsBSDDB.py (make_env_name): Add method to
	determine the environment name.



svn: r8660
This commit is contained in:
Alex Roitman 2007-06-25 03:35:48 +00:00
parent 3bec863693
commit 863a701d63
3 changed files with 46 additions and 16 deletions

View File

@ -1,3 +1,9 @@
2007-06-24 Alex Roitman <shura@gramps-project.org>
* src/plugins/ReadGrdb.py (importData): Rework to upgrade and
import a copy of grdb file, leaving the original file untouched.
* src/GrampsDb/_GrampsBSDDB.py (make_env_name): Add method to
determine the environment name.
2007-06-24 Brian Matherly <brian@gramps-project.org> 2007-06-24 Brian Matherly <brian@gramps-project.org>
* src/plugins/BookReport.py (BookReportDialog::__init__): * src/plugins/BookReport.py (BookReportDialog::__init__):
Fix non text report styles Fix non text report styles

View File

@ -417,14 +417,7 @@ class GrampsBSDDB(GrampsDbBase, UpdateCallback):
if os.path.isfile(self.full_name): if os.path.isfile(self.full_name):
env_flags = env_flags | db.DB_RECOVER env_flags = env_flags | db.DB_RECOVER
# Environment name is now based on the filename env_name = self.make_env_name(self.full_name)
drive, tmp_name = os.path.splitdrive(self.full_name)
tmp_name = tmp_name.lstrip(os.sep)
env_name = os.path.join(os.path.expanduser(const.env_dir), tmp_name)
else:
env_flags = db.DB_CREATE | db.DB_PRIVATE | db.DB_INIT_MPOOL
env_name = os.path.expanduser('~')
self.env.open(env_name, env_flags) self.env.open(env_name, env_flags)
if self.UseTXN: if self.UseTXN:
self.env.txn_checkpoint() self.env.txn_checkpoint()
@ -501,6 +494,17 @@ class GrampsBSDDB(GrampsDbBase, UpdateCallback):
db_copy(other_database, self, callback) db_copy(other_database, self, callback)
return 1 return 1
def make_env_name(self,full_name):
if self.UseTXN:
# Environment name is now based on the filename
drive, tmp_name = os.path.splitdrive(full_name)
tmp_name = tmp_name.lstrip(os.sep)
env_name = os.path.join(os.path.expanduser(const.env_dir),tmp_name)
else:
env_flags = db.DB_CREATE | db.DB_PRIVATE | db.DB_INIT_MPOOL
env_name = os.path.expanduser('~')
return env_name
def __load_metadata(self): def __load_metadata(self):
# name display formats # name display formats
self.name_formats = self.metadata.get('name_formats', default=[]) self.name_formats = self.metadata.get('name_formats', default=[])

View File

@ -29,8 +29,9 @@
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import os import os
import shutil
import tempfile
from gettext import gettext as _ from gettext import gettext as _
import sets
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -58,16 +59,31 @@ from PluginUtils import register_import
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
def importData(database, filename, callback=None,cl=0,use_trans=True): def importData(database, filename, callback=None,cl=0,use_trans=True):
filename = os.path.normpath(filename)
other_database = GrampsBSDDB() other_database = GrampsBSDDB()
# Since we don't want to modify the file being imported,
# we create new temp file into which we will copy the imported file
orig_filename = os.path.normpath(filename)
new_filename = tempfile.mkstemp()[1]
new_env_name = tempfile.mkdtemp()
# determine old env dir and make db work with new env dir
orig_env_name = other_database.make_env_name(orig_filename)
other_database.make_env_name = lambda x: new_env_name
# copy data (and env if using TXN)
shutil.copyfile(orig_filename,new_filename)
if other_database.UseTXN:
shutil.rmtree(new_env_name)
shutil.copytree(orig_env_name,new_env_name)
try: try:
other_database.load(filename,callback) other_database.load(new_filename,callback)
except: except:
if cl: if cl:
print "Error: %s could not be opened. Exiting." % filename print "Error: %s could not be opened. Exiting." % new_filename
else: else:
ErrorDialog(_("%s could not be opened") % filename) ErrorDialog(_("%s could not be opened") % new_filename)
return return
if not other_database.version_supported(): if not other_database.version_supported():
@ -216,6 +232,10 @@ def importData(database, filename, callback=None,cl=0,use_trans=True):
# close the other database and clean things up # close the other database and clean things up
other_database.close() other_database.close()
# Remove temp file and env dir
os.unlink(new_filename)
shutil.rmtree(new_env_name)
database.transaction_commit(trans,_("Import database")) database.transaction_commit(trans,_("Import database"))
database.enable_signals() database.enable_signals()
database.request_rebuild() database.request_rebuild()
@ -224,8 +244,8 @@ def check_common_handles(table,other_table,msg):
# Check for duplicate handles. At the moment we simply exit here, # Check for duplicate handles. At the moment we simply exit here,
# before modifying any data. In the future we will need to handle # before modifying any data. In the future we will need to handle
# this better. How? # this better. How?
handles = sets.Set(table.keys()) handles = set(table.keys())
other_handles = sets.Set(other_table.keys()) other_handles = set(other_table.keys())
if handles.intersection(other_handles): if handles.intersection(other_handles):
raise HandleError(msg) raise HandleError(msg)
return len(other_handles) return len(other_handles)