* src/plugins/RemoveUnused.py: remove unused sources and events, and UI

svn: r7560
This commit is contained in:
Don Allingham 2006-11-06 04:23:10 +00:00
parent d5fea06ce3
commit cf4dae1779
2 changed files with 85 additions and 16 deletions

View File

@ -3,7 +3,7 @@
2006-11-05 Don Allingham <don@gramps-project.org>
* src/plugins/Makefile.am: add RemoveUnused.py
* src/plugins/RemoveUnused.py: remove unused sources and events
* src/plugins/RemoveUnused.py: remove unused sources and events, and UI
* src/DataViews/_PersonView.py: provide a default surname for and Add
Person button press based of selected item in the Person View tree.
* help/C/various: remove unused files from manual

View File

@ -66,33 +66,73 @@ from QuestionDialog import OkDialog, MissingMediaDialog
# runTool
#
#-------------------------------------------------------------------------
class RemoveUnused(Tool.BatchTool):
class RemoveUnused:
def __init__(self, dbstate, uistate, options_class, name, callback=None):
Tool.BatchTool.__init__(self, dbstate, options_class, name)
if self.fail:
return
cli = uistate == None
self.db = dbstate.db
self.dbstate = dbstate
self.uistate = uistate
if self.db.readonly:
# TODO: split plugin in a check and repair part to support
# checking of a read only database
return
if uistate:
self.init_gui()
else:
self.run_tool(cli=True)
def init_gui(self):
a = gtk.Dialog("%s - GRAMPS" % _('Remove unused objects'),
flags=gtk.DIALOG_MODAL,
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
a.set_size_request(400, 200)
a.set_border_width(12)
a.set_has_separator(False)
self.event = gtk.CheckButton(_('Remove unused events'))
self.source = gtk.CheckButton(_('Remove unused sources'))
self.place = gtk.CheckButton(_('Remove unused places'))
self.event.set_active(True)
self.source.set_active(True)
self.place.set_active(True)
label = gtk.Label('<span size="larger" weight="bold">%s</span>' % _('Remove unused objects'))
label.set_use_markup(True)
a.vbox.add(label)
a.vbox.add(self.event)
a.vbox.add(self.source)
a.vbox.add(self.place)
a.vbox.show_all()
result = a.run()
a.destroy()
if result == gtk.RESPONSE_ACCEPT:
self.run_tool(self.event.get_active(),
self.source.get_active(),
self.place.get_active())
def run_tool(self, clean_events, clean_sources, clean_places):
trans = self.db.transaction_begin("",batch=True)
self.db.disable_signals()
checker = CheckIntegrity(dbstate, uistate, trans)
checker.cleanup_events()
checker.cleanup_sources()
checker = CheckIntegrity(self.dbstate, self.uistate, trans)
if clean_events:
checker.cleanup_events()
if clean_sources:
checker.cleanup_sources()
if clean_places:
checker.cleanup_places()
self.db.transaction_commit(trans, _("Remove unused objects"))
self.db.enable_signals()
self.db.request_rebuild()
errs = checker.build_report(cli)
errs = checker.build_report()
if errs:
Report(uistate, checker.text.getvalue(),cli)
Report(uistate, checker.text.getvalue())
#-------------------------------------------------------------------------
#
@ -128,6 +168,17 @@ class CheckIntegrity:
self.db.remove_event(handle)
self.source_cnt += 1
def cleanup_places(self):
self.progress.set_pass(_('Removing unused places'),
self.db.get_number_of_places())
self.source_cnt = 0
for handle in self.db.place_map.keys():
event = self.db.get_place_from_handle(handle)
if not self.db.find_backlink_handles(handle):
self.db.remove_place(handle)
self.source_cnt += 1
def build_report(self,cl=0):
self.progress.close()
@ -201,6 +252,24 @@ class CheckOptions(Tool.ToolOptions):
def __init__(self,name,person_id=None):
Tool.ToolOptions.__init__(self,name,person_id)
def set_new_options(self):
self.options_dict = {
'rm_src' : 1,
'rm_event' : 1,
'rm_place' : 1,
}
self.options_help = {
'rm_src' : ("=0/1","Whether to remove unused sources",
["Do not remove unused sources","Remove unused sources"],
True),
'rm_event' : ("=0/1","Whether to remove unused events",
["Do not remove unused events","Remove unused events"],
True),
'rm_place' : ("=0/1","Whether to remove unused places",
["Do not remove unused places","Remove unused places"],
True),
}
#------------------------------------------------------------------------
#
#
@ -211,7 +280,7 @@ register_tool(
category = Tool.TOOL_DBFIX,
tool_class = RemoveUnused,
options_class = CheckOptions,
modes = Tool.MODE_GUI | Tool.MODE_CLI,
modes = Tool.MODE_GUI,
translated_name = _("Remove unused objects"),
status = _("Stable"),
author_name = "Donald N. Allingham",