2008-03-02 Gary Burton <gary.burton@zen.co.uk>

* src/GrampsCfg.py:
	* src/Config/_GrampsConfigKeys.py:
	* src/gen/db/dbdir.py:
	* src/DbManager.py:
	* src/DbLoader.py: Gramps databases run with transactions enabled. The
	option to switch off transactions is now removed. The "transactions" and 
	"port_warn" settings are ignored in the config file.



svn: r10169
This commit is contained in:
Gary Burton 2008-03-02 21:34:51 +00:00
parent d78dacb08b
commit 34cf711351
6 changed files with 72 additions and 178 deletions

View File

@ -1,3 +1,12 @@
2008-03-02 Gary Burton <gary.burton@zen.co.uk>
* src/GrampsCfg.py:
* src/Config/_GrampsConfigKeys.py:
* src/gen/db/dbdir.py:
* src/DbManager.py:
* src/DbLoader.py: Gramps databases run with transactions enabled. The
option to switch off transactions is now removed. The "transactions" and
"port_warn" settings are ignored in the config file.
2008-03-02 Brian Matherly <brian@gramps-project.org>
* src/plugins/CmdRef.py:
0001873: AttributeError: 'NoneType' object has no attribute

View File

@ -143,8 +143,6 @@ POP_PLUGIN_STATUS = ('behavior', 'pop-plugin-status', 0)
VIEW = ('interface', 'view', 0)
SIDEBAR_TEXT = ('interface', 'sidebar-text', 0)
WEBSITE_DIRECTORY = ('paths', 'website-directory', 2)
PORT_WARN = ('preferences', 'port-warn', 0)
TRANSACTIONS = ('behavior', 'transactions', 0)
LDS_HEIGHT = ('interface', 'lds-height', 1)
LDS_WIDTH = ('interface', 'lds-width', 1)
LOCATION_HEIGHT = ('interface', 'location-height', 1)
@ -267,8 +265,6 @@ default_value = {
VIEW : True,
SIDEBAR_TEXT : True,
WEBSITE_DIRECTORY : const.USER_HOME,
PORT_WARN : False,
TRANSACTIONS : True,
LDS_HEIGHT : 450,
LDS_WIDTH : 600,
LOCATION_HEIGHT : 250,

View File

@ -262,7 +262,7 @@ class DbLoader:
dbclass = gen.db.GrampsDBDir
self.dbstate.change_database(dbclass(Config.get(Config.TRANSACTIONS)))
self.dbstate.change_database(dbclass())
self.dbstate.db.disable_signals()
self.uistate.window.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))

View File

@ -209,13 +209,12 @@ class CLIDbManager:
# create the database
new_path, name = self._create_new_db(name)
trans = Config.TRANSACTIONS
# get the import function using the filetype, but create a db
# based on the DBDir
self.__start_cursor(_("Importing data..."))
dbclass = gen.db.GrampsDBDir
dbase = dbclass(trans)
dbase = dbclass()
dbase.load(new_path, callback)
rdr = GrampsDbUtils.gramps_db_reader_factory(filetype)
@ -661,11 +660,10 @@ class DbManager(CLIDbManager):
imports it into the db
"""
new_path, newname = self._create_new_db("%s : %s" % (parent_name, name))
trans = Config.TRANSACTIONS
self.__start_cursor(_("Extracting archive..."))
dbclass = gen.db.GrampsDBDir
dbase = dbclass(trans)
dbase = dbclass()
dbase.load(new_path, None)
self.__start_cursor(_("Importing archive..."))
@ -788,7 +786,7 @@ class DbManager(CLIDbManager):
os.unlink(fname)
dbclass = gen.db.GrampsDBDir
dbase = dbclass(Config.get(Config.TRANSACTIONS))
dbase = dbclass()
dbase.set_save_path(dirname)
dbase.load(dirname, None)

View File

@ -143,7 +143,6 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
buttons=(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)),
None, _('Preferences'), None)
panel = gtk.Notebook()
self.original = Config.get(Config.TRANSACTIONS)
self.window.vbox.add(panel)
self.window.connect('response', self.done)
panel.append_page(self.add_behavior_panel(),
@ -166,8 +165,6 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
self.show()
def done(self, obj, value):
if not self.original and Config.get(Config.TRANSACTIONS):
Config.set(Config.PORT_WARN, True)
self.close()
def add_researcher_panel(self):
@ -758,7 +755,7 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
return table
def add_database_panel(self):
table = gtk.Table(3, 8)
table = gtk.Table(2, 8)
table.set_border_width(12)
table.set_col_spacings(6)
table.set_row_spacings(6)
@ -768,8 +765,6 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
1, Config.ENABLE_AUTOBACKUP)
self.add_checkbox(table, _('Automatically load last database'),
2, Config.AUTOLOAD)
self.add_checkbox(table, _('Enable database transactions'),
3, Config.TRANSACTIONS)
return table
def add_checkbox(self, table, label, index, constant):

View File

@ -179,19 +179,15 @@ class GrampsDBDir(GrampsDbBase, UpdateCallback):
This object is a base class for other objects.
"""
def __init__(self, use_txn = True):
def __init__(self):
"""Create a new GrampsDB."""
GrampsDbBase.__init__(self)
self.txn = None
self.secondary_connected = False
self.UseTXN = use_txn
def __open_flags(self):
if self.UseTXN:
return db.DB_CREATE | db.DB_AUTO_COMMIT
else:
return db.DB_CREATE
def __open_table(self, file_name, table_name, dbtype=db.DB_HASH):
dbmap = dbshelve.DBShelf(self.env)
@ -376,16 +372,10 @@ class GrampsDBDir(GrampsDbBase, UpdateCallback):
def __set_default_person_handle(self, handle):
"""Set the default Person to the passed instance."""
if not self.readonly:
if self.UseTXN:
# Start transaction if needed
# Start transaction
the_txn = self.env.txn_begin()
else:
the_txn = None
self.metadata.put('default', str(handle), txn=the_txn)
if self.UseTXN:
the_txn.commit()
else:
self.metadata.sync()
def get_default_person(self):
try:
@ -400,44 +390,26 @@ class GrampsDBDir(GrampsDbBase, UpdateCallback):
if person:
return person
elif (self.metadata) and (not self.readonly):
if self.UseTXN:
# Start transaction if needed
# Start transaction
the_txn = self.env.txn_begin()
else:
the_txn = None
self.metadata.put('default', None, txn=the_txn)
if self.UseTXN:
the_txn.commit()
else:
self.metadata.sync()
return None
def set_mediapath(self, path):
"""Set the default media path for database, path should be utf-8."""
if self.metadata and not self.readonly:
if self.UseTXN:
# Start transaction if needed
# Start transaction
the_txn = self.env.txn_begin()
else:
the_txn = None
self.metadata.put('mediapath', path, txn=the_txn)
if self.UseTXN:
the_txn.commit()
else:
self.metadata.sync()
def set_column_order(self, col_list, name):
if self.metadata and not self.readonly:
if self.UseTXN:
# Start transaction if needed
# Start transaction
the_txn = self.env.txn_begin()
else:
the_txn = None
self.metadata.put(name, col_list, txn=the_txn)
if self.UseTXN:
the_txn.commit()
else:
self.metadata.sync()
def version_supported(self):
try:
@ -479,8 +451,6 @@ class GrampsDBDir(GrampsDbBase, UpdateCallback):
self.close()
self.readonly = mode == "r"
if self.readonly:
self.UseTXN = False
if callback:
callback(12)
@ -492,7 +462,6 @@ class GrampsDBDir(GrampsDbBase, UpdateCallback):
self.env = db.DBEnv()
self.env.set_cachesize(0, 0x4000000) # 32MB
if self.UseTXN:
# These env settings are only needed for Txn environment
self.env.set_lk_max_locks(25000)
self.env.set_lk_max_objects(25000)
@ -509,12 +478,8 @@ class GrampsDBDir(GrampsDbBase, UpdateCallback):
# Environment name is now based on the filename
env_name = 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)
if self.UseTXN:
self.env.txn_checkpoint()
if callback:
@ -553,11 +518,8 @@ class GrampsDBDir(GrampsDbBase, UpdateCallback):
gstats = self.metadata.get('gender_stats', default=None)
if not self.readonly:
if self.UseTXN:
# Start transaction if needed
# Start transaction
the_txn = self.env.txn_begin()
else:
the_txn = None
if gstats == None:
# New database. Set up the current version.
@ -567,10 +529,7 @@ class GrampsDBDir(GrampsDbBase, UpdateCallback):
# Use 0, but it is likely to fail anyway.
self.metadata.put('version', 0, txn=the_txn)
if self.UseTXN:
the_txn.commit()
else:
self.metadata.sync()
self.genderStats = GenderStats(gstats)
@ -1021,8 +980,6 @@ class GrampsDBDir(GrampsDbBase, UpdateCallback):
if not self.readonly:
if transaction.batch:
self.reference_map.delete(str(key), txn=txn)
if not self.UseTXN:
self.reference_map.sync()
else:
old_data = self.reference_map.get(str(key), txn=self.txn)
transaction.add(REFERENCE_KEY, str(key), old_data, None)
@ -1039,8 +996,6 @@ class GrampsDBDir(GrampsDbBase, UpdateCallback):
if transaction.batch:
self.reference_map.put(str(key), data, txn=txn)
if not self.UseTXN:
self.reference_map.sync()
else:
transaction.add(REFERENCE_KEY, str(key), None, data)
transaction.reference_add.append((str(key), data))
@ -1128,13 +1083,8 @@ class GrampsDBDir(GrampsDbBase, UpdateCallback):
obj = InstanceType(class_func)
obj.unserialize(val)
if self.UseTXN:
the_txn = self.env.txn_begin()
else:
the_txn = None
self.update_reference_map(obj, transaction, the_txn)
if not self.UseTXN:
self.reference_map.sync()
if the_txn:
the_txn.commit()
@ -1155,11 +1105,8 @@ class GrampsDBDir(GrampsDbBase, UpdateCallback):
def __close_metadata(self):
if not self.readonly:
if self.UseTXN:
# Start transaction if needed
# Start transaction
the_txn = self.env.txn_begin()
else:
the_txn = None
# name display formats
self.metadata.put('name_formats', self.name_formats, txn=the_txn)
@ -1220,10 +1167,7 @@ class GrampsDBDir(GrampsDbBase, UpdateCallback):
# name display formats
self.metadata.put('surname_list', self.surname_list, txn=the_txn)
if self.UseTXN:
the_txn.commit()
else:
self.metadata.sync()
self.metadata.close()
@ -1258,7 +1202,6 @@ class GrampsDBDir(GrampsDbBase, UpdateCallback):
if not self.db_is_open:
return
if self.UseTXN:
self.env.txn_checkpoint()
self.__close_metadata()
@ -1313,15 +1256,10 @@ class GrampsDBDir(GrampsDbBase, UpdateCallback):
handle = str(handle)
if transaction.batch:
if self.UseTXN:
the_txn = self.env.txn_begin()
else:
the_txn = None
self.delete_primary_from_reference_map(handle, transaction,
txn=the_txn)
data_map.delete(handle, txn=the_txn)
if not self.UseTXN:
data_map.sync()
if the_txn:
the_txn.commit()
else:
@ -1332,43 +1270,27 @@ class GrampsDBDir(GrampsDbBase, UpdateCallback):
def del_person(self, handle):
self.person_map.delete(str(handle), txn=self.txn)
if not self.UseTXN:
self.person_map.sync()
def del_source(self, handle):
self.source_map.delete(str(handle), txn=self.txn)
if not self.UseTXN:
self.source_map.sync()
def del_repository(self, handle):
self.repository_map.delete(str(handle), txn=self.txn)
if not self.UseTXN:
self.repository_map.sync()
def del_note(self, handle):
self.note_map.delete(str(handle), txn=self.txn)
if not self.UseTXN:
self.note_map.sync()
def del_place(self, handle):
self.place_map.delete(str(handle), txn=self.txn)
if not self.UseTXN:
self.place_map.sync()
def del_media(self, handle):
self.media_map.delete(str(handle), txn=self.txn)
if not self.UseTXN:
self.media_map.sync()
def del_family(self, handle):
self.family_map.delete(str(handle), txn=self.txn)
if not self.UseTXN:
self.family_map.sync()
def del_event(self, handle):
self.event_map.delete(str(handle), txn=self.txn)
if not self.UseTXN:
self.event_map.sync()
def set_name_group_mapping(self, name, group):
"""
@ -1384,21 +1306,16 @@ class GrampsDBDir(GrampsDbBase, UpdateCallback):
def __set_name_group_mapping(self, name, group):
if not self.readonly:
if self.UseTXN:
# Start transaction if needed
# Start transaction
the_txn = self.env.txn_begin()
else:
the_txn = None
name = str(name)
data = self.name_group.get(name, txn=the_txn)
if data is not None:
self.name_group.delete(name, txn=the_txn)
if group is not None:
self.name_group.put(name, group, txn=the_txn)
if self.UseTXN:
the_txn.commit()
else:
self.name_group.sync()
self.emit('person-rebuild')
def build_surname_list(self):
@ -1536,14 +1453,9 @@ class GrampsDBDir(GrampsDbBase, UpdateCallback):
handle = str(obj.handle)
if transaction.batch:
if self.UseTXN:
the_txn = self.env.txn_begin()
else:
the_txn = None
self.update_reference_map(obj, transaction, txn=the_txn)
data_map.put(handle, obj.serialize(), txn=the_txn)
if not self.UseTXN:
data_map.sync()
if the_txn:
the_txn.commit()
old_data = None
@ -1562,8 +1474,6 @@ class GrampsDBDir(GrampsDbBase, UpdateCallback):
retlist = []
for (handle, data) in add_list:
db_map.put(handle, data, self.txn)
if not self.UseTXN:
db_map.sync()
retlist.append(str(handle))
return retlist
@ -1621,7 +1531,6 @@ class GrampsDBDir(GrampsDbBase, UpdateCallback):
self.translist = [None] * len(self.translist)
transaction = BdbTransaction(msg, self.undodb, batch, no_magic)
if transaction.batch:
if self.UseTXN:
self.env.txn_checkpoint()
self.env.set_flags(db.DB_TXN_NOSYNC, 1) # async txn
@ -1647,10 +1556,7 @@ class GrampsDBDir(GrampsDbBase, UpdateCallback):
def __transaction_commit(self, transaction, msg):
# Start BSD DB transaction -- DBTxn
if self.UseTXN:
self.txn = self.env.txn_begin()
else:
self.txn = None
GrampsDbBase.transaction_commit(self, transaction, msg)
@ -1660,15 +1566,9 @@ class GrampsDBDir(GrampsDbBase, UpdateCallback):
for key in transaction.reference_del:
self.reference_map.delete(str(key), txn=self.txn)
if (len(transaction.reference_add)+len(transaction.reference_del)) > 0\
and not self.UseTXN:
self.reference_map.sync()
# Commit BSD DB transaction -- DBTxn
if self.UseTXN:
self.txn.commit()
if transaction.batch:
if self.UseTXN:
self.env.txn_checkpoint()
self.env.set_flags(db.DB_TXN_NOSYNC, 0) # sync txn
@ -1700,10 +1600,8 @@ class GrampsDBDir(GrampsDbBase, UpdateCallback):
def undo(self, update_history=True):
try:
if self.UseTXN:
self.txn = self.env.txn_begin()
status = GrampsDbBase.undo(self, update_history)
if self.UseTXN:
if status:
self.txn.commit()
else:
@ -1716,10 +1614,8 @@ class GrampsDBDir(GrampsDbBase, UpdateCallback):
def redo(self, update_history=True):
try:
if self.UseTXN:
self.txn = self.env.txn_begin()
status = GrampsDbBase.redo(self, update_history)
if self.UseTXN:
if status:
self.txn.commit()
else: