From 99febc759fd88edf07401983098fc2df8bd6230f Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Mon, 8 Oct 2007 21:19:32 +0000 Subject: [PATCH] * various: cleanup 2007-10-08 Don Allingham svn: r9109 --- ChangeLog | 3 + src/DisplayModels/_PeopleModel.py | 2 +- src/GrampsDb/Makefile.am | 12 +- src/GrampsDb/__init__.py | 12 - src/GrampsDbUtils/_ReadXML.py | 2 +- src/ProgressDialog.py | 6 +- src/ViewManager.py | 2 +- src/gen/db/Makefile.am | 1 - src/gen/db/base.py | 28 +-- src/gen/db/iterator.py | 2 +- src/gen/lib/date.py | 220 +++++++++--------- src/gen/utils/Makefile.am | 6 +- src/gen/utils/__init__.py | 3 + src/gen/{db => utils}/callback.py | 27 +-- src/gen/{db => utils}/longop.py | 0 .../utils/progressmon.py} | 8 +- 16 files changed, 156 insertions(+), 178 deletions(-) rename src/gen/{db => utils}/callback.py (97%) rename src/gen/{db => utils}/longop.py (100%) rename src/{GrampsDb/_ProgressMonitor.py => gen/utils/progressmon.py} (96%) diff --git a/ChangeLog b/ChangeLog index 6601b27c1..502e74706 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2007-10-08 Don Allingham + * various: cleanup + 2007-10-08 Don Allingham * src/gen/lib/note.py: make independent of MarkupText.py diff --git a/src/DisplayModels/_PeopleModel.py b/src/DisplayModels/_PeopleModel.py index 9122788f6..3b8e112be 100644 --- a/src/DisplayModels/_PeopleModel.py +++ b/src/DisplayModels/_PeopleModel.py @@ -65,7 +65,7 @@ import DateHandler import ToolTips import GrampsLocale import Config -from gen.db.longop import LongOpStatus +from gen.utils.longop import LongOpStatus from Filters import SearchFilter, ExactSearchFilter from Lru import LRU diff --git a/src/GrampsDb/Makefile.am b/src/GrampsDb/Makefile.am index 2761fe8e9..8872506ba 100644 --- a/src/GrampsDb/Makefile.am +++ b/src/GrampsDb/Makefile.am @@ -6,22 +6,12 @@ pkgdatadir = $(datadir)/@PACKAGE@/GrampsDb pkgdata_PYTHON = \ - _CursorIterator.py \ - _DbUtils.py \ - _GrampsBSDDB.py\ - _GrampsCursor.py\ - _GrampsDbBase.py\ - _GrampsDBCallback.py\ - _GrampsDbConst.py\ _GrampsDBDir.py \ - _GrampsDbExceptions.py\ _GrampsDbFactories.py\ _GrampsDbWriteXML.py \ _GrampsGEDDB.py\ _GrampsInMemDB.py\ - __init__.py\ - _LongOpStatus.py\ - _ProgressMonitor.py + __init__.py pkgpyexecdir = @pkgpyexecdir@/GrampsDb pkgpythondir = @pkgpythondir@/GrampsDb diff --git a/src/GrampsDb/__init__.py b/src/GrampsDb/__init__.py index f51b23e0b..862af6f6b 100644 --- a/src/GrampsDb/__init__.py +++ b/src/GrampsDb/__init__.py @@ -38,21 +38,9 @@ the database objects. Read the comments in _GrampsDBCallback.py for more information. """ -#from _GrampsDbBase import GrampsDbBase - from _GrampsDbFactories import gramps_db_factory -#from _GrampsDbExceptions import * - -#from _GrampsDBCallback import GrampsDBCallback - -#from _DbUtils import * - -#import _GrampsDbConst as GrampsDbConst - from _GrampsDbWriteXML import GrampsDbXmlWriter, \ exportData, quick_write -#from _LongOpStatus import LongOpStatus -from _ProgressMonitor import ProgressMonitor diff --git a/src/GrampsDbUtils/_ReadXML.py b/src/GrampsDbUtils/_ReadXML.py index dfd9d75d6..22edc1136 100644 --- a/src/GrampsDbUtils/_ReadXML.py +++ b/src/GrampsDbUtils/_ReadXML.py @@ -45,7 +45,7 @@ import const import Utils import DateHandler from BasicUtils import name_displayer -from GrampsDb._GrampsDbConst import \ +from gen.db.dbconst import \ PERSON_KEY, FAMILY_KEY, SOURCE_KEY, EVENT_KEY, \ MEDIA_KEY, PLACE_KEY, REPOSITORY_KEY, NOTE_KEY from BasicUtils import UpdateCallback diff --git a/src/ProgressDialog.py b/src/ProgressDialog.py index 6afa3d032..ae81d03cd 100644 --- a/src/ProgressDialog.py +++ b/src/ProgressDialog.py @@ -12,7 +12,7 @@ class _GtkProgressBar(gtk.VBox): def __init__(self, long_op_status): """@param long_op_status: the status of the operation. - @type long_op_status: L{GrampsDb.LongOpStatus} + @type long_op_status: L{gen.utils.LongOpStatus} """ gtk.VBox.__init__(self) @@ -91,7 +91,7 @@ class GtkProgressDialog(gtk.Dialog): """Add a new status object to the progress dialog. @param long_op_status: the status object. - @type long_op_status: L{GrampsDb.LongOpStatus} + @type long_op_status: L{gen.utils.LongOpStatus} @return: a key that can be used as the L{pbar_idx} to the other methods. @rtype: int @@ -153,7 +153,7 @@ class GtkProgressDialog(gtk.Dialog): if __name__ == '__main__': import time - from GrampsDb import LongOpStatus, ProgressMonitor + from gen.utils import LongOpStatus, ProgressMonitor def test(a, b): d = ProgressMonitor(GtkProgressDialog) diff --git a/src/ViewManager.py b/src/ViewManager.py index aafe03ec9..5ee4349a6 100644 --- a/src/ViewManager.py +++ b/src/ViewManager.py @@ -76,7 +76,7 @@ import GrampsWidgets import UndoHistory from DbLoader import DbLoader import GrampsDisplay -from GrampsDb import ProgressMonitor +from gen.utils import ProgressMonitor import gen.db import ProgressDialog diff --git a/src/gen/db/Makefile.am b/src/gen/db/Makefile.am index 8deffb1b1..d831fd228 100644 --- a/src/gen/db/Makefile.am +++ b/src/gen/db/Makefile.am @@ -8,7 +8,6 @@ pkgdatadir = $(datadir)/@PACKAGE@/db pkgdata_PYTHON = \ __init__.py\ base.py \ - callback.py \ cursor.py \ dbconst.py \ dbdir.py \ diff --git a/src/gen/db/base.py b/src/gen/db/base.py index 8a1d48ae9..be22d3869 100644 --- a/src/gen/db/base.py +++ b/src/gen/db/base.py @@ -438,25 +438,17 @@ class GrampsDbBase(GrampsDBCallback): self.update_reference_map(obj, transaction) - try: - if transaction.batch: - data_map[handle] = obj.serialize() - old_data = None + if transaction.batch: + data_map[handle] = obj.serialize() + old_data = None + else: + old_data = data_map.get(handle) + new_data = obj.serialize() + transaction.add(key, handle, old_data, new_data) + if old_data: + update_list.append((handle, new_data)) else: - old_data = data_map.get(handle) - new_data = obj.serialize() - transaction.add(key, handle, old_data, new_data) - if old_data: - update_list.append((handle, new_data)) - else: - add_list.append((handle, new_data)) - except db.DBNoSpaceError, msg: - from QuestionDialog import ErrorDialog - - ErrorDialog(_("Out of disk space"), - _("Your data cannot be saved because you are out " - "of disk space. Please free up some disk space " - "and try again.\n\n%s") % msg[1]) + add_list.append((handle, new_data)) return old_data def commit_person(self, person, transaction, change_time=None): diff --git a/src/gen/db/iterator.py b/src/gen/db/iterator.py index 7ee6e87bd..9126edd41 100644 --- a/src/gen/db/iterator.py +++ b/src/gen/db/iterator.py @@ -1,4 +1,4 @@ -from longop import LongOpStatus +from ..utils import LongOpStatus class CursorIterator(object): diff --git a/src/gen/lib/date.py b/src/gen/lib/date.py index 59ff703cc..dae157a3c 100644 --- a/src/gen/lib/date.py +++ b/src/gen/lib/date.py @@ -759,114 +759,114 @@ class Date: and self.get_year_valid() and self.get_month_valid() \ and self.get_day_valid() -if __name__ == "__main__": - # Test function. Call it as follows from the command line (so as to find - # imported modules): - # export PYTHONPATH=/path/to/gramps/src python src/gen.lib/_Date.py - # - from DateHandler import _DateParser - df = _DateParser.DateParser() # date factory - def test_date(d1, d2, expected1, expected2 = None): - if expected2 == None: - expected2 = expected1 - pos1 = 1 - if expected1 : - pos1 = 0 - pos2 = 1 - if expected2 : - pos2 = 0 - date1 = df.parse(d1) - date2 = df.parse(d2) - wrong = 0 - print "Testing '%s' and '%s'" % (d1, d2) - val = date2.match(date1) - try: - assert(val == expected1) - print [" correct: they match!" - ," correct: they do not match!"][pos1] - except: - print " Wrong! got %s" % (not expected1) - wrong += 1 - val = date1.match(date2) - try: - assert(val == expected2) - print [" correct: they match!" - ," correct: they do not match!"][pos2] - except: - print " Wrong! got %s" % (not expected2) - wrong += 1 - return {"incorrect": wrong, "correct": 2 - wrong } +# if __name__ == "__main__": +# # Test function. Call it as follows from the command line (so as to find +# # imported modules): +# # export PYTHONPATH=/path/to/gramps/src python src/gen.lib/_Date.py +# # +# from DateHandler import _DateParser +# df = _DateParser.DateParser() # date factory +# def test_date(d1, d2, expected1, expected2 = None): +# if expected2 == None: +# expected2 = expected1 +# pos1 = 1 +# if expected1 : +# pos1 = 0 +# pos2 = 1 +# if expected2 : +# pos2 = 0 +# date1 = df.parse(d1) +# date2 = df.parse(d2) +# wrong = 0 +# print "Testing '%s' and '%s'" % (d1, d2) +# val = date2.match(date1) +# try: +# assert(val == expected1) +# print [" correct: they match!" +# ," correct: they do not match!"][pos1] +# except: +# print " Wrong! got %s" % (not expected1) +# wrong += 1 +# val = date1.match(date2) +# try: +# assert(val == expected2) +# print [" correct: they match!" +# ," correct: they do not match!"][pos2] +# except: +# print " Wrong! got %s" % (not expected2) +# wrong += 1 +# return {"incorrect": wrong, "correct": 2 - wrong } - stats = {'incorrect':0, 'correct':0} - # create a bunch of tests: - # most are symmetric: #date1, date2, does d1 match d2? does d2 match d1? - tests = [("before 1960", "before 1961", True), - ("before 1960", "before 1960", True), - ("before 1961", "before 1961", True), - ("jan 1, 1960", "jan 1, 1960", True), - ("dec 31, 1959", "dec 31, 1959", True), - ("before 1960", "jan 1, 1960", False), - ("before 1960", "dec 31, 1959", True), - ("abt 1960", "1960", True), - ("abt 1960", "before 1960", True), - ("1960", "1960", True), - ("1960", "after 1960", False), - ("1960", "before 1960", False), - ("abt 1960", "abt 1960", True), - ("before 1960", "after 1960", False), - ("after jan 1, 1900", "jan 2, 1900", True), - ("abt jan 1, 1900", "jan 1, 1900", True), - ("from 1950 to 1955", "1950", True), - ("from 1950 to 1955", "1951", True), - ("from 1950 to 1955", "1952", True), - ("from 1950 to 1955", "1953", True), - ("from 1950 to 1955", "1954", True), - ("from 1950 to 1955", "1955", True), - ("from 1950 to 1955", "1956", False), - ("from 1950 to 1955", "dec 31, 1955", True), - ("from 1950 to 1955", "jan 1, 1955", True), - ("from 1950 to 1955", "dec 31, 1949", False), - ("from 1950 to 1955", "jan 1, 1956", False), - ("after jul 4, 1980", "jul 4, 1980", False), - ("after jul 4, 1980", "before jul 4, 1980", False), - ("after jul 4, 1980", "about jul 4, 1980", True), - ("after jul 4, 1980", "after jul 4, 1980", True), - ("between 1750 and 1752", "1750", True), - ("between 1750 and 1752", "about 1750", True), - ("between 1750 and 1752", "between 1749 and 1750", True), - ("between 1750 and 1752", "1749", False), - ("invalid date", "invalid date", True), - ("invalid date", "invalid", False, True), - ("invalid date 1", "invalid date 2", False), - ("abt jan 1, 2000", "dec 31, 1999", True), - ("jan 1, 2000", "dec 31, 1999", False), - ("aft jan 1, 2000", "dec 31, 1999", False), - ("after jan 1, 2000", "after dec 31, 1999", True), - ("after dec 31, 1999", "after jan 1, 2000", True), - ("1 31, 2000", "jan 1, 2000", False), - ("dec 31, 1999", "jan 1, 2000", False), - ("jan 1, 2000", "before dec 31, 1999", False), - ("aft jan 1, 2000", "before dec 31, 1999", False), - ("before jan 1, 2000", "after dec 31, 1999", False), - ("jan 1, 2000/1", "jan 1, 2000", False), - ("jan 1, 2000/1", "jan 1, 2001", True), - ("about 1984", "about 2005", False), - ("about 1990", "about 2005", True), - ("about 2007", "about 2006", True), - ("about 1995", "after 2000", True), - ("about 1995", "after 2005", False), - ("about 2007", "about 2003", True), - ("before 2007", "2000", True), - # different calendar, same date - ("Aug 3, 1982", "14 Thermidor 190 (French Republican)", True), - ("after Aug 3, 1982", - "before 14 Thermidor 190 (French Republican)", False), - ("ab cd", "54 ab cd 2000", True, False), - ] - # test them: - for testdata in tests: - results = test_date(*testdata) - for result in results: - stats[result] += results[result] - for result in stats: - print result, stats[result] +# stats = {'incorrect':0, 'correct':0} +# # create a bunch of tests: +# # most are symmetric: #date1, date2, does d1 match d2? does d2 match d1? +# tests = [("before 1960", "before 1961", True), +# ("before 1960", "before 1960", True), +# ("before 1961", "before 1961", True), +# ("jan 1, 1960", "jan 1, 1960", True), +# ("dec 31, 1959", "dec 31, 1959", True), +# ("before 1960", "jan 1, 1960", False), +# ("before 1960", "dec 31, 1959", True), +# ("abt 1960", "1960", True), +# ("abt 1960", "before 1960", True), +# ("1960", "1960", True), +# ("1960", "after 1960", False), +# ("1960", "before 1960", False), +# ("abt 1960", "abt 1960", True), +# ("before 1960", "after 1960", False), +# ("after jan 1, 1900", "jan 2, 1900", True), +# ("abt jan 1, 1900", "jan 1, 1900", True), +# ("from 1950 to 1955", "1950", True), +# ("from 1950 to 1955", "1951", True), +# ("from 1950 to 1955", "1952", True), +# ("from 1950 to 1955", "1953", True), +# ("from 1950 to 1955", "1954", True), +# ("from 1950 to 1955", "1955", True), +# ("from 1950 to 1955", "1956", False), +# ("from 1950 to 1955", "dec 31, 1955", True), +# ("from 1950 to 1955", "jan 1, 1955", True), +# ("from 1950 to 1955", "dec 31, 1949", False), +# ("from 1950 to 1955", "jan 1, 1956", False), +# ("after jul 4, 1980", "jul 4, 1980", False), +# ("after jul 4, 1980", "before jul 4, 1980", False), +# ("after jul 4, 1980", "about jul 4, 1980", True), +# ("after jul 4, 1980", "after jul 4, 1980", True), +# ("between 1750 and 1752", "1750", True), +# ("between 1750 and 1752", "about 1750", True), +# ("between 1750 and 1752", "between 1749 and 1750", True), +# ("between 1750 and 1752", "1749", False), +# ("invalid date", "invalid date", True), +# ("invalid date", "invalid", False, True), +# ("invalid date 1", "invalid date 2", False), +# ("abt jan 1, 2000", "dec 31, 1999", True), +# ("jan 1, 2000", "dec 31, 1999", False), +# ("aft jan 1, 2000", "dec 31, 1999", False), +# ("after jan 1, 2000", "after dec 31, 1999", True), +# ("after dec 31, 1999", "after jan 1, 2000", True), +# ("1 31, 2000", "jan 1, 2000", False), +# ("dec 31, 1999", "jan 1, 2000", False), +# ("jan 1, 2000", "before dec 31, 1999", False), +# ("aft jan 1, 2000", "before dec 31, 1999", False), +# ("before jan 1, 2000", "after dec 31, 1999", False), +# ("jan 1, 2000/1", "jan 1, 2000", False), +# ("jan 1, 2000/1", "jan 1, 2001", True), +# ("about 1984", "about 2005", False), +# ("about 1990", "about 2005", True), +# ("about 2007", "about 2006", True), +# ("about 1995", "after 2000", True), +# ("about 1995", "after 2005", False), +# ("about 2007", "about 2003", True), +# ("before 2007", "2000", True), +# # different calendar, same date +# ("Aug 3, 1982", "14 Thermidor 190 (French Republican)", True), +# ("after Aug 3, 1982", +# "before 14 Thermidor 190 (French Republican)", False), +# ("ab cd", "54 ab cd 2000", True, False), +# ] +# # test them: +# for testdata in tests: +# results = test_date(*testdata) +# for result in results: +# stats[result] += results[result] +# for result in stats: +# print result, stats[result] diff --git a/src/gen/utils/Makefile.am b/src/gen/utils/Makefile.am index 3fed5e751..3fb194880 100644 --- a/src/gen/utils/Makefile.am +++ b/src/gen/utils/Makefile.am @@ -7,8 +7,10 @@ pkgdatadir = $(datadir)/@PACKAGE@/utils pkgdata_PYTHON = \ __init__.py \ - dbutils.py - + dbutils.py \ + callback.py \ + progressmon.py \ + longop.py pkgpyexecdir = @pkgpyexecdir@/utils pkgpythondir = @pkgpythondir@/utils diff --git a/src/gen/utils/__init__.py b/src/gen/utils/__init__.py index 7c911a4c9..b4749848d 100644 --- a/src/gen/utils/__init__.py +++ b/src/gen/utils/__init__.py @@ -21,4 +21,7 @@ __version__ = "$Revision: $" from dbutils import * +from progressmon import ProgressMonitor +from longop import LongOpStatus +from callback import GrampsDBCallback diff --git a/src/gen/db/callback.py b/src/gen/utils/callback.py similarity index 97% rename from src/gen/db/callback.py rename to src/gen/utils/callback.py index 345bd3324..c1a8d10e6 100644 --- a/src/gen/db/callback.py +++ b/src/gen/utils/callback.py @@ -412,10 +412,11 @@ class GrampsDBCallback(object): cb[0](fn[1],*args) elif type(fn) == types.FunctionType or \ type(fn) == types.MethodType: # call func - try: - fn(*args) - except Errors.DbError: - display_error() + fn(*args) +# try: +# fn(*args) +# except Errors.DbError: +# display_error() else: self._warn("Badly formed entry in callback map.\n") except: @@ -464,15 +465,15 @@ class GrampsDBCallback(object): enable_all_signals = classmethod(__enable_all_signals) -def display_error(): - from QuestionDialog import ErrorDialog - ErrorDialog( - _('Database error'), - _('A problem as been detected in your database. ' - 'This is probably caused by opening a database that was ' - 'created with one transaction setting when the database was ' - 'created with another, or by moving a non-portable database ' - 'to a different machine.')) +# def display_error(): +# from QuestionDialog import ErrorDialog +# ErrorDialog( +# _('Database error'), +# _('A problem as been detected in your database. ' +# 'This is probably caused by opening a database that was ' +# 'created with one transaction setting when the database was ' +# 'created with another, or by moving a non-portable database ' +# 'to a different machine.')) #------------------------------------------------------------------------- # diff --git a/src/gen/db/longop.py b/src/gen/utils/longop.py similarity index 100% rename from src/gen/db/longop.py rename to src/gen/utils/longop.py diff --git a/src/GrampsDb/_ProgressMonitor.py b/src/gen/utils/progressmon.py similarity index 96% rename from src/GrampsDb/_ProgressMonitor.py rename to src/gen/utils/progressmon.py index c9b943785..a3b404f20 100644 --- a/src/GrampsDb/_ProgressMonitor.py +++ b/src/gen/utils/progressmon.py @@ -23,7 +23,7 @@ This module provides a progess dialog for displaying the status of long running operations. """ import logging -log = logging.getLogger(".GrampsDb") +log = logging.getLogger(".gen") from gettext import gettext as _ @@ -34,7 +34,7 @@ class _StatusObjectFacade(object): def __init__(self, status_obj, heartbeat_cb_id=None, end_cb_id=None): """ @param status_obj: - @type status_obj: L{GrampsDb.LongOpStatus} + @type status_obj: L{gen.utils.LongOpStatus} @param heartbeat_cb_id: (default: None) @type heartbeat_cb_id: int @@ -51,7 +51,7 @@ class _StatusObjectFacade(object): class ProgressMonitor(object): """A dialog for displaying the status of long running operations. - It will work with L{GrampsDb.LongOpStatus} objects to track the + It will work with L{gen.utils.LongOpStatus} objects to track the progress of long running operations. If the operations is going to take longer than I{popup_time} it will pop up a dialog with a progress bar so that the user gets some feedback about what is @@ -102,7 +102,7 @@ class ProgressMonitor(object): """Add a new status object to the progress dialog. @param op_status: the status object. - @type op_status: L{GrampsDb.LongOpStatus} + @type op_status: L{gen.utils.LongOpStatus} """ log.debug("adding op to Progress Monitor")