diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index b4d106085..e5783d83c 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -3,6 +3,7 @@ parents in case the toolbar is not visible. 2006-12-01 Alex Roitman + * src/plugins/Rebuild.py (__init__): Proper progress indication. * src/ArgHandler.py (cl_action): Properly call CLI tool. * src/plugins/DumpGenderStats.py (__init__): Fix CLI mode. * src/PluginUtils/_Tool.py (cli_tool): Fix CLI tools. diff --git a/gramps2/src/GrampsDb/_GrampsBSDDB.py b/gramps2/src/GrampsDb/_GrampsBSDDB.py index 0e81d68f4..99525f17b 100644 --- a/gramps2/src/GrampsDb/_GrampsBSDDB.py +++ b/gramps2/src/GrampsDb/_GrampsBSDDB.py @@ -606,7 +606,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): self.secondary_connected = True - def rebuild_secondary(self,callback=None): + def rebuild_secondary(self,callback): if self.readonly: return @@ -616,54 +616,65 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): self.id_trans.close() junk = db.DB(self.env) junk.remove(self.full_name,"idtrans") + callback(1) self.surnames.close() junk = db.DB(self.env) junk.remove(self.full_name,"surnames") + callback(2) # Repair secondary indices related to family_map self.fid_trans.close() junk = db.DB(self.env) junk.remove(self.full_name,"fidtrans") + callback(3) # Repair secondary indices related to place_map self.pid_trans.close() junk = db.DB(self.env) junk.remove(self.full_name,"pidtrans") + callback(4) # Repair secondary indices related to media_map self.oid_trans.close() junk = db.DB(self.env) junk.remove(self.full_name,"oidtrans") + callback(5) # Repair secondary indices related to source_map self.sid_trans.close() junk = db.DB(self.env) junk.remove(self.full_name,"sidtrans") + callback(6) # Repair secondary indices related to event_map self.eid_trans.close() junk = db.DB(self.env) junk.remove(self.full_name,"eidtrans") + callback(7) # Repair secondary indices related to repository_map self.rid_trans.close() junk = db.DB(self.env) junk.remove(self.full_name,"ridtrans") + callback(8) # Repair secondary indices related to reference_map self.reference_map_primary_map.close() junk = db.DB(self.env) junk.remove(self.full_name,"reference_map_primary_map") + callback(9) self.reference_map_referenced_map.close() junk = db.DB(self.env) junk.remove(self.full_name,"reference_map_referenced_map") + callback(10) # Set flag saying that we have removed secondary indices # and then call the creating routine self.secondary_connected = False self.connect_secondary() + callback(11) def find_backlink_handles(self, handle, include_classes=None): """ @@ -865,7 +876,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): transaction.add(REFERENCE_KEY,str(key),None,data) transaction.reference_add.append((str(key),data)) - def reindex_reference_map(self): + def reindex_reference_map(self,callback): """ Reindex all primary records in the database. This will be a slow process for large databases. @@ -876,14 +887,17 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): self.reference_map_referenced_map.close() junk = db.DB(self.env) junk.remove(self.full_name,"reference_map_referenced_map") + callback(1) self.reference_map_primary_map.close() junk = db.DB(self.env) junk.remove(self.full_name,"reference_map_primary_map") + callback(2) self.reference_map.close() junk = db.DB(self.env) junk.remove(self.full_name,"reference_map") + callback(3) # Open reference_map and primapry map self.reference_map = self.open_table(self.full_name, "reference_map", @@ -919,6 +933,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): } transaction = self.transaction_begin(batch=True,no_magic=True) + callback(4) # Now we use the functions and classes defined above # to loop through each of the primary object tables. @@ -948,6 +963,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): data = cursor.next() cursor.close() + callback(5) self.transaction_commit(transaction,_("Rebuild reference map")) self.reference_map_referenced_map = db.DB(self.env) @@ -957,6 +973,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): db.DB_BTREE,flags=open_flags) self.reference_map.associate(self.reference_map_referenced_map, find_referenced_handle,open_flags) + callback(6) return diff --git a/gramps2/src/GrampsDb/_GrampsDbBase.py b/gramps2/src/GrampsDb/_GrampsDbBase.py index e463047ed..1b1af31ef 100644 --- a/gramps2/src/GrampsDb/_GrampsDbBase.py +++ b/gramps2/src/GrampsDb/_GrampsDbBase.py @@ -283,7 +283,7 @@ class GrampsDbBase(GrampsDBCallback): self.path = "" self.name_group = {} - def rebuild_secondary(self, callback=None): + def rebuild_secondary(self, callback): pass def version_supported(self): @@ -2044,7 +2044,7 @@ class GrampsDbBase(GrampsDBCallback): need to be changed.""" pass - def reindex_reference_map(self): + def reindex_reference_map(self,callback): """ Reindex all primary records in the database. diff --git a/gramps2/src/plugins/Rebuild.py b/gramps2/src/plugins/Rebuild.py index c558508d0..5acdc2a75 100644 --- a/gramps2/src/plugins/Rebuild.py +++ b/gramps2/src/plugins/Rebuild.py @@ -53,47 +53,49 @@ import gtk.glade # #------------------------------------------------------------------------- import RelLib -import Utils import const from PluginUtils import Tool, register_tool from QuestionDialog import OkDialog +from BasicUtils import UpdateCallback #------------------------------------------------------------------------- # # runTool # #------------------------------------------------------------------------- -class Rebuild(Tool.Tool): +class Rebuild(Tool.Tool,UpdateCallback): def __init__(self, dbstate, uistate, options_class, name, callback=None): Tool.Tool.__init__(self, dbstate, options_class, name) if self.db.readonly: - # TODO: split plugin in a check and repair part to support - # checking of a read only database return self.db.disable_signals() if uistate: - progress = Utils.ProgressMeter( - _('Rebuilding Secondary Indices')) - # Six indices to rebuild, and the first step is removing - # old ones - total = 7 - progress.set_pass('',total) - self.db.rebuild_secondary(progress.step) - progress.close() - OkDialog(_("Secondary indices rebuilt"), - _('All secondary indices have been rebuilt.')) + self.callback = uistate.pulse_progressbar + uistate.set_busy_cursor(1) + uistate.progress.show() + uistate.push_message(dbstate, _("Rebuilding secondary indices...")) else: print "Rebuilding Secondary Indices..." self.db.rebuild_secondary(self.empty) print "All secondary indices have been rebuilt." - self.db.enable_signals() - def empty(self): - pass + UpdateCallback.__init__(self,self.callback) + self.set_total(11) + self.db.rebuild_secondary(self.update) + self.reset() + + if uistate: + uistate.set_busy_cursor(0) + uistate.progress.hide() + OkDialog(_("Secondary indices rebuilt"), + _('All secondary indices have been rebuilt.')) + else: + print "All secondary indices have been rebuilt." + self.db.enable_signals() #------------------------------------------------------------------------ # diff --git a/gramps2/src/plugins/RebuildRefMap.py b/gramps2/src/plugins/RebuildRefMap.py index 7f9f15ef9..1ff10801c 100644 --- a/gramps2/src/plugins/RebuildRefMap.py +++ b/gramps2/src/plugins/RebuildRefMap.py @@ -55,17 +55,17 @@ import gtk.glade # #------------------------------------------------------------------------- import RelLib -import Utils import const from PluginUtils import Tool, register_tool from QuestionDialog import OkDialog +from BasicUtils import UpdateCallback #------------------------------------------------------------------------- # # runTool # #------------------------------------------------------------------------- -class RebuildRefMap(Tool.Tool): +class RebuildRefMap(Tool.Tool,UpdateCallback): def __init__(self, dbstate, uistate, options_class, name, callback=None): @@ -76,12 +76,25 @@ class RebuildRefMap(Tool.Tool): self.db.disable_signals() if uistate: - self.db.reindex_reference_map() + self.callback = uistate.pulse_progressbar + uistate.set_busy_cursor(1) + uistate.progress.show() + uistate.push_message(dbstate, _("Rebuilding reference maps...")) + else: + self.callback = None + print "Rebuilding reference maps..." + + UpdateCallback.__init__(self,self.callback) + self.set_total(6) + self.db.reindex_reference_map(self.update) + self.reset() + + if uistate: + uistate.set_busy_cursor(0) + uistate.progress.hide() OkDialog(_("Reference maps rebuilt"), _('All reference maps have been rebuilt.')) else: - print "Rebuilding reference maps..." - self.db.reindex_reference_map() print "All reference maps have been rebuilt." self.db.enable_signals()