Change gramplet to populate database with sources and citations into a tool under the Tools/Debug menu as I should have created it in the first place. This tool is a test/diagnostic tool.
svn: r18944
This commit is contained in:
parent
5f15b64215
commit
a5c42e2975
@ -1,41 +0,0 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2009 Benny Malengier
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
# $Id$
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# Register Gramplet
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
register(GRAMPLET,
|
||||
id="Populate",
|
||||
name=_("Populate data"),
|
||||
description = _("Gramplet to populate database"),
|
||||
version="2.0.0",
|
||||
gramps_target_version="3.4",
|
||||
status = STABLE,
|
||||
fname="PopulateGramplet.py",
|
||||
height=200,
|
||||
gramplet = 'PopulateGramplet',
|
||||
gramplet_title=_("Populate data"),
|
||||
)
|
||||
|
||||
|
@ -1,131 +0,0 @@
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2011 Tim G L Lyons
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
# $Id$
|
||||
|
||||
"""
|
||||
Gramplet that populates the database with sources and citations.
|
||||
"""
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# Python modules
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
import logging
|
||||
LOG = logging.getLogger(".citation")
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# GRAMPS modules
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
from gen.plug import Gramplet
|
||||
from gen.ggettext import sgettext as _
|
||||
import DateHandler
|
||||
from QuickReports import run_quick_report_by_name
|
||||
import gen.lib
|
||||
from gen.db import DbTxn
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# Gramplet class
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
class PopulateGramplet(Gramplet):
|
||||
"""
|
||||
Gramplet that populates the database with sources and citations.
|
||||
"""
|
||||
def init(self):
|
||||
"""
|
||||
Constructs the GUI, consisting of a message, an entry, and
|
||||
a Run button.
|
||||
"""
|
||||
import gtk
|
||||
# GUI setup:
|
||||
self.set_tooltip(_("Enter a date, click Run"))
|
||||
vbox = gtk.VBox()
|
||||
hbox = gtk.HBox()
|
||||
# label, entry
|
||||
description = gtk.TextView()
|
||||
description.set_wrap_mode(gtk.WRAP_WORD)
|
||||
description.set_editable(False)
|
||||
buffer = description.get_buffer()
|
||||
buffer.set_text(_("Enter a valid number of sources and citations."
|
||||
" This will create the requested number of sources,"
|
||||
" and for each source, will create the requested"
|
||||
" number of citations."))
|
||||
label_sources = gtk.Label()
|
||||
label_sources.set_text(_("Number of sources") + ":")
|
||||
self.num_sources = gtk.Entry()
|
||||
label_citations = gtk.Label()
|
||||
label_citations.set_text(_("Number of citations") + ":")
|
||||
self.num_citations = gtk.Entry()
|
||||
button = gtk.Button(_("Run"))
|
||||
button.connect("clicked", self.run)
|
||||
##self.filter =
|
||||
hbox.pack_start(label_sources, False)
|
||||
hbox.pack_start(self.num_sources, True)
|
||||
hbox.pack_start(label_citations, False)
|
||||
hbox.pack_start(self.num_citations, True)
|
||||
vbox.pack_start(description, True)
|
||||
vbox.pack_start(hbox, False)
|
||||
vbox.pack_start(button, False)
|
||||
self.gui.get_container_widget().remove(self.gui.textview)
|
||||
self.gui.get_container_widget().add_with_viewport(vbox)
|
||||
vbox.show_all()
|
||||
|
||||
def post_init(self):
|
||||
self.disconnect("active-changed")
|
||||
|
||||
def run(self, obj):
|
||||
"""
|
||||
Method that is run when you click the Run button.
|
||||
The date is retrieved from the entry box, parsed as a date,
|
||||
and then handed to the quick report.
|
||||
"""
|
||||
num_sources_text = self.num_sources.get_text()
|
||||
num_sources = int(num_sources_text)
|
||||
num_citations_text = self.num_citations.get_text()
|
||||
num_citations = int(num_citations_text)
|
||||
|
||||
LOG.debug("sources %04d citations %04d" % (num_sources,
|
||||
num_citations))
|
||||
|
||||
source = gen.lib.Source()
|
||||
citation = gen.lib.Citation()
|
||||
db = self.gui.dbstate.db
|
||||
|
||||
db.disable_signals()
|
||||
with DbTxn('Populate citations', db) as trans:
|
||||
for i in range(num_sources):
|
||||
source.gramps_id = None
|
||||
source.handle = None
|
||||
source.title = "Source %04d" % (i + 1)
|
||||
source_handle = db.add_source(source, trans)
|
||||
|
||||
for j in range(num_citations):
|
||||
citation.gramps_id = None
|
||||
citation.handle = None
|
||||
citation.source_handle = source_handle
|
||||
citation.page = "Page %04d" % (j + 1)
|
||||
db.add_citation(citation, trans)
|
||||
LOG.debug("sources and citations added")
|
||||
db.enable_signals()
|
||||
db.request_rebuild()
|
||||
|
188
src/plugins/tool/PopulateSources.py
Normal file
188
src/plugins/tool/PopulateSources.py
Normal file
@ -0,0 +1,188 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2011 Tim G L Lyons
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
# $Id$
|
||||
|
||||
"""Tools/Debug/Populate sources and citations"""
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# Python modules
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
import logging
|
||||
LOG = logging.getLogger(".citation")
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# gnome/gtk
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import gtk
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# gramps modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from gui.utils import ProgressMeter
|
||||
from gui.plug import tool
|
||||
from QuestionDialog import OkDialog
|
||||
import ManagedWindow
|
||||
import gen.lib
|
||||
from gen.db import DbTxn
|
||||
from gen.ggettext import sgettext as _
|
||||
|
||||
class PopulateSources(tool.Tool, ManagedWindow.ManagedWindow):
|
||||
"""
|
||||
Gramplet that populates the database with sources and citations.
|
||||
"""
|
||||
|
||||
def __init__(self, dbstate, uistate, options_class, name, callback=None):
|
||||
self.label = _('Populate sources and citations tool')
|
||||
ManagedWindow.ManagedWindow.__init__(self, uistate, [], self.__class__)
|
||||
self.set_window(gtk.Window(), gtk.Label(), '')
|
||||
tool.Tool.__init__(self, dbstate, options_class, name)
|
||||
|
||||
dialog = self.display()
|
||||
response = dialog.run()
|
||||
dialog.destroy()
|
||||
|
||||
if response == gtk.RESPONSE_ACCEPT:
|
||||
self.on_ok_clicked()
|
||||
OkDialog(_('Data generated'),
|
||||
_("The requested sources and citations were generated"))
|
||||
|
||||
self.close()
|
||||
|
||||
def display(self):
|
||||
"""
|
||||
Constructs the GUI, consisting of a message, and fields to enter the
|
||||
required number of sources and citations
|
||||
"""
|
||||
|
||||
# retrieve options
|
||||
num_sources = self.options.handler.options_dict['sources']
|
||||
num_citations = self.options.handler.options_dict['citations']
|
||||
|
||||
# GUI setup:
|
||||
dialog = gtk.Dialog(_("Populate sources and citations tool"),
|
||||
self.uistate.window,
|
||||
gtk.DIALOG_MODAL|gtk.DIALOG_DESTROY_WITH_PARENT,
|
||||
(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
|
||||
gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
|
||||
label = gtk.Label(_("Enter a valid number of sources and citations."
|
||||
" This will create the requested number of sources,"
|
||||
" and for each source, will create the requested"
|
||||
" number of citations."))
|
||||
label.set_line_wrap(True)
|
||||
|
||||
hbox1 = gtk.HBox()
|
||||
label_sources = gtk.Label(_("Number of sources") + ":")
|
||||
self.sources_entry = gtk.Entry()
|
||||
self.sources_entry.set_text("%d" % num_sources)
|
||||
hbox1.pack_start(label_sources, False)
|
||||
hbox1.pack_start(self.sources_entry, True)
|
||||
|
||||
hbox2 = gtk.HBox()
|
||||
label_citations = gtk.Label(_("Number of citations") + ":")
|
||||
self.citations_entry = gtk.Entry()
|
||||
self.citations_entry.set_text("%d" % num_citations)
|
||||
hbox2.pack_start(label_citations, False)
|
||||
hbox2.pack_start(self.citations_entry, True)
|
||||
|
||||
vbox = gtk.VBox()
|
||||
vbox.pack_start(label, True)
|
||||
vbox.pack_start(hbox1, False)
|
||||
vbox.pack_start(hbox2, False)
|
||||
|
||||
dialog.vbox.set_spacing(10)
|
||||
dialog.vbox.pack_start(vbox)
|
||||
dialog.show_all()
|
||||
return dialog
|
||||
|
||||
def on_ok_clicked(self):
|
||||
"""
|
||||
Method that is run when you click the OK button. The numbers of sources
|
||||
and citations are retrieved from the entry box and used to govern the
|
||||
amount of data generated
|
||||
"""
|
||||
|
||||
num_sources_text = self.sources_entry.get_text()
|
||||
num_sources = int(num_sources_text)
|
||||
num_citations_text = self.citations_entry.get_text()
|
||||
num_citations = int(num_citations_text)
|
||||
|
||||
self.progress = ProgressMeter(
|
||||
_('Generating data'), '')
|
||||
self.progress.set_pass(_('Generating data'),
|
||||
num_sources*num_citations)
|
||||
LOG.debug("sources %04d citations %04d" % (num_sources,
|
||||
num_citations))
|
||||
|
||||
source = gen.lib.Source()
|
||||
citation = gen.lib.Citation()
|
||||
|
||||
self.db.disable_signals()
|
||||
with DbTxn('Populate sources and citations', self.db) as trans:
|
||||
for i in range(num_sources):
|
||||
source.gramps_id = None
|
||||
source.handle = None
|
||||
source.title = "Source %04d" % (i + 1)
|
||||
source_handle = self.db.add_source(source, trans)
|
||||
|
||||
for j in range(num_citations):
|
||||
citation.gramps_id = None
|
||||
citation.handle = None
|
||||
citation.source_handle = source_handle
|
||||
citation.page = "Page %04d" % (j + 1)
|
||||
self.db.add_citation(citation, trans)
|
||||
self.progress.step()
|
||||
LOG.debug("sources and citations added")
|
||||
self.db.enable_signals()
|
||||
self.db.request_rebuild()
|
||||
self.progress.close()
|
||||
|
||||
self.options.handler.options_dict['sources'] = num_sources
|
||||
self.options.handler.options_dict['citations'] = num_citations
|
||||
# Save options
|
||||
self.options.handler.save_options()
|
||||
|
||||
class PopulateSourcesOptions(tool.ToolOptions):
|
||||
"""
|
||||
Defines options and provides handling interface.
|
||||
"""
|
||||
|
||||
def __init__(self, name, person_id=None):
|
||||
tool.ToolOptions.__init__(self, name, person_id)
|
||||
|
||||
# Options specific for this report
|
||||
self.options_dict = {
|
||||
'sources' : 2,
|
||||
'citations' : 2,
|
||||
}
|
||||
self.options_help = {
|
||||
'sources' : ("=num",
|
||||
"Number of sources to generate",
|
||||
"Integer number"),
|
||||
'citations' : ("=num",
|
||||
"Number of citations to generate for each source",
|
||||
"Integer number")
|
||||
}
|
@ -97,3 +97,26 @@ optionclass = 'TestcaseGeneratorOptions',
|
||||
tool_modes = [TOOL_MODE_GUI, TOOL_MODE_CLI]
|
||||
)
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# Generate Testcases for Sources and citations
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
register(TOOL,
|
||||
id = 'populatesources',
|
||||
name = "Populate Sources and Citations",
|
||||
description = ("This tool generates sources and citations ofr each source in "
|
||||
"order to populate the database for testing with significant "
|
||||
"numbers of sources and citations"),
|
||||
version = '1.0',
|
||||
gramps_target_version = '3.4',
|
||||
status = UNSTABLE,
|
||||
fname = 'PopulateSources.py',
|
||||
authors = ["Tim Lyons"],
|
||||
authors_email = [""],
|
||||
category = TOOL_DEBUG,
|
||||
toolclass = 'PopulateSources',
|
||||
optionclass = 'PopulateSourcesOptions',
|
||||
tool_modes = [TOOL_MODE_GUI, TOOL_MODE_CLI]
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user