6953: remove "undo history warning" under CLI

Port my fix from gramps34.
In addition, the Check tool now has a hardwired dependency
on ProgressMeter. Make a nullifying mock locally and
only set it to the real thing only under GUI.

Tested with impex.sh (further stages after check still fail,
see bug #6878).

svn: r22899
This commit is contained in:
Vassilii Khachaturov 2013-08-21 17:24:41 +00:00
parent 949c41107a
commit f92f5d08bf
11 changed files with 50 additions and 39 deletions

View File

@ -1038,7 +1038,7 @@ class ToolManagedWindowBatch(tool.BatchTool, ToolManagedWindowBase):
# This constructor will ask a question, set self.fail:
self.dbstate = dbstate
self.uistate = uistate
tool.BatchTool.__init__(self, dbstate, options_class, name)
tool.BatchTool.__init__(self, dbstate, uistate, options_class, name)
if not self.fail:
ToolManagedWindowBase.__init__(self, dbstate, uistate,
options_class, name, callback)

View File

@ -101,25 +101,26 @@ class Tool(object):
class BatchTool(Tool):
"""
Same as Tool, except the warning is displayed about the potential
loss of undo history. Should be used for tools using batch transactions.
loss of undo history when GUI is available.
Should be used for tools using batch transactions.
"""
def __init__(self, dbstate, options_class, name):
# TODO: should we replace this with a callback?
from ..dialog import QuestionDialog2
warn_dialog = QuestionDialog2(
_('Undo history warning'),
_('Proceeding with this tool will erase the undo history '
'for this session. In particular, you will not be able '
'to revert the changes made by this tool or any changes '
'made prior to it.\n\n'
'If you think you may want to revert running this tool, '
'please stop here and backup your database.'),
_('_Proceed with the tool'), _('_Stop'))
if not warn_dialog.run():
self.fail = True
return
def __init__(self, dbstate, uistate, options_class, name):
if uistate:
# TODO: should we replace this with a callback?
from ..dialog import QuestionDialog2
warn_dialog = QuestionDialog2(
_('Undo history warning'),
_('Proceeding with this tool will erase the undo history '
'for this session. In particular, you will not be able '
'to revert the changes made by this tool or any changes '
'made prior to it.\n\n'
'If you think you may want to revert running this tool, '
'please stop here and backup your database.'),
_('_Proceed with the tool'), _('_Stop'))
if not warn_dialog.run():
self.fail = True
return
Tool.__init__(self, dbstate, options_class, name)
self.fail = False

View File

@ -79,7 +79,7 @@ class ChangeNames(tool.BatchTool, ManagedWindow):
ManagedWindow.__init__(self,uistate,[],self.__class__)
self.set_window(Gtk.Window(),Gtk.Label(),'')
tool.BatchTool.__init__(self, dbstate, options_class, name)
tool.BatchTool.__init__(self, dbstate, uistate, options_class, name)
if self.fail:
return

View File

@ -56,7 +56,7 @@ class ChangeTypes(tool.BatchTool, ManagedWindow):
def __init__(self, dbstate, uistate, options_class, name, callback=None):
tool.BatchTool.__init__(self, dbstate, options_class, name)
tool.BatchTool.__init__(self, dbstate, uistate, options_class, name)
if self.fail:
return

View File

@ -70,7 +70,6 @@ from gramps.gen.utils.db import family_name
from gramps.gen.utils.unknown import make_unknown
from gramps.gen.utils.file import (media_path_full, find_file, fix_encoding,
get_unicode_path_from_file_chooser)
from gramps.gui.utils import ProgressMeter
from gramps.gui.managedwindow import ManagedWindow
from gramps.gui.plug import tool
@ -86,6 +85,12 @@ ngettext = glocale.translation.ngettext
# All except 09, 0A, 0D are replaced with space.
strip_dict = dict.fromkeys(list(range(9))+list(range(11,13))+list(range(14, 32)), " ")
class ProgressMeter(object):
def __init__(self, *args): pass
def set_pass(self, *args): pass
def step(self): pass
def close(self): pass
#-------------------------------------------------------------------------
#
# Low Level repair
@ -132,11 +137,15 @@ def cross_table_duplicates(db):
class Check(tool.BatchTool):
def __init__(self, dbstate, uistate, options_class, name, callback=None):
tool.BatchTool.__init__(self, dbstate, options_class, name)
tool.BatchTool.__init__(self, dbstate, uistate, options_class, name)
if self.fail:
return
cli = uistate is None
if uistate:
from gramps.gui.utils import ProgressMeter as PM
global ProgressMeter
ProgressMeter = PM
if self.db.readonly:
# TODO: split plugin in a check and repair part to support
@ -2242,20 +2251,21 @@ class Report(ManagedWindow):
if cl:
print (text)
ManagedWindow.__init__(self, uistate, [], self)
if uistate:
ManagedWindow.__init__(self, uistate, [], self)
topDialog = Glade()
topDialog.get_object("close").connect('clicked', self.close)
window = topDialog.toplevel
textwindow = topDialog.get_object("textwindow")
textwindow.get_buffer().set_text(text)
topDialog = Glade()
topDialog.get_object("close").connect('clicked', self.close)
window = topDialog.toplevel
textwindow = topDialog.get_object("textwindow")
textwindow.get_buffer().set_text(text)
self.set_window(window,
#topDialog.get_widget("title"),
topDialog.get_object("title"),
_("Integrity Check Results"))
self.set_window(window,
#topDialog.get_widget("title"),
topDialog.get_object("title"),
_("Integrity Check Results"))
self.show()
self.show()
def build_menu_names(self, obj):
return (_('Check and Repair'), None)

View File

@ -69,7 +69,7 @@ class EventNames(tool.BatchTool, ManagedWindow):
"""
def __init__(self, dbstate, uistate, options_class, name, callback=None):
tool.BatchTool.__init__(self, dbstate, options_class, name)
tool.BatchTool.__init__(self, dbstate, uistate, options_class, name)
if not self.fail:
uistate.set_busy_cursor(True)

View File

@ -419,7 +419,7 @@ class ExtractCity(tool.BatchTool, ManagedWindow):
ManagedWindow.__init__(self, uistate, [], self.__class__)
self.set_window(Gtk.Window(), Gtk.Label(), '')
tool.BatchTool.__init__(self, dbstate, options_class, name)
tool.BatchTool.__init__(self, dbstate, uistate, options_class, name)
if not self.fail:
uistate.set_busy_cursor(True)

View File

@ -97,7 +97,7 @@ class MergeCitations(tool.BatchTool,ManagedWindow):
self.dbstate = dbstate
self.set_window(Gtk.Window(), Gtk.Label(), '')
tool.BatchTool.__init__(self, dbstate, options_class, name)
tool.BatchTool.__init__(self, dbstate, uistate, options_class, name)
if not self.fail:
uistate.set_busy_cursor(True)

View File

@ -108,7 +108,7 @@ class PatchNames(tool.BatchTool, ManagedWindow):
ManagedWindow.__init__(self, uistate, [], self.__class__)
self.set_window(Gtk.Window(), Gtk.Label(), '')
tool.BatchTool.__init__(self, dbstate, options_class, name)
tool.BatchTool.__init__(self, dbstate, uistate, options_class, name)
if self.fail:
return

View File

@ -60,7 +60,7 @@ _parseformat = re.compile('.*%(\d+)[^\d]+')
#-------------------------------------------------------------------------
class ReorderIds(tool.BatchTool):
def __init__(self, dbstate, uistate, options_class, name, callback=None):
tool.BatchTool.__init__(self, dbstate, options_class, name)
tool.BatchTool.__init__(self, dbstate, uistate, options_class, name)
if self.fail:
return

View File

@ -115,7 +115,7 @@ class TestcaseGenerator(tool.BatchTool):
if dbstate.db.readonly:
return
tool.BatchTool.__init__(self, dbstate, options_class, name)
tool.BatchTool.__init__(self, dbstate, uistate, options_class, name)
if self.fail:
return