move database code into new package
svn: r5598
This commit is contained in:
parent
d850b72fcf
commit
9eb1f99b86
28
ChangeLog
28
ChangeLog
@ -1,3 +1,31 @@
|
|||||||
|
2005-12-21 Richard Taylor <rjt-gramps@thegrindstone.me.uk>
|
||||||
|
* src/GrampsDb: new package for all the db related modules
|
||||||
|
* src/GedcomInfo.py moved to src/GrampsDb/_GedcomInfo.py
|
||||||
|
* src/GrampsBSDDB.py moved to src/GrampsDb/_GrampsBSDDB.py
|
||||||
|
* src/GrampsDBCallback.py moved to src/GrampsDb/_GrampsDBCallback.py
|
||||||
|
* src/GrampsDbBase.py moved to src/GrampsDb/_GrampsDbBase.py
|
||||||
|
* src/GrampsGEDDB.py moved to src/GrampsDb/_GrampsGEDDB.py
|
||||||
|
* src/GrampsInMemDB.py moved to src/GrampsDb/_GrampsInMemDB.py
|
||||||
|
* src/GrampsXMLDB.py moved to src/GrampsDb/_GrampsXMLDB.py
|
||||||
|
* src/ReadGedcom.py moved to src/GrampsDb/_ReadGedcom.py
|
||||||
|
* src/eadGrdb.py moved to src/GrampsDb/_ReadGrdb.py
|
||||||
|
* src/ReadXML.py moved to src/GrampsDb/_ReadXML.py
|
||||||
|
* src/WriteGedcom.py moved to src/GrampsDb/_WriteGedcom.py
|
||||||
|
* src/WriteGrdb.py moved to src/GrampsDb/_WriteGrdb.py
|
||||||
|
* src/WriteXML.py moved to src/GrampsDb/_WriteXML.py
|
||||||
|
* src/GrampsDb/__init__.py: new package export file
|
||||||
|
* src/GrampsDb/_GrampsDbExceptions.py: new module for GrampDb exceptions
|
||||||
|
* src/GrampsDb/_GrampsDbFactories.py: new module for factory methods
|
||||||
|
* test/RelLib: new test directory
|
||||||
|
* test/RelLib: new test directory
|
||||||
|
* test/GrampsDbBase_Test.py moved to test/GrampsDb/GrampsDbBase_Test.py
|
||||||
|
* test/GrampsDbTestBase.py moved to test/GrampsDb/GrampsDbTestBase.py
|
||||||
|
* test/RelLib_Test.py moved to test/RelLib/RelLib_Test.py
|
||||||
|
* src/ArgHandler.py src/DbPrompter.py src/DisplayState.py
|
||||||
|
src/Exporter.py src/RepositoryRefEdit.py src/ViewManager.py
|
||||||
|
src/gramps_main.py: modified to work with new GrampsDb package
|
||||||
|
* test/RunAllTests.py: find tests in subdirectories
|
||||||
|
|
||||||
2005-12-21 Richard Taylor <rjt-gramps@thegrindstone.me.uk>
|
2005-12-21 Richard Taylor <rjt-gramps@thegrindstone.me.uk>
|
||||||
* src/RelLib/_SourceRef.py: added import for Note class
|
* src/RelLib/_SourceRef.py: added import for Note class
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ from gettext import gettext as _
|
|||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
import const
|
import const
|
||||||
import ReadXML
|
import GrampsDb
|
||||||
import GrampsMime
|
import GrampsMime
|
||||||
import DbPrompter
|
import DbPrompter
|
||||||
import QuestionDialog
|
import QuestionDialog
|
||||||
@ -407,18 +407,17 @@ class ArgHandler:
|
|||||||
Any errors will cause the os._exit(1) call.
|
Any errors will cause the os._exit(1) call.
|
||||||
"""
|
"""
|
||||||
if format == 'grdb':
|
if format == 'grdb':
|
||||||
import ReadGrdb
|
|
||||||
filename = os.path.normpath(os.path.abspath(filename))
|
filename = os.path.normpath(os.path.abspath(filename))
|
||||||
try:
|
try:
|
||||||
ReadGrdb.importData(self.parent.db,filename,None)
|
GrampsDb.gramps_db_reader_factory(const.app_gramps)(self.parent.db,filename,None)
|
||||||
except:
|
except:
|
||||||
print "Error importing %s" % filename
|
print "Error importing %s" % filename
|
||||||
os._exit(1)
|
os._exit(1)
|
||||||
elif format == 'gedcom':
|
elif format == 'gedcom':
|
||||||
import ReadGedcom
|
from GrampsDb import GedcomParser
|
||||||
filename = os.path.normpath(os.path.abspath(filename))
|
filename = os.path.normpath(os.path.abspath(filename))
|
||||||
try:
|
try:
|
||||||
g = ReadGedcom.GedcomParser(self.parent.db,filename,None)
|
g = GedcomParser(self.parent.db,filename,None)
|
||||||
g.parse_gedcom_file()
|
g.parse_gedcom_file()
|
||||||
g.resolve_refns()
|
g.resolve_refns()
|
||||||
del g
|
del g
|
||||||
@ -427,7 +426,7 @@ class ArgHandler:
|
|||||||
os._exit(1)
|
os._exit(1)
|
||||||
elif format == 'gramps-xml':
|
elif format == 'gramps-xml':
|
||||||
try:
|
try:
|
||||||
ReadXML.importData(self.parent.db,filename,None,self.parent.cl)
|
GrampsDb.gramps_db_reader_factory(const.app_gramps_xml)(self.parent.db,filename,None,self.parent.cl)
|
||||||
except:
|
except:
|
||||||
print "Error importing %s" % filename
|
print "Error importing %s" % filename
|
||||||
os._exit(1)
|
os._exit(1)
|
||||||
@ -469,7 +468,7 @@ class ArgHandler:
|
|||||||
dbname = os.path.join(tmpdir_path,const.xmlFile)
|
dbname = os.path.join(tmpdir_path,const.xmlFile)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ReadXML.importData(self.parent.db,dbname,None)
|
GrampsDb.gramps_db_reader_factory(const.app_gramps_xml)(self.parent.db,dbname,None)
|
||||||
except:
|
except:
|
||||||
print "Error importing %s" % filename
|
print "Error importing %s" % filename
|
||||||
os._exit(1)
|
os._exit(1)
|
||||||
@ -496,16 +495,14 @@ class ArgHandler:
|
|||||||
Any errors will cause the os._exit(1) call.
|
Any errors will cause the os._exit(1) call.
|
||||||
"""
|
"""
|
||||||
if format == 'grdb':
|
if format == 'grdb':
|
||||||
import WriteGrdb
|
|
||||||
try:
|
try:
|
||||||
WriteGrdb.exportData(self.parent.db,filename)
|
GrampsDb.gramps_db_writer_factory(const.app_gramps)(self.parent.db,filename)
|
||||||
except:
|
except:
|
||||||
print "Error exporting %s" % filename
|
print "Error exporting %s" % filename
|
||||||
os._exit(1)
|
os._exit(1)
|
||||||
elif format == 'gedcom':
|
elif format == 'gedcom':
|
||||||
import WriteGedcom
|
|
||||||
try:
|
try:
|
||||||
gw = WriteGedcom.GedcomWriter(self.parent.db,None,1,filename)
|
gw = GrampsDb.GedcomWriter(self.parent.db,None,1,filename)
|
||||||
ret = gw.export_data(filename)
|
ret = gw.export_data(filename)
|
||||||
except:
|
except:
|
||||||
print "Error exporting %s" % filename
|
print "Error exporting %s" % filename
|
||||||
@ -514,8 +511,7 @@ class ArgHandler:
|
|||||||
filename = os.path.normpath(os.path.abspath(filename))
|
filename = os.path.normpath(os.path.abspath(filename))
|
||||||
if filename:
|
if filename:
|
||||||
try:
|
try:
|
||||||
import WriteXML
|
g = GrampsDb.XmlWriter(self.parent.db,None,1,1)
|
||||||
g = WriteXML.XmlWriter(self.parent.db,None,1,1)
|
|
||||||
ret = g.write(filename)
|
ret = g.write(filename)
|
||||||
except:
|
except:
|
||||||
print "Error exporting %s" % filename
|
print "Error exporting %s" % filename
|
||||||
|
@ -50,15 +50,9 @@ import Utils
|
|||||||
import const
|
import const
|
||||||
import QuestionDialog
|
import QuestionDialog
|
||||||
import PluginMgr
|
import PluginMgr
|
||||||
import GrampsBSDDB
|
import GrampsDb
|
||||||
import GrampsXMLDB
|
|
||||||
import GrampsGEDDB
|
|
||||||
import GrampsKeys
|
import GrampsKeys
|
||||||
import RecentFiles
|
import RecentFiles
|
||||||
import ReadGrdb
|
|
||||||
import WriteGrdb
|
|
||||||
import WriteXML
|
|
||||||
import WriteGedcom
|
|
||||||
import GrampsDisplay
|
import GrampsDisplay
|
||||||
|
|
||||||
from bsddb import db
|
from bsddb import db
|
||||||
@ -353,18 +347,16 @@ class ImportDbPrompter:
|
|||||||
|
|
||||||
if filetype == const.app_gramps:
|
if filetype == const.app_gramps:
|
||||||
choose.destroy()
|
choose.destroy()
|
||||||
ReadGrdb.importData(self.parent.db,filename)
|
GrampsDb.gramps_db_reader_factory(filetype)(self.parent.db,filename)
|
||||||
self.parent.import_tool_callback()
|
self.parent.import_tool_callback()
|
||||||
return True
|
return True
|
||||||
elif filetype == const.app_gramps_xml:
|
elif filetype == const.app_gramps_xml:
|
||||||
choose.destroy()
|
choose.destroy()
|
||||||
import ReadXML
|
GrampsDb.gramps_db_reader_factory(filetype)(self.parent.db,filename,self.parent.update_bar)
|
||||||
ReadXML.importData(self.parent.db,filename,self.parent.update_bar)
|
|
||||||
return True
|
return True
|
||||||
elif filetype == const.app_gedcom:
|
elif filetype == const.app_gedcom:
|
||||||
choose.destroy()
|
choose.destroy()
|
||||||
import ReadGedcom
|
GrampsDb.gramps_db_reader_factory(filetype)(self.parent.db,filename)
|
||||||
ReadGedcom.importData(self.parent.db,filename)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
(the_path,the_file) = os.path.split(filename)
|
(the_path,the_file) = os.path.split(filename)
|
||||||
@ -443,7 +435,7 @@ class NewNativeDbPrompter:
|
|||||||
close(self.parent)
|
close(self.parent)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
self.parent.db = GrampsBSDDB.GrampsBSDDB()
|
self.parent.db = GrampsDb.gramps_db_factory(const.app_gramps)()
|
||||||
self.parent.read_file(filename)
|
self.parent.read_file(filename)
|
||||||
# Add the file to the recent items
|
# Add the file to the recent items
|
||||||
RecentFiles.recent_files(filename,const.app_gramps)
|
RecentFiles.recent_files(filename,const.app_gramps)
|
||||||
@ -530,17 +522,17 @@ class NewSaveasDbPrompter:
|
|||||||
_('File type "%s" is unknown to GRAMPS.\n\nValid types are: GRAMPS database, GRAMPS XML, GRAMPS package, and GEDCOM.') % filetype)
|
_('File type "%s" is unknown to GRAMPS.\n\nValid types are: GRAMPS database, GRAMPS XML, GRAMPS package, and GEDCOM.') % filetype)
|
||||||
return False
|
return False
|
||||||
if filetype == const.app_gramps:
|
if filetype == const.app_gramps:
|
||||||
WriteGrdb.exportData(self.parent.db,filename,None,None)
|
GrampsDb.gramps_db_writer_factory(filetype)(self.parent.db,filename,None,None)
|
||||||
close(self.parent)
|
close(self.parent)
|
||||||
self.parent.db = GrampsBSDDB.GrampsBSDDB()
|
self.parent.db = GrampsDb.gramps_db_factory(filetype)()
|
||||||
elif filetype == const.app_gramps_xml:
|
elif filetype == const.app_gramps_xml:
|
||||||
WriteXML.exportData(self.parent.db,filename,None,None)
|
GrampsDb.gramps_db_writer_factory(filetype)(self.parent.db,filename,None,None)
|
||||||
close(self.parent)
|
close(self.parent)
|
||||||
self.parent.db = GrampsXMLDB.GrampsXMLDB()
|
self.parent.db = GrampsDb.gramps_db_factory(filetype)()
|
||||||
elif filetype == const.app_gedcom:
|
elif filetype == const.app_gedcom:
|
||||||
WriteGedcom.exportData(self.parent.db,filename,None,None)
|
GrampsDb.gramps_db_writer_factory(filetype)(self.parent.db,filename,None,None)
|
||||||
close(self.parent)
|
close(self.parent)
|
||||||
self.parent.db = GrampsGEDDB.GrampsGEDDB()
|
self.parent.db = GrampsDb.gramps_db_factory(filetype)()
|
||||||
self.parent.read_file(filename)
|
self.parent.read_file(filename)
|
||||||
# Add the file to the recent items
|
# Add the file to the recent items
|
||||||
RecentFiles.recent_files(filename,const.app_gramps)
|
RecentFiles.recent_files(filename,const.app_gramps)
|
||||||
@ -574,8 +566,8 @@ def open_native(parent,filename,filetype):
|
|||||||
GrampsKeys.save_last_import_dir(the_path)
|
GrampsKeys.save_last_import_dir(the_path)
|
||||||
|
|
||||||
success = False
|
success = False
|
||||||
if filetype == const.app_gramps:
|
if filetype == const.app_gramps:
|
||||||
state.db = GrampsBSDDB.GrampsBSDDB()
|
state.db = GrampsDb.gramps_db_factory(filetype)()
|
||||||
msgxml = gtk.glade.XML(const.gladeFile, "load_message","gramps")
|
msgxml = gtk.glade.XML(const.gladeFile, "load_message","gramps")
|
||||||
msg_top = msgxml.get_widget('load_message')
|
msg_top = msgxml.get_widget('load_message')
|
||||||
msg_label = msgxml.get_widget('message')
|
msg_label = msgxml.get_widget('message')
|
||||||
@ -589,10 +581,10 @@ def open_native(parent,filename,filetype):
|
|||||||
success = self.read_file(filename,update_msg)
|
success = self.read_file(filename,update_msg)
|
||||||
msg_top.destroy()
|
msg_top.destroy()
|
||||||
elif filetype == const.app_gramps_xml:
|
elif filetype == const.app_gramps_xml:
|
||||||
state.db = GrampsXMLDB.GrampsXMLDB()
|
state.db = GrampsDb.gramps_db_factory(filetype)()
|
||||||
success = self.read_file(filename)
|
success = self.read_file(filename)
|
||||||
elif filetype == const.app_gedcom:
|
elif filetype == const.app_gedcom:
|
||||||
state.db = GrampsGEDDB.GrampsGEDDB()
|
state.db = GrampsDb.gramps_db_factory(filetype)()
|
||||||
success = self.read_file(filename)
|
success = self.read_file(filename)
|
||||||
|
|
||||||
#if success:
|
#if success:
|
||||||
|
@ -40,8 +40,7 @@ import gtk
|
|||||||
# GRAMPS modules
|
# GRAMPS modules
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
import GrampsDbBase
|
import GrampsDb
|
||||||
import GrampsDBCallback
|
|
||||||
import GrampsKeys
|
import GrampsKeys
|
||||||
import NameDisplay
|
import NameDisplay
|
||||||
|
|
||||||
@ -50,7 +49,7 @@ import NameDisplay
|
|||||||
# History manager
|
# History manager
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
class History(GrampsDBCallback.GrampsDBCallback):
|
class History(GrampsDb.GrampsDBCallback):
|
||||||
|
|
||||||
__signals__ = {
|
__signals__ = {
|
||||||
'changed' : (list,),
|
'changed' : (list,),
|
||||||
@ -58,7 +57,7 @@ class History(GrampsDBCallback.GrampsDBCallback):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
GrampsDBCallback.GrampsDBCallback.__init__(self)
|
GrampsDb.GrampsDBCallback.__init__(self)
|
||||||
self.history = []
|
self.history = []
|
||||||
self.mhistory = []
|
self.mhistory = []
|
||||||
self.index = -1
|
self.index = -1
|
||||||
@ -405,7 +404,7 @@ class ManagedWindow:
|
|||||||
# Gramps Display State class
|
# Gramps Display State class
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
class DisplayState(GrampsDBCallback.GrampsDBCallback):
|
class DisplayState(GrampsDb.GrampsDBCallback):
|
||||||
|
|
||||||
__signals__ = {
|
__signals__ = {
|
||||||
}
|
}
|
||||||
@ -414,7 +413,7 @@ class DisplayState(GrampsDBCallback.GrampsDBCallback):
|
|||||||
self.dbstate = dbstate
|
self.dbstate = dbstate
|
||||||
self.uimanager = uimanager
|
self.uimanager = uimanager
|
||||||
self.window = window
|
self.window = window
|
||||||
GrampsDBCallback.GrampsDBCallback.__init__(self)
|
GrampsDb.GrampsDBCallback.__init__(self)
|
||||||
self.status = status
|
self.status = status
|
||||||
self.status_id = status.get_context_id('GRAMPS')
|
self.status_id = status.get_context_id('GRAMPS')
|
||||||
self.phistory = History()
|
self.phistory = History()
|
||||||
|
@ -365,8 +365,7 @@ class Exporter:
|
|||||||
In the future, filter and other options may be added.
|
In the future, filter and other options may be added.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
import WriteGrdb
|
GrampsDb.gramps_db_writer_factory(const.app_gramps)(database,filename,person)
|
||||||
WriteGrdb.exportData(database,filename,person)
|
|
||||||
return 1
|
return 1
|
||||||
except IOError, msg:
|
except IOError, msg:
|
||||||
QuestionDialog.ErrorDialog( _("Could not write file: %s") % filename,
|
QuestionDialog.ErrorDialog( _("Could not write file: %s") % filename,
|
||||||
|
@ -50,7 +50,7 @@ except NameError:
|
|||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
from RelLib import *
|
from RelLib import *
|
||||||
from GrampsDbBase import *
|
from _GrampsDbBase import *
|
||||||
|
|
||||||
_MINVERSION = 5
|
_MINVERSION = 5
|
||||||
_DBVERSION = 9
|
_DBVERSION = 9
|
@ -49,7 +49,7 @@ log = sys.stderr.write
|
|||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
from RelLib import *
|
from RelLib import *
|
||||||
import GrampsKeys
|
import GrampsKeys
|
||||||
import GrampsDBCallback
|
from _GrampsDBCallback import GrampsDBCallback
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -144,7 +144,7 @@ class GrampsCursor:
|
|||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class GrampsDbBase(GrampsDBCallback.GrampsDBCallback):
|
class GrampsDbBase(GrampsDBCallback):
|
||||||
"""
|
"""
|
||||||
GRAMPS database object. This object is a base class for all
|
GRAMPS database object. This object is a base class for all
|
||||||
database interfaces.
|
database interfaces.
|
||||||
@ -196,7 +196,7 @@ class GrampsDbBase(GrampsDBCallback.GrampsDBCallback):
|
|||||||
be created.
|
be created.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
GrampsDBCallback.GrampsDBCallback.__init__(self)
|
GrampsDBCallback.__init__(self)
|
||||||
|
|
||||||
self.readonly = False
|
self.readonly = False
|
||||||
self.rand = random.Random(time.time())
|
self.rand = random.Random(time.time())
|
||||||
@ -1671,7 +1671,7 @@ class Transaction:
|
|||||||
return self.last - self.first + 1
|
return self.last - self.first + 1
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
class DbState(GrampsDBCallback.GrampsDBCallback):
|
class DbState(GrampsDBCallback):
|
||||||
|
|
||||||
__signals__ = {
|
__signals__ = {
|
||||||
'database-changed' : (GrampsDbBase,),
|
'database-changed' : (GrampsDbBase,),
|
||||||
@ -1680,7 +1680,7 @@ class DbState(GrampsDBCallback.GrampsDBCallback):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
GrampsDBCallback.GrampsDBCallback.__init__(self)
|
GrampsDBCallback.__init__(self)
|
||||||
self.db = GrampsDbBase()
|
self.db = GrampsDbBase()
|
||||||
self.open = False
|
self.open = False
|
||||||
self.active = None
|
self.active = None
|
32
src/GrampsDb/_GrampsDbExceptions.py
Normal file
32
src/GrampsDb/_GrampsDbExceptions.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#
|
||||||
|
# Gramps - a GTK+/GNOME based genealogy program
|
||||||
|
#
|
||||||
|
# Copyright (C) 2004-2005 Donald N. Allingham
|
||||||
|
#
|
||||||
|
# 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$
|
||||||
|
|
||||||
|
"""Exceptions generated by the GrampsDb package."""
|
||||||
|
|
||||||
|
|
||||||
|
class GrampsDbException(Exception):
|
||||||
|
|
||||||
|
def __init__(self, value):
|
||||||
|
self.value = value
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return repr(self.value)
|
123
src/GrampsDb/_GrampsDbFactories.py
Normal file
123
src/GrampsDb/_GrampsDbFactories.py
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
#
|
||||||
|
# Gramps - a GTK+/GNOME based genealogy program
|
||||||
|
#
|
||||||
|
# Copyright (C) 2004-2005 Donald N. Allingham
|
||||||
|
#
|
||||||
|
# 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$
|
||||||
|
|
||||||
|
"""
|
||||||
|
This module contains factory methods for accessing the different
|
||||||
|
GrampsDb backends. These methods should be used obtain the correct class
|
||||||
|
for a database backend.
|
||||||
|
|
||||||
|
The app_* constants in const.py can be used to indicate which backend is
|
||||||
|
required e.g.:
|
||||||
|
|
||||||
|
# To get the class for the grdb backend
|
||||||
|
db_class = GrampsDb.gramps_db_factory(db_type = const.app_gramps)
|
||||||
|
|
||||||
|
# To get a XML writer
|
||||||
|
GrampsDb.gramps_db_writer_factory(db_type = const.app_gramps_xml)
|
||||||
|
|
||||||
|
# To get a Gedcom reader
|
||||||
|
GrampsDb.gramps_db_reader_factory(db_type = const.app_gedcom)
|
||||||
|
|
||||||
|
"""
|
||||||
|
import const
|
||||||
|
|
||||||
|
from _GrampsDbExceptions import GrampsDbException
|
||||||
|
|
||||||
|
def gramps_db_factory(db_type):
|
||||||
|
"""Factory class for obtaining a Gramps database backend.
|
||||||
|
|
||||||
|
@param db_type: the type of backend required.
|
||||||
|
@type db_type: one of the app_* constants in const.py
|
||||||
|
|
||||||
|
Raises GrampsDbException if the db_type is not recognised.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if db_type == const.app_gramps:
|
||||||
|
from _GrampsBSDDB import GrampsBSDDB
|
||||||
|
cls = GrampsBSDDB
|
||||||
|
elif db_type == const.app_gramps_xml:
|
||||||
|
from _GrampsXMLDB import GrampsXMLDB
|
||||||
|
cls = GrampsXMLDB
|
||||||
|
elif db_type == const.app_gedcom:
|
||||||
|
from _GrampsGEDDB import GrampsGEDDB
|
||||||
|
cls = GrampsGEDDB
|
||||||
|
else:
|
||||||
|
raise GrampsDbException("Attempt to create unknown "
|
||||||
|
"database backend class: "
|
||||||
|
"db_type = %s" % (str(db_type),))
|
||||||
|
|
||||||
|
return cls
|
||||||
|
|
||||||
|
|
||||||
|
def gramps_db_writer_factory(db_type):
|
||||||
|
"""Factory class for obtaining a Gramps database writers.
|
||||||
|
|
||||||
|
|
||||||
|
@param db_type: the type of backend required.
|
||||||
|
@type db_type: one of the app_* constants in const.py
|
||||||
|
|
||||||
|
Raises GrampsDbException if the db_type is not recognised.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if db_type == const.app_gramps:
|
||||||
|
import _WriteGrdb as WriteGrdb
|
||||||
|
md = WriteGrdb.exportData
|
||||||
|
elif db_type == const.app_gramps_xml:
|
||||||
|
import _WriteXML as WriteXML
|
||||||
|
md = WriteXML.exportData
|
||||||
|
elif db_type == const.app_gedcom:
|
||||||
|
import _WriteGedcom as WriteGedcom
|
||||||
|
md = WriteGedcom.exportData
|
||||||
|
else:
|
||||||
|
raise GrampsDbException("Attempt to create a database "
|
||||||
|
"writer for unknown format: "
|
||||||
|
"db_type = %s" % (str(db_type),))
|
||||||
|
|
||||||
|
return md
|
||||||
|
|
||||||
|
def gramps_db_reader_factory(db_type):
|
||||||
|
"""Factory class for obtaining a Gramps database writers.
|
||||||
|
|
||||||
|
@param db_type: the type of backend required.
|
||||||
|
@type db_type: one of the app_* constants in const.py
|
||||||
|
|
||||||
|
Raises GrampsDbException if the db_type is not recognised.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if db_type == const.app_gramps:
|
||||||
|
import _ReadGrdb as ReadGrdb
|
||||||
|
md = ReadGrdb.importData
|
||||||
|
elif db_type == const.app_gramps_xml:
|
||||||
|
import _ReadXML as ReadXML
|
||||||
|
md = ReadXML.importData
|
||||||
|
elif db_type == const.app_gedcom:
|
||||||
|
import _ReadGedcom as ReadGedcom
|
||||||
|
md = ReadGedcom.importData
|
||||||
|
else:
|
||||||
|
raise GrampsDbException("Attempt to create a database "
|
||||||
|
"reader for unknown format: "
|
||||||
|
"db_type = %s" % (str(db_type),))
|
||||||
|
|
||||||
|
return md
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -26,10 +26,10 @@ of GEDCOM files.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from RelLib import *
|
from RelLib import *
|
||||||
from GrampsInMemDB import *
|
from _GrampsInMemDB import *
|
||||||
|
|
||||||
import ReadGedcom
|
import _ReadGedcom as ReadGedcom
|
||||||
import WriteGedcom
|
import _WriteGedcom as WriteGedcom
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
@ -33,7 +33,7 @@ from bsddb import dbshelve, db
|
|||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
from RelLib import *
|
from RelLib import *
|
||||||
from GrampsDbBase import *
|
from _GrampsDbBase import *
|
||||||
import sets
|
import sets
|
||||||
|
|
||||||
class GrampsInMemCursor(GrampsCursor):
|
class GrampsInMemCursor(GrampsCursor):
|
@ -26,10 +26,10 @@ of GRAMPS XML format.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from RelLib import *
|
from RelLib import *
|
||||||
from GrampsInMemDB import *
|
from _GrampsInMemDB import *
|
||||||
|
|
||||||
import ReadXML
|
import _ReadXML as ReadXML
|
||||||
import WriteXML
|
import _WriteXML as WriteXML
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
@ -57,7 +57,7 @@ from ansel_utf8 import ansel_to_utf8
|
|||||||
import Utils
|
import Utils
|
||||||
import GrampsMime
|
import GrampsMime
|
||||||
from bsddb import db
|
from bsddb import db
|
||||||
from GedcomInfo import *
|
from _GedcomInfo import *
|
||||||
from QuestionDialog import ErrorDialog, WarningDialog
|
from QuestionDialog import ErrorDialog, WarningDialog
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
@ -37,7 +37,7 @@ import sets
|
|||||||
# Gramps Modules
|
# Gramps Modules
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
import GrampsBSDDB
|
from _GrampsBSDDB import GrampsBSDDB
|
||||||
from QuestionDialog import ErrorDialog
|
from QuestionDialog import ErrorDialog
|
||||||
import Errors
|
import Errors
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ def importData(database, filename, callback=None,cl=0,use_trans=True):
|
|||||||
|
|
||||||
filename = os.path.normpath(filename)
|
filename = os.path.normpath(filename)
|
||||||
|
|
||||||
other_database = GrampsBSDDB.GrampsBSDDB()
|
other_database = GrampsBSDDB()
|
||||||
try:
|
try:
|
||||||
other_database.load(filename,callback)
|
other_database.load(filename,callback)
|
||||||
except:
|
except:
|
@ -49,7 +49,7 @@ import RelLib
|
|||||||
import GenericFilter
|
import GenericFilter
|
||||||
import const
|
import const
|
||||||
import Date
|
import Date
|
||||||
import GedcomInfo
|
import _GedcomInfo as GedcomInfo
|
||||||
import Errors
|
import Errors
|
||||||
import ansel_utf8
|
import ansel_utf8
|
||||||
import Utils
|
import Utils
|
@ -35,7 +35,7 @@ from gettext import gettext as _
|
|||||||
# Gramps Modules
|
# Gramps Modules
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
import GrampsBSDDB
|
from _GrampsBSDDB import GrampsBSDDB
|
||||||
from QuestionDialog import ErrorDialog
|
from QuestionDialog import ErrorDialog
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
@ -47,7 +47,7 @@ def exportData(database, filename, person=None, callback=None, cl=False):
|
|||||||
|
|
||||||
filename = os.path.normpath(filename)
|
filename = os.path.normpath(filename)
|
||||||
|
|
||||||
new_database = GrampsBSDDB.GrampsBSDDB()
|
new_database = GrampsBSDDB()
|
||||||
try:
|
try:
|
||||||
new_database.load(filename,callback)
|
new_database.load(filename,callback)
|
||||||
except:
|
except:
|
56
src/GrampsDb/__init__.py
Normal file
56
src/GrampsDb/__init__.py
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
#
|
||||||
|
# Gramps - a GTK+/GNOME based genealogy program
|
||||||
|
#
|
||||||
|
# Copyright (C) 2004-2005 Donald N. Allingham
|
||||||
|
#
|
||||||
|
# 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$
|
||||||
|
|
||||||
|
"""
|
||||||
|
This package implements the GrampsDb database. It provides a number
|
||||||
|
of different backends for different storage mechanisms.
|
||||||
|
|
||||||
|
A number of importers and exporters are provided to convert between
|
||||||
|
the different backend formats.
|
||||||
|
|
||||||
|
To obtain a class that implements the backend required you should use the
|
||||||
|
gramps_db_factory method, likewise for writers use the gramps_db_writer_factory
|
||||||
|
method and for readers use the gramps_db_reader_factory method. For information
|
||||||
|
on using these factories see the _GrampsDbFactories.py file comments.
|
||||||
|
|
||||||
|
The package also contains GrampsDBCallback which provides signal/slot type
|
||||||
|
functionality to allow objects to hook into signals that are generated from
|
||||||
|
the database objects. Read the comments in _GrampsDBCallback.py for more
|
||||||
|
information.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from _GrampsDbBase import DbState
|
||||||
|
|
||||||
|
from _GrampsDbFactories import \
|
||||||
|
gramps_db_factory, \
|
||||||
|
gramps_db_writer_factory, \
|
||||||
|
gramps_db_reader_factory
|
||||||
|
|
||||||
|
|
||||||
|
from _ReadGedcom import GedcomParser
|
||||||
|
from _WriteGedcom import GedcomWriter
|
||||||
|
from _WriteXML import XmlWriter
|
||||||
|
|
||||||
|
from _GrampsDbExceptions import GrampsDbException
|
||||||
|
|
||||||
|
from _GrampsDBCallback import GrampsDBCallback
|
||||||
|
|
@ -50,7 +50,6 @@ import RelLib
|
|||||||
import Date
|
import Date
|
||||||
import DateEdit
|
import DateEdit
|
||||||
import DateHandler
|
import DateHandler
|
||||||
import GrampsDBCallback
|
|
||||||
import AutoComp
|
import AutoComp
|
||||||
|
|
||||||
|
|
||||||
|
@ -51,10 +51,7 @@ import DbPrompter
|
|||||||
import const
|
import const
|
||||||
import PluginMgr
|
import PluginMgr
|
||||||
import GrampsKeys
|
import GrampsKeys
|
||||||
import GrampsDbBase
|
import GrampsDb
|
||||||
import GrampsBSDDB
|
|
||||||
import GrampsGEDDB
|
|
||||||
import GrampsXMLDB
|
|
||||||
import GrampsCfg
|
import GrampsCfg
|
||||||
import Errors
|
import Errors
|
||||||
import DisplayTrace
|
import DisplayTrace
|
||||||
@ -556,7 +553,7 @@ class ViewManager:
|
|||||||
self.state.db.close()
|
self.state.db.close()
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
self.state.change_database(GrampsBSDDB.GrampsBSDDB())
|
self.state.change_database(GrampsDb.gramps_db_factory(app_gramps)())
|
||||||
self.read_file(filename)
|
self.read_file(filename)
|
||||||
self.state.db.request_rebuild()
|
self.state.db.request_rebuild()
|
||||||
self.change_page(None,None)
|
self.change_page(None,None)
|
||||||
@ -580,7 +577,7 @@ class ViewManager:
|
|||||||
|
|
||||||
success = False
|
success = False
|
||||||
if filetype == const.app_gramps:
|
if filetype == const.app_gramps:
|
||||||
self.state.change_database(GrampsBSDDB.GrampsBSDDB())
|
self.state.change_database(GrampsDb.gramps_db_factory(db_type = const.app_gramps)())
|
||||||
msgxml = gtk.glade.XML(const.gladeFile, "load_message","gramps")
|
msgxml = gtk.glade.XML(const.gladeFile, "load_message","gramps")
|
||||||
msg_top = msgxml.get_widget('load_message')
|
msg_top = msgxml.get_widget('load_message')
|
||||||
msg_label = msgxml.get_widget('message')
|
msg_label = msgxml.get_widget('message')
|
||||||
@ -596,12 +593,12 @@ class ViewManager:
|
|||||||
self.change_page(None,None)
|
self.change_page(None,None)
|
||||||
msg_top.destroy()
|
msg_top.destroy()
|
||||||
elif filetype == const.app_gramps_xml:
|
elif filetype == const.app_gramps_xml:
|
||||||
self.state.change_database(GrampsXMLDB.GrampsXMLDB())
|
self.state.change_database(GrampsDb.gramps_db_factory(db_type = const.app_gramps_xml)())
|
||||||
success = self.read_file(filename)
|
success = self.read_file(filename)
|
||||||
self.state.db.request_rebuild()
|
self.state.db.request_rebuild()
|
||||||
self.change_page(None,None)
|
self.change_page(None,None)
|
||||||
elif filetype == const.app_gedcom:
|
elif filetype == const.app_gedcom:
|
||||||
self.state.change_database(GrampsGEDDB.GrampsGEDDB())
|
self.state.change_database(GrampsDb.gramps_db_factory(db_type = const.app_gedcom)())
|
||||||
success = self.read_file(filename)
|
success = self.read_file(filename)
|
||||||
self.state.db.request_rebuild()
|
self.state.db.request_rebuild()
|
||||||
self.change_page(None,None)
|
self.change_page(None,None)
|
||||||
@ -781,20 +778,18 @@ class ViewManager:
|
|||||||
|
|
||||||
if filetype == const.app_gramps:
|
if filetype == const.app_gramps:
|
||||||
choose.destroy()
|
choose.destroy()
|
||||||
ReadGrdb.importData(self.state.db,filename)
|
GrampsDb.gramps_db_reader_factory(filetype)(self.state.db,filename)
|
||||||
self.parent.import_tool_callback()
|
self.parent.import_tool_callback()
|
||||||
return True
|
return True
|
||||||
elif filetype == const.app_gramps_xml:
|
elif filetype == const.app_gramps_xml:
|
||||||
choose.destroy()
|
choose.destroy()
|
||||||
import ReadXML
|
|
||||||
self.progress.show()
|
self.progress.show()
|
||||||
ReadXML.importData(self.state.db,filename,self.pulse_progressbar)
|
GrampsDb.gramps_db_reader_factory(filetype)(self.state.db,filename,self.pulse_progressbar)
|
||||||
self.progress.hide()
|
self.progress.hide()
|
||||||
return True
|
return True
|
||||||
elif filetype == const.app_gedcom:
|
elif filetype == const.app_gedcom:
|
||||||
choose.destroy()
|
choose.destroy()
|
||||||
import ReadGedcom
|
GrampsDb.gramps_db_reader_factory(filetype)(self.state.db,filename)
|
||||||
ReadGedcom.importData(self.state.db,filename)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
(the_path,the_file) = os.path.split(filename)
|
(the_path,the_file) = os.path.split(filename)
|
||||||
|
@ -38,8 +38,7 @@ import PersonView
|
|||||||
import RepositoryView
|
import RepositoryView
|
||||||
import GrampsDisplay
|
import GrampsDisplay
|
||||||
import RelLib
|
import RelLib
|
||||||
import GrampsDbBase
|
import GrampsDb
|
||||||
import GrampsBSDDB
|
|
||||||
import PedView
|
import PedView
|
||||||
import MapView
|
import MapView
|
||||||
import FamilyView
|
import FamilyView
|
||||||
@ -155,7 +154,7 @@ class Gramps:
|
|||||||
|
|
||||||
register_stock_icons()
|
register_stock_icons()
|
||||||
|
|
||||||
state = GrampsDbBase.DbState()
|
state = GrampsDb.DbState()
|
||||||
vm = ViewManager.ViewManager(state)
|
vm = ViewManager.ViewManager(state)
|
||||||
vm.register_view(PersonView.PersonView)
|
vm.register_view(PersonView.PersonView)
|
||||||
vm.register_view(FamilyView.FamilyView)
|
vm.register_view(FamilyView.FamilyView)
|
||||||
|
@ -13,14 +13,64 @@ try:
|
|||||||
set()
|
set()
|
||||||
except NameError:
|
except NameError:
|
||||||
from sets import Set as set
|
from sets import Set as set
|
||||||
|
|
||||||
import GrampsBSDDB
|
import const
|
||||||
import RelLib
|
import RelLib
|
||||||
|
|
||||||
logger = logging.getLogger('Gramps.GrampsDbBase_Test')
|
logger = logging.getLogger('Gramps.GrampsDbBase_Test')
|
||||||
|
|
||||||
from GrampsDbTestBase import GrampsDbBaseTest
|
from GrampsDbTestBase import GrampsDbBaseTest
|
||||||
|
import GrampsDb
|
||||||
|
|
||||||
|
class FactoryTest(unittest.TestCase):
|
||||||
|
"""Test the GrampsDb Factory classes."""
|
||||||
|
|
||||||
|
def test_gramps_db_factory(self):
|
||||||
|
"""test than gramps_db_factory returns the correct classes."""
|
||||||
|
|
||||||
|
cls = GrampsDb.gramps_db_factory(db_type = const.app_gramps)
|
||||||
|
assert cls.__name__ == "GrampsBSDDB", \
|
||||||
|
"Returned class is %s " % str(cls.__class__.__name__)
|
||||||
|
|
||||||
|
cls = GrampsDb.gramps_db_factory(db_type = const.app_gramps_xml)
|
||||||
|
assert cls.__name__ == "GrampsXMLDB", \
|
||||||
|
"Returned class is %s " % str(cls.__class__.__name__)
|
||||||
|
|
||||||
|
cls = GrampsDb.gramps_db_factory(db_type = const.app_gedcom)
|
||||||
|
assert cls.__name__ == "GrampsGEDDB", \
|
||||||
|
"Returned class is %s " % str(cls.__class__.__name__)
|
||||||
|
|
||||||
|
self.assertRaises(GrampsDb.GrampsDbException, GrampsDb.gramps_db_factory, "gibberish")
|
||||||
|
|
||||||
|
def test_gramps_db_writer_factory(self):
|
||||||
|
"""Test that gramps_db_writer_factory returns the correct method."""
|
||||||
|
|
||||||
|
md = GrampsDb.gramps_db_writer_factory(db_type = const.app_gramps)
|
||||||
|
assert callable(md), "Returned method is %s " % str(md)
|
||||||
|
|
||||||
|
md = GrampsDb.gramps_db_writer_factory(db_type = const.app_gramps_xml)
|
||||||
|
assert callable(md), "Returned method is %s " % str(md)
|
||||||
|
|
||||||
|
md = GrampsDb.gramps_db_writer_factory(db_type = const.app_gedcom)
|
||||||
|
assert callable(md), "Returned method is %s " % str(md)
|
||||||
|
|
||||||
|
self.assertRaises(GrampsDb.GrampsDbException, GrampsDb.gramps_db_writer_factory, "gibberish")
|
||||||
|
|
||||||
|
def test_gramps_db_reader_factory(self):
|
||||||
|
"""Test that gramps_db_reader_factory returns the correct method."""
|
||||||
|
|
||||||
|
md = GrampsDb.gramps_db_reader_factory(db_type = const.app_gramps)
|
||||||
|
assert callable(md), "Returned method is %s " % str(md)
|
||||||
|
|
||||||
|
md = GrampsDb.gramps_db_reader_factory(db_type = const.app_gramps_xml)
|
||||||
|
assert callable(md), "Returned method is %s " % str(md)
|
||||||
|
|
||||||
|
md = GrampsDb.gramps_db_reader_factory(db_type = const.app_gedcom)
|
||||||
|
assert callable(md), "Returned method is %s " % str(md)
|
||||||
|
|
||||||
|
self.assertRaises(GrampsDb.GrampsDbException, GrampsDb.gramps_db_reader_factory, "gibberish")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ReferenceMapTest (GrampsDbBaseTest):
|
class ReferenceMapTest (GrampsDbBaseTest):
|
||||||
"""Test methods on the GrampsDbBase class that are related to the reference_map
|
"""Test methods on the GrampsDbBase class that are related to the reference_map
|
||||||
@ -180,6 +230,7 @@ class ReferenceMapTest (GrampsDbBaseTest):
|
|||||||
|
|
||||||
def testSuite():
|
def testSuite():
|
||||||
suite = unittest.makeSuite(ReferenceMapTest,'test')
|
suite = unittest.makeSuite(ReferenceMapTest,'test')
|
||||||
|
suite.addTests(unittest.makeSuite(FactoryTest,'test'))
|
||||||
return suite
|
return suite
|
||||||
|
|
||||||
def perfSuite():
|
def perfSuite():
|
@ -14,7 +14,8 @@ try:
|
|||||||
except NameError:
|
except NameError:
|
||||||
from sets import Set as set
|
from sets import Set as set
|
||||||
|
|
||||||
import GrampsBSDDB
|
import GrampsDb
|
||||||
|
import const
|
||||||
import RelLib
|
import RelLib
|
||||||
|
|
||||||
logger = logging.getLogger('Gramps.GrampsDbTestBase')
|
logger = logging.getLogger('Gramps.GrampsDbTestBase')
|
||||||
@ -27,7 +28,7 @@ class GrampsDbBaseTest(unittest.TestCase):
|
|||||||
self._tmpdir = tempfile.mkdtemp()
|
self._tmpdir = tempfile.mkdtemp()
|
||||||
self._filename = os.path.join(self._tmpdir,'test.grdb')
|
self._filename = os.path.join(self._tmpdir,'test.grdb')
|
||||||
|
|
||||||
self._db = GrampsBSDDB.GrampsBSDDB()
|
self._db = GrampsDb.gramps_db_factory(const.app_gramps)()
|
||||||
self._db.load(self._filename,
|
self._db.load(self._filename,
|
||||||
None, # callback
|
None, # callback
|
||||||
"w")
|
"w")
|
@ -7,7 +7,6 @@ import time
|
|||||||
import traceback
|
import traceback
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
sys.path.append('../src')
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
set()
|
set()
|
||||||
@ -19,9 +18,8 @@ import RelLib
|
|||||||
|
|
||||||
logger = logging.getLogger('Gramps.RelLib_Test')
|
logger = logging.getLogger('Gramps.RelLib_Test')
|
||||||
|
|
||||||
from GrampsDbTestBase import GrampsDbBaseTest
|
|
||||||
|
|
||||||
class PrimaryObjectTest (GrampsDbBaseTest):
|
class PrimaryObjectTest (unittest.TestCase):
|
||||||
"""Test methods on the PrimaryObject class"""
|
"""Test methods on the PrimaryObject class"""
|
||||||
|
|
||||||
|
|
@ -5,9 +5,12 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
|
sys.path.append('../src')
|
||||||
|
|
||||||
def make_parser():
|
def make_parser():
|
||||||
usage = "usage: %prog [options]"
|
usage = "usage: %prog [options]"
|
||||||
parser = OptionParser(usage)
|
parser = OptionParser(usage)
|
||||||
@ -19,18 +22,29 @@ def make_parser():
|
|||||||
|
|
||||||
|
|
||||||
def getTestSuites():
|
def getTestSuites():
|
||||||
|
# Sorry about this line, but it is the easiest way of doing it.
|
||||||
|
# It just walks the filetree from '.' downwards and returns
|
||||||
|
# a tuple per directory of (dirpatch,filelist) if the directory
|
||||||
|
# contains any test files.
|
||||||
|
|
||||||
test_modules = [ i for i in os.listdir('.') if i[-8:] == "_Test.py" ]
|
paths = [(f[0],f[2]) for f in os.walk('.') \
|
||||||
|
if len ([i for i in f[2] \
|
||||||
|
if i[-8:] == "_Test.py"]) ]
|
||||||
|
|
||||||
test_suites = []
|
for (dir,test_modules) in paths:
|
||||||
perf_suites = []
|
sys.path.append(dir)
|
||||||
for module in test_modules:
|
|
||||||
mod = __import__(module[:-3])
|
test_suites = []
|
||||||
test_suites.append(mod.testSuite())
|
perf_suites = []
|
||||||
try:
|
for module in test_modules:
|
||||||
perf_suites.append(mod.perfSuite())
|
if module[-8:] != "_Test.py":
|
||||||
except:
|
break
|
||||||
pass
|
mod = __import__(module[:-3])
|
||||||
|
test_suites.append(mod.testSuite())
|
||||||
|
try:
|
||||||
|
perf_suites.append(mod.perfSuite())
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
return (test_suites,perf_suites)
|
return (test_suites,perf_suites)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user