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:
parent
8bdb301958
commit
5c9751f3b9
@ -652,7 +652,8 @@ class ArgHandler(object):
|
||||
category=category,
|
||||
tool_class=tool_class,
|
||||
options_class=options_class,
|
||||
options_str_dict=options_str_dict)
|
||||
options_str_dict=options_str_dict,
|
||||
user=self.user)
|
||||
return
|
||||
msg = _("Unknown tool name.")
|
||||
else:
|
||||
|
@ -339,8 +339,7 @@ def startcli(errors, argparser):
|
||||
|
||||
#we need a manager for the CLI session
|
||||
from .user import User
|
||||
user=User(error=self.__error,
|
||||
auto_accept=argparser.auto_accept,
|
||||
user=User(auto_accept=argparser.auto_accept,
|
||||
quiet=argparser.quiet)
|
||||
climanager = CLIManager(dbstate, setloader=True, user=user)
|
||||
|
||||
|
@ -36,6 +36,7 @@ class User():
|
||||
self.callback_function = callback
|
||||
self.error_function = error
|
||||
self._fileout = sys.stderr # redirected to mocks by unit tests
|
||||
self.uistate = None
|
||||
|
||||
def begin_progress(self, title, message, steps):
|
||||
"""
|
||||
|
@ -248,9 +248,10 @@ class PluginDialog(ManagedWindow):
|
||||
pdata.name, pdata.id,
|
||||
pdata.category, pdata.require_active)
|
||||
else:
|
||||
from ..user import User
|
||||
tool.gui_tool(
|
||||
dbstate = self.state,
|
||||
uistate = self.uistate,
|
||||
user = User(uistate=self.uistate),
|
||||
tool_class = eval('mod.' + pdata.toolclass),
|
||||
options_class = eval('mod.' + pdata.optionclass),
|
||||
translated_name = pdata.name,
|
||||
|
@ -1046,7 +1046,8 @@ class ToolManagedWindowBase(ManagedWindow):
|
||||
|
||||
|
||||
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:
|
||||
self.dbstate = dbstate
|
||||
self.uistate = uistate
|
||||
|
@ -244,7 +244,7 @@ class CommandLineTool(object):
|
||||
#------------------------------------------------------------------------
|
||||
# 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):
|
||||
"""
|
||||
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:
|
||||
tool_class(dbstate = dbstate, uistate = uistate,
|
||||
tool_class(dbstate = dbstate, user = user,
|
||||
options_class = options_class, name = name,
|
||||
callback = callback)
|
||||
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)
|
||||
|
||||
# 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,
|
||||
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:
|
||||
return
|
||||
|
||||
if user is None:
|
||||
from ...cli.user import User
|
||||
user = User()
|
||||
# run tool
|
||||
try:
|
||||
tool_class(dbstate = dbstate, uistate = None,
|
||||
tool_class(dbstate = dbstate, user = user,
|
||||
options_class = clt.option_class, name = name, callback = None)
|
||||
except:
|
||||
log.error("Failed to start tool.", exc_info=True)
|
||||
|
@ -1626,7 +1626,7 @@ def run_plugin(pdata, dbstate, uistate):
|
||||
pdata.category, pdata.require_active,
|
||||
)
|
||||
else:
|
||||
tool.gui_tool(dbstate = dbstate, uistate = uistate,
|
||||
tool.gui_tool(dbstate = dbstate, user = User(uistate = uistate),
|
||||
tool_class = getattr(mod, pdata.toolclass),
|
||||
options_class = getattr(mod, pdata.optionclass),
|
||||
translated_name = pdata.name,
|
||||
|
@ -72,7 +72,8 @@ WIKI_HELP_SEC = _('manual|Fix_Capitalization_of_Family_Names...')
|
||||
#-------------------------------------------------------------------------
|
||||
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.cb = callback
|
||||
|
||||
|
@ -54,7 +54,8 @@ from gramps.gui.glade import Glade
|
||||
#-------------------------------------------------------------------------
|
||||
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)
|
||||
if self.fail:
|
||||
|
@ -135,7 +135,8 @@ def cross_table_duplicates(db):
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
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)
|
||||
if self.fail:
|
||||
|
@ -59,7 +59,8 @@ from gramps.gen.datehandler import displayer as _dd
|
||||
#-------------------------------------------------------------------------
|
||||
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)
|
||||
if uistate:
|
||||
|
@ -57,7 +57,8 @@ WIKI_HELP_SEC = _('manual|Interactive_Descendant_Browser...')
|
||||
|
||||
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,
|
||||
name)
|
||||
|
@ -45,7 +45,8 @@ _GENDER = [ _('female'), _('male'), _('unknown') ]
|
||||
#-------------------------------------------------------------------------
|
||||
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")
|
||||
tool.Tool.__init__(self, dbstate, options_class, name)
|
||||
if uistate:
|
||||
|
@ -55,7 +55,8 @@ from gramps.gen.constfunc import cuni
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
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")
|
||||
|
||||
tool.Tool.__init__(self,dbstate, options_class, name)
|
||||
|
@ -117,7 +117,8 @@ class TableReport(object):
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
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.uistate = uistate
|
||||
|
||||
|
@ -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)
|
||||
|
||||
if not self.fail:
|
||||
|
@ -413,7 +413,8 @@ class ExtractCity(tool.BatchTool, ManagedWindow):
|
||||
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')
|
||||
|
||||
ManagedWindow.__init__(self, uistate, [], self.__class__)
|
||||
|
@ -88,7 +88,8 @@ def is_initial(name):
|
||||
#-------------------------------------------------------------------------
|
||||
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)
|
||||
ManagedWindow.__init__(self, uistate, [],
|
||||
|
@ -67,7 +67,8 @@ from gramps.gui.utils import is_right_click
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
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')
|
||||
|
||||
tool.Tool.__init__(self,dbstate, options_class, name)
|
||||
|
@ -78,7 +78,8 @@ WIKI_HELP_SEC = _('manual|Media_Manager...')
|
||||
#-------------------------------------------------------------------------
|
||||
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)
|
||||
self.uistate = uistate
|
||||
|
@ -92,7 +92,8 @@ WIKI_HELP_SEC = _('manual|Merge citations...')
|
||||
#-------------------------------------------------------------------------
|
||||
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__)
|
||||
self.dbstate = dbstate
|
||||
|
@ -68,7 +68,8 @@ WIKI_HELP_SEC = _('manual|Not_Related...')
|
||||
#------------------------------------------------------------------------
|
||||
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,
|
||||
name)
|
||||
|
||||
|
@ -86,7 +86,8 @@ class OwnerEditor(tool.Tool, ManagedWindow):
|
||||
Provides a possibility to direcly verify and edit the owner data of the
|
||||
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__)
|
||||
tool.Tool.__init__(self, dbstate, options_class, name)
|
||||
|
||||
|
@ -103,7 +103,8 @@ class PatchNames(tool.BatchTool, ManagedWindow):
|
||||
pref1id = 3
|
||||
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')
|
||||
ManagedWindow.__init__(self, uistate, [], self.__class__)
|
||||
self.set_window(Gtk.Window(), Gtk.Label(), '')
|
||||
|
@ -54,7 +54,8 @@ class PopulateSources(tool.Tool, ManagedWindow):
|
||||
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'
|
||||
ManagedWindow.__init__(self, uistate, [], self.__class__)
|
||||
self.set_window(Gtk.Window(), Gtk.Label(), '')
|
||||
|
@ -64,7 +64,8 @@ from gramps.gen.updatecallback import 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)
|
||||
|
||||
|
@ -70,7 +70,8 @@ COLUMN_ALTNAMES = 4
|
||||
|
||||
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)
|
||||
|
||||
|
@ -66,7 +66,8 @@ from gramps.gen.updatecallback import 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)
|
||||
|
||||
|
@ -71,7 +71,8 @@ column_names = [column[0] for column in BasePersonView.COLUMNS]
|
||||
#-------------------------------------------------------------------------
|
||||
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.
|
||||
"""
|
||||
|
@ -77,7 +77,8 @@ class RemoveUnused(tool.Tool, ManagedWindow, UpdateCallback):
|
||||
OBJ_TYPE_COL = 3
|
||||
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')
|
||||
|
||||
tool.Tool.__init__(self, dbstate, options_class, name)
|
||||
|
@ -59,7 +59,8 @@ _parseformat = re.compile('.*%(\d+)[^\d]+')
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
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)
|
||||
if self.fail:
|
||||
return
|
||||
|
@ -56,7 +56,8 @@ WIKI_HELP_SEC = _('manual|Generate_SoundEx_codes')
|
||||
|
||||
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')
|
||||
tool.Tool.__init__(self, dbstate, options_class, name)
|
||||
ManagedWindow.__init__(self,uistate,[],self.__class__)
|
||||
|
@ -116,7 +116,8 @@ class TestcaseGenerator(tool.BatchTool):
|
||||
EventType.MARR_SETTL,
|
||||
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
|
||||
if dbstate.db.readonly:
|
||||
return
|
||||
|
@ -254,7 +254,8 @@ def get_marriage_date(db, family):
|
||||
#-------------------------------------------------------------------------
|
||||
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.vr = None
|
||||
tool.Tool.__init__(self, dbstate, options_class, name)
|
||||
|
Loading…
Reference in New Issue
Block a user