5598: implement User() class for tools

Refactoring in progress:
Modified all the tools' classes' call signature:
now all take a user argument instead of a uistate, and
GUI and CLI signature is unified.

All tools now begin with uistate = user.uistate

svn: r23061
This commit is contained in:
Vassilii Khachaturov 2013-09-08 21:43:12 +00:00
parent 8bdb301958
commit 5c9751f3b9
34 changed files with 70 additions and 37 deletions

View File

@ -652,7 +652,8 @@ class ArgHandler(object):
category=category, category=category,
tool_class=tool_class, tool_class=tool_class,
options_class=options_class, options_class=options_class,
options_str_dict=options_str_dict) options_str_dict=options_str_dict,
user=self.user)
return return
msg = _("Unknown tool name.") msg = _("Unknown tool name.")
else: else:

View File

@ -339,8 +339,7 @@ def startcli(errors, argparser):
#we need a manager for the CLI session #we need a manager for the CLI session
from .user import User from .user import User
user=User(error=self.__error, user=User(auto_accept=argparser.auto_accept,
auto_accept=argparser.auto_accept,
quiet=argparser.quiet) quiet=argparser.quiet)
climanager = CLIManager(dbstate, setloader=True, user=user) climanager = CLIManager(dbstate, setloader=True, user=user)

View File

@ -36,6 +36,7 @@ class User():
self.callback_function = callback self.callback_function = callback
self.error_function = error self.error_function = error
self._fileout = sys.stderr # redirected to mocks by unit tests self._fileout = sys.stderr # redirected to mocks by unit tests
self.uistate = None
def begin_progress(self, title, message, steps): def begin_progress(self, title, message, steps):
""" """

View File

@ -248,9 +248,10 @@ class PluginDialog(ManagedWindow):
pdata.name, pdata.id, pdata.name, pdata.id,
pdata.category, pdata.require_active) pdata.category, pdata.require_active)
else: else:
from ..user import User
tool.gui_tool( tool.gui_tool(
dbstate = self.state, dbstate = self.state,
uistate = self.uistate, user = User(uistate=self.uistate),
tool_class = eval('mod.' + pdata.toolclass), tool_class = eval('mod.' + pdata.toolclass),
options_class = eval('mod.' + pdata.optionclass), options_class = eval('mod.' + pdata.optionclass),
translated_name = pdata.name, translated_name = pdata.name,

View File

@ -1046,7 +1046,8 @@ class ToolManagedWindowBase(ManagedWindow):
class ToolManagedWindowBatch(tool.BatchTool, ToolManagedWindowBase): class ToolManagedWindowBatch(tool.BatchTool, ToolManagedWindowBase):
def __init__(self, dbstate, uistate, options_class, name, callback=None): def __init__(self, dbstate, user, options_class, name, callback=None):
uistate = user.uistate
# 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

View File

@ -244,7 +244,7 @@ class CommandLineTool(object):
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# Standard GUI tool generic task # Standard GUI tool generic task
def gui_tool(dbstate, uistate, tool_class, options_class, translated_name, def gui_tool(dbstate, user, tool_class, options_class, translated_name,
name, category, callback): name, category, callback):
""" """
tool - task starts the report. The plugin system requires that the tool - task starts the report. The plugin system requires that the
@ -253,7 +253,7 @@ def gui_tool(dbstate, uistate, tool_class, options_class, translated_name,
""" """
try: try:
tool_class(dbstate = dbstate, uistate = uistate, tool_class(dbstate = dbstate, user = user,
options_class = options_class, name = name, options_class = options_class, name = name,
callback = callback) callback = callback)
except WindowActiveError: except WindowActiveError:
@ -262,7 +262,7 @@ def gui_tool(dbstate, uistate, tool_class, options_class, translated_name,
log.error("Failed to start tool.", exc_info=True) log.error("Failed to start tool.", exc_info=True)
# Command-line generic task # Command-line generic task
def cli_tool(dbstate, name, category, tool_class, options_class, options_str_dict): def cli_tool(dbstate, name, category, tool_class, options_class, options_str_dict, user = None):
clt = CommandLineTool(dbstate.db, name, category, clt = CommandLineTool(dbstate.db, name, category,
options_class, options_str_dict) options_class, options_str_dict)
@ -272,9 +272,12 @@ def cli_tool(dbstate, name, category, tool_class, options_class, options_str_dic
if clt.show: if clt.show:
return return
if user is None:
from ...cli.user import User
user = User()
# run tool # run tool
try: try:
tool_class(dbstate = dbstate, uistate = None, tool_class(dbstate = dbstate, user = user,
options_class = clt.option_class, name = name, callback = None) options_class = clt.option_class, name = name, callback = None)
except: except:
log.error("Failed to start tool.", exc_info=True) log.error("Failed to start tool.", exc_info=True)

View File

@ -1626,7 +1626,7 @@ def run_plugin(pdata, dbstate, uistate):
pdata.category, pdata.require_active, pdata.category, pdata.require_active,
) )
else: else:
tool.gui_tool(dbstate = dbstate, uistate = uistate, tool.gui_tool(dbstate = dbstate, user = User(uistate = uistate),
tool_class = getattr(mod, pdata.toolclass), tool_class = getattr(mod, pdata.toolclass),
options_class = getattr(mod, pdata.optionclass), options_class = getattr(mod, pdata.optionclass),
translated_name = pdata.name, translated_name = pdata.name,

View File

@ -72,7 +72,8 @@ WIKI_HELP_SEC = _('manual|Fix_Capitalization_of_Family_Names...')
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class ChangeNames(tool.BatchTool, ManagedWindow): class ChangeNames(tool.BatchTool, ManagedWindow):
def __init__(self, dbstate, uistate, options_class, name, callback=None): def __init__(self, dbstate, user, options_class, name, callback=None):
uistate = user.uistate
self.label = _('Capitalization changes') self.label = _('Capitalization changes')
self.cb = callback self.cb = callback

View File

@ -54,7 +54,8 @@ from gramps.gui.glade import Glade
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class ChangeTypes(tool.BatchTool, ManagedWindow): class ChangeTypes(tool.BatchTool, ManagedWindow):
def __init__(self, dbstate, uistate, options_class, name, callback=None): def __init__(self, dbstate, user, options_class, name, callback=None):
uistate = user.uistate
tool.BatchTool.__init__(self, dbstate, uistate, options_class, name) tool.BatchTool.__init__(self, dbstate, uistate, options_class, name)
if self.fail: if self.fail:

View File

@ -135,7 +135,8 @@ def cross_table_duplicates(db):
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class Check(tool.BatchTool): class Check(tool.BatchTool):
def __init__(self, dbstate, uistate, options_class, name, callback=None): def __init__(self, dbstate, user, options_class, name, callback=None):
uistate = user.uistate
tool.BatchTool.__init__(self, dbstate, uistate, options_class, name) tool.BatchTool.__init__(self, dbstate, uistate, options_class, name)
if self.fail: if self.fail:

View File

@ -59,7 +59,8 @@ from gramps.gen.datehandler import displayer as _dd
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class DateParserDisplayTest(tool.Tool): class DateParserDisplayTest(tool.Tool):
def __init__(self, dbstate, uistate, options_class, name, callback=None): def __init__(self, dbstate, user, options_class, name, callback=None):
uistate = user.uistate
tool.Tool.__init__(self, dbstate, options_class, name) tool.Tool.__init__(self, dbstate, options_class, name)
if uistate: if uistate:

View File

@ -57,7 +57,8 @@ WIKI_HELP_SEC = _('manual|Interactive_Descendant_Browser...')
class DesBrowse(tool.ActivePersonTool, ManagedWindow): class DesBrowse(tool.ActivePersonTool, ManagedWindow):
def __init__(self, dbstate, uistate, options_class, name, callback=None): def __init__(self, dbstate, user, options_class, name, callback=None):
uistate = user.uistate
tool.ActivePersonTool.__init__(self, dbstate, uistate, options_class, tool.ActivePersonTool.__init__(self, dbstate, uistate, options_class,
name) name)

View File

@ -45,7 +45,8 @@ _GENDER = [ _('female'), _('male'), _('unknown') ]
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class DumpGenderStats(tool.Tool, ManagedWindow): class DumpGenderStats(tool.Tool, ManagedWindow):
def __init__(self, dbstate, uistate, options_class, name, callback=None): def __init__(self, dbstate, user, options_class, name, callback=None):
uistate = user.uistate
self.label = _("Gender Statistics tool") self.label = _("Gender Statistics tool")
tool.Tool.__init__(self, dbstate, options_class, name) tool.Tool.__init__(self, dbstate, options_class, name)
if uistate: if uistate:

View File

@ -55,7 +55,8 @@ from gramps.gen.constfunc import cuni
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class Eval(tool.Tool,ManagedWindow): class Eval(tool.Tool,ManagedWindow):
def __init__(self,dbstate, uistate, options_class, name, callback=None): def __init__(self,dbstate, user, options_class, name, callback=None):
uistate = user.uistate
self.title = _("Python evaluation window") self.title = _("Python evaluation window")
tool.Tool.__init__(self,dbstate, options_class, name) tool.Tool.__init__(self,dbstate, options_class, name)

View File

@ -117,7 +117,8 @@ class TableReport(object):
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
class EventComparison(tool.Tool,ManagedWindow): class EventComparison(tool.Tool,ManagedWindow):
def __init__(self, dbstate, uistate, options_class, name, callback=None): def __init__(self, dbstate, user, options_class, name, callback=None):
uistate = user.uistate
self.dbstate = dbstate self.dbstate = dbstate
self.uistate = uistate self.uistate = uistate

View File

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

View File

@ -413,7 +413,8 @@ class ExtractCity(tool.BatchTool, ManagedWindow):
or Paris, ILE DE FRANCE 75000, FRA or Paris, ILE DE FRANCE 75000, FRA
""" """
def __init__(self, dbstate, uistate, options_class, name, callback=None): def __init__(self, dbstate, user, options_class, name, callback=None):
uistate = user.uistate
self.label = _('Extract Place data') self.label = _('Extract Place data')
ManagedWindow.__init__(self, uistate, [], self.__class__) ManagedWindow.__init__(self, uistate, [], self.__class__)

View File

@ -88,7 +88,8 @@ def is_initial(name):
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class Merge(tool.Tool,ManagedWindow): class Merge(tool.Tool,ManagedWindow):
def __init__(self, dbstate, uistate, options_class, name, callback=None): def __init__(self, dbstate, user, options_class, name, callback=None):
uistate = user.uistate
tool.Tool.__init__(self, dbstate, options_class, name) tool.Tool.__init__(self, dbstate, options_class, name)
ManagedWindow.__init__(self, uistate, [], ManagedWindow.__init__(self, uistate, [],

View File

@ -67,7 +67,8 @@ from gramps.gui.utils import is_right_click
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class Leak(tool.Tool, ManagedWindow): class Leak(tool.Tool, ManagedWindow):
def __init__(self,dbstate, uistate, options_class, name, callback=None): def __init__(self,dbstate, user, options_class, name, callback=None):
uistate = user.uistate
self.title = _('Uncollected Objects Tool') self.title = _('Uncollected Objects Tool')
tool.Tool.__init__(self,dbstate, options_class, name) tool.Tool.__init__(self,dbstate, options_class, name)

View File

@ -78,7 +78,8 @@ WIKI_HELP_SEC = _('manual|Media_Manager...')
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class MediaMan(tool.Tool): class MediaMan(tool.Tool):
def __init__(self, dbstate, uistate, options_class, name, callback=None): def __init__(self, dbstate, user, options_class, name, callback=None):
uistate = user.uistate
tool.Tool.__init__(self, dbstate, options_class, name) tool.Tool.__init__(self, dbstate, options_class, name)
self.uistate = uistate self.uistate = uistate

View File

@ -92,7 +92,8 @@ WIKI_HELP_SEC = _('manual|Merge citations...')
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class MergeCitations(tool.BatchTool,ManagedWindow): class MergeCitations(tool.BatchTool,ManagedWindow):
def __init__(self, dbstate, uistate, options_class, name, callback=None): def __init__(self, dbstate, user, options_class, name, callback=None):
uistate = user.uistate
ManagedWindow.__init__(self, uistate, [], self.__class__) ManagedWindow.__init__(self, uistate, [], self.__class__)
self.dbstate = dbstate self.dbstate = dbstate

View File

@ -68,7 +68,8 @@ WIKI_HELP_SEC = _('manual|Not_Related...')
#------------------------------------------------------------------------ #------------------------------------------------------------------------
class NotRelated(tool.ActivePersonTool, ManagedWindow) : class NotRelated(tool.ActivePersonTool, ManagedWindow) :
def __init__(self, dbstate, uistate, options_class, name, callback=None): def __init__(self, dbstate, user, options_class, name, callback=None):
uistate = user.uistate
tool.ActivePersonTool.__init__(self, dbstate, uistate, options_class, tool.ActivePersonTool.__init__(self, dbstate, uistate, options_class,
name) name)

View File

@ -86,7 +86,8 @@ class OwnerEditor(tool.Tool, ManagedWindow):
Provides a possibility to direcly verify and edit the owner data of the Provides a possibility to direcly verify and edit the owner data of the
current database. It also allows copying data from/to the preferences. current database. It also allows copying data from/to the preferences.
""" """
def __init__(self, dbstate, uistate, options_class, name, callback=None): def __init__(self, dbstate, user, options_class, name, callback=None):
uistate = user.uistate
ManagedWindow.__init__(self, uistate, [], self.__class__) ManagedWindow.__init__(self, uistate, [], self.__class__)
tool.Tool.__init__(self, dbstate, options_class, name) tool.Tool.__init__(self, dbstate, options_class, name)

View File

@ -103,7 +103,8 @@ class PatchNames(tool.BatchTool, ManagedWindow):
pref1id = 3 pref1id = 3
compid = 4 compid = 4
def __init__(self, dbstate, uistate, options_class, name, callback=None): def __init__(self, dbstate, user, options_class, name, callback=None):
uistate = user.uistate
self.label = _('Name and title extraction tool') self.label = _('Name and title extraction tool')
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(), '')

View File

@ -54,7 +54,8 @@ class PopulateSources(tool.Tool, ManagedWindow):
Gramplet that populates the database with sources and citations. Gramplet that populates the database with sources and citations.
""" """
def __init__(self, dbstate, uistate, options_class, name, callback=None): def __init__(self, dbstate, user, options_class, name, callback=None):
uistate = user.uistate
self.label = 'Populate sources and citations tool' self.label = 'Populate sources and citations tool'
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(), '')

View File

@ -64,7 +64,8 @@ from gramps.gen.updatecallback import UpdateCallback
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class Rebuild(tool.Tool, UpdateCallback): class Rebuild(tool.Tool, UpdateCallback):
def __init__(self, dbstate, uistate, options_class, name, callback=None): def __init__(self, dbstate, user, options_class, name, callback=None):
uistate = user.uistate
tool.Tool.__init__(self, dbstate, options_class, name) tool.Tool.__init__(self, dbstate, options_class, name)

View File

@ -70,7 +70,8 @@ COLUMN_ALTNAMES = 4
class RebuildGenderStat(tool.Tool, UpdateCallback): class RebuildGenderStat(tool.Tool, UpdateCallback):
def __init__(self, dbstate, uistate, options_class, name, callback=None): def __init__(self, dbstate, user, options_class, name, callback=None):
uistate = user.uistate
tool.Tool.__init__(self, dbstate, options_class, name) tool.Tool.__init__(self, dbstate, options_class, name)

View File

@ -66,7 +66,8 @@ from gramps.gen.updatecallback import UpdateCallback
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class RebuildRefMap(tool.Tool, UpdateCallback): class RebuildRefMap(tool.Tool, UpdateCallback):
def __init__(self, dbstate, uistate, options_class, name, callback=None): def __init__(self, dbstate, user, options_class, name, callback=None):
uistate = user.uistate
tool.Tool.__init__(self, dbstate, options_class, name) tool.Tool.__init__(self, dbstate, options_class, name)

View File

@ -71,7 +71,8 @@ column_names = [column[0] for column in BasePersonView.COLUMNS]
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class RelCalc(tool.Tool, ManagedWindow): class RelCalc(tool.Tool, ManagedWindow):
def __init__(self, dbstate, uistate, options_class, name, callback=None): def __init__(self, dbstate, user, options_class, name, callback=None):
uistate = user.uistate
""" """
Relationship calculator class. Relationship calculator class.
""" """

View File

@ -77,7 +77,8 @@ class RemoveUnused(tool.Tool, ManagedWindow, UpdateCallback):
OBJ_TYPE_COL = 3 OBJ_TYPE_COL = 3
OBJ_HANDLE_COL = 4 OBJ_HANDLE_COL = 4
def __init__(self, dbstate, uistate, options_class, name, callback=None): def __init__(self, dbstate, user, options_class, name, callback=None):
uistate = user.uistate
self.title = _('Unused Objects') self.title = _('Unused Objects')
tool.Tool.__init__(self, dbstate, options_class, name) tool.Tool.__init__(self, dbstate, options_class, name)

View File

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

View File

@ -56,7 +56,8 @@ WIKI_HELP_SEC = _('manual|Generate_SoundEx_codes')
class SoundGen(tool.Tool, ManagedWindow): class SoundGen(tool.Tool, ManagedWindow):
def __init__(self, dbstate, uistate, options_class, name, callback=None): def __init__(self, dbstate, user, options_class, name, callback=None):
uistate = user.uistate
self.label = _('SoundEx code generator') self.label = _('SoundEx code generator')
tool.Tool.__init__(self, dbstate, options_class, name) tool.Tool.__init__(self, dbstate, options_class, name)
ManagedWindow.__init__(self,uistate,[],self.__class__) ManagedWindow.__init__(self,uistate,[],self.__class__)

View File

@ -116,7 +116,8 @@ class TestcaseGenerator(tool.BatchTool):
EventType.MARR_SETTL, EventType.MARR_SETTL,
EventType.CUSTOM ]) EventType.CUSTOM ])
def __init__(self, dbstate, uistate, options_class, name, callback=None): def __init__(self, dbstate, user, options_class, name, callback=None):
uistate = user.uistate
self.person = None self.person = None
if dbstate.db.readonly: if dbstate.db.readonly:
return return

View File

@ -254,7 +254,8 @@ def get_marriage_date(db, family):
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class Verify(tool.Tool, ManagedWindow, UpdateCallback): class Verify(tool.Tool, ManagedWindow, UpdateCallback):
def __init__(self, dbstate, uistate, options_class, name, callback=None): def __init__(self, dbstate, user, options_class, name, callback=None):
uistate = user.uistate
self.label = _('Data Verify tool') self.label = _('Data Verify tool')
self.vr = None self.vr = None
tool.Tool.__init__(self, dbstate, options_class, name) tool.Tool.__init__(self, dbstate, options_class, name)