5598: implement User() class for tools
change BatchTool to take user instead of uistate BatchTool now uses user.prompt, properly prompting the user in CLI scenario as well, unless "--yes" flag is given svn: r23071
This commit is contained in:
parent
a4ae95f260
commit
be8c13ef4f
@ -1051,7 +1051,7 @@ class ToolManagedWindowBatch(tool.BatchTool, ToolManagedWindowBase):
|
|||||||
# This constructor will ask a question, set self.fail:
|
# This constructor will ask a question, set self.fail:
|
||||||
self.dbstate = dbstate
|
self.dbstate = dbstate
|
||||||
self.uistate = uistate
|
self.uistate = uistate
|
||||||
tool.BatchTool.__init__(self, dbstate, uistate, options_class, name)
|
tool.BatchTool.__init__(self, dbstate, user, options_class, name)
|
||||||
if not self.fail:
|
if not self.fail:
|
||||||
ToolManagedWindowBase.__init__(self, dbstate, uistate,
|
ToolManagedWindowBase.__init__(self, dbstate, uistate,
|
||||||
options_class, name, callback)
|
options_class, name, callback)
|
||||||
|
@ -100,16 +100,13 @@ class Tool(object):
|
|||||||
|
|
||||||
class BatchTool(Tool):
|
class BatchTool(Tool):
|
||||||
"""
|
"""
|
||||||
Same as Tool, except the warning is displayed about the potential
|
Same as Tool, except the warning is given about the potential
|
||||||
loss of undo history when GUI is available.
|
loss of undo history.
|
||||||
Should be used for tools using batch transactions.
|
Should be used for tools using batch transactions.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, dbstate, uistate, options_class, name):
|
def __init__(self, dbstate, user, options_class, name):
|
||||||
if uistate:
|
if not user.prompt(
|
||||||
# TODO: should we replace this with a callback?
|
|
||||||
from ..dialog import QuestionDialog2
|
|
||||||
warn_dialog = QuestionDialog2(
|
|
||||||
_('Undo history warning'),
|
_('Undo history warning'),
|
||||||
_('Proceeding with this tool will erase the undo history '
|
_('Proceeding with this tool will erase the undo history '
|
||||||
'for this session. In particular, you will not be able '
|
'for this session. In particular, you will not be able '
|
||||||
@ -117,8 +114,7 @@ class BatchTool(Tool):
|
|||||||
'made prior to it.\n\n'
|
'made prior to it.\n\n'
|
||||||
'If you think you may want to revert running this tool, '
|
'If you think you may want to revert running this tool, '
|
||||||
'please stop here and backup your database.'),
|
'please stop here and backup your database.'),
|
||||||
_('_Proceed with the tool'), _('_Stop'))
|
_('_Proceed with the tool'), _('_Stop')):
|
||||||
if not warn_dialog.run():
|
|
||||||
self.fail = True
|
self.fail = True
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ class ChangeNames(tool.BatchTool, ManagedWindow):
|
|||||||
ManagedWindow.__init__(self,uistate,[],self.__class__)
|
ManagedWindow.__init__(self,uistate,[],self.__class__)
|
||||||
self.set_window(Gtk.Window(),Gtk.Label(),'')
|
self.set_window(Gtk.Window(),Gtk.Label(),'')
|
||||||
|
|
||||||
tool.BatchTool.__init__(self, dbstate, uistate, options_class, name)
|
tool.BatchTool.__init__(self, dbstate, user, options_class, name)
|
||||||
if self.fail:
|
if self.fail:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ class ChangeTypes(tool.BatchTool, ManagedWindow):
|
|||||||
def __init__(self, dbstate, user, options_class, name, callback=None):
|
def __init__(self, dbstate, user, options_class, name, callback=None):
|
||||||
uistate = user.uistate
|
uistate = user.uistate
|
||||||
|
|
||||||
tool.BatchTool.__init__(self, dbstate, uistate, options_class, name)
|
tool.BatchTool.__init__(self, dbstate, user, options_class, name)
|
||||||
if self.fail:
|
if self.fail:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ class Check(tool.BatchTool):
|
|||||||
def __init__(self, dbstate, user, options_class, name, callback=None):
|
def __init__(self, dbstate, user, options_class, name, callback=None):
|
||||||
uistate = user.uistate
|
uistate = user.uistate
|
||||||
|
|
||||||
tool.BatchTool.__init__(self, dbstate, uistate, options_class, name)
|
tool.BatchTool.__init__(self, dbstate, user, options_class, name)
|
||||||
if self.fail:
|
if self.fail:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ class EventNames(tool.BatchTool, ManagedWindow):
|
|||||||
|
|
||||||
def __init__(self, dbstate, user, options_class, name, callback=None):
|
def __init__(self, dbstate, user, options_class, name, callback=None):
|
||||||
uistate = user.uistate
|
uistate = user.uistate
|
||||||
tool.BatchTool.__init__(self, dbstate, uistate, options_class, name)
|
tool.BatchTool.__init__(self, dbstate, user, options_class, name)
|
||||||
|
|
||||||
if not self.fail:
|
if not self.fail:
|
||||||
uistate.set_busy_cursor(True)
|
uistate.set_busy_cursor(True)
|
||||||
|
@ -420,7 +420,7 @@ class ExtractCity(tool.BatchTool, ManagedWindow):
|
|||||||
ManagedWindow.__init__(self, uistate, [], self.__class__)
|
ManagedWindow.__init__(self, uistate, [], self.__class__)
|
||||||
self.set_window(Gtk.Window(), Gtk.Label(), '')
|
self.set_window(Gtk.Window(), Gtk.Label(), '')
|
||||||
|
|
||||||
tool.BatchTool.__init__(self, dbstate, uistate, options_class, name)
|
tool.BatchTool.__init__(self, dbstate, user, options_class, name)
|
||||||
|
|
||||||
if not self.fail:
|
if not self.fail:
|
||||||
uistate.set_busy_cursor(True)
|
uistate.set_busy_cursor(True)
|
||||||
|
@ -99,7 +99,7 @@ class MergeCitations(tool.BatchTool,ManagedWindow):
|
|||||||
self.dbstate = dbstate
|
self.dbstate = dbstate
|
||||||
self.set_window(Gtk.Window(), Gtk.Label(), '')
|
self.set_window(Gtk.Window(), Gtk.Label(), '')
|
||||||
|
|
||||||
tool.BatchTool.__init__(self, dbstate, uistate, options_class, name)
|
tool.BatchTool.__init__(self, dbstate, user, options_class, name)
|
||||||
|
|
||||||
if not self.fail:
|
if not self.fail:
|
||||||
uistate.set_busy_cursor(True)
|
uistate.set_busy_cursor(True)
|
||||||
|
@ -109,7 +109,7 @@ class PatchNames(tool.BatchTool, ManagedWindow):
|
|||||||
ManagedWindow.__init__(self, uistate, [], self.__class__)
|
ManagedWindow.__init__(self, uistate, [], self.__class__)
|
||||||
self.set_window(Gtk.Window(), Gtk.Label(), '')
|
self.set_window(Gtk.Window(), Gtk.Label(), '')
|
||||||
|
|
||||||
tool.BatchTool.__init__(self, dbstate, uistate, options_class, name)
|
tool.BatchTool.__init__(self, dbstate, user, options_class, name)
|
||||||
if self.fail:
|
if self.fail:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ _parseformat = re.compile('.*%(\d+)[^\d]+')
|
|||||||
class ReorderIds(tool.BatchTool):
|
class ReorderIds(tool.BatchTool):
|
||||||
def __init__(self, dbstate, user, options_class, name, callback=None):
|
def __init__(self, dbstate, user, options_class, name, callback=None):
|
||||||
uistate = user.uistate
|
uistate = user.uistate
|
||||||
tool.BatchTool.__init__(self, dbstate, uistate, options_class, name)
|
tool.BatchTool.__init__(self, dbstate, user, options_class, name)
|
||||||
if self.fail:
|
if self.fail:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ class TestcaseGenerator(tool.BatchTool):
|
|||||||
if dbstate.db.readonly:
|
if dbstate.db.readonly:
|
||||||
return
|
return
|
||||||
|
|
||||||
tool.BatchTool.__init__(self, dbstate, uistate, options_class, name)
|
tool.BatchTool.__init__(self, dbstate, user, options_class, name)
|
||||||
|
|
||||||
if self.fail:
|
if self.fail:
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user