diff --git a/gramps/gen/datehandler/test/datehandler_test.py b/gramps/gen/datehandler/test/datehandler_test.py index eb3eabd3d..9779d7b0f 100644 --- a/gramps/gen/datehandler/test/datehandler_test.py +++ b/gramps/gen/datehandler/test/datehandler_test.py @@ -63,7 +63,7 @@ class DateHandlerTest(unittest.TestCase): self.assertTrue(test_date.is_equal(new_date), "{} -> {}\n{} -> {}".format( test_date, new_date, - test_date.to_struct(), new_date.to_struct())) + test_date.__dict__, new_date.__dict__)) def test_simple(self): diff --git a/gramps/gen/lib/date.py b/gramps/gen/lib/date.py index 713fb5946..03664d098 100644 --- a/gramps/gen/lib/date.py +++ b/gramps/gen/lib/date.py @@ -1652,7 +1652,7 @@ class Date: self.__compare(sanity.dateval, value, year_delta) except DateError as err: LOG.debug("Sanity check failed - self: {}, sanity: {}". - format(self.to_struct(), sanity.to_struct())) + format(self.__dict__, sanity.__dict__)) err.date = self raise diff --git a/gramps/gen/lib/test/date_test.py b/gramps/gen/lib/test/date_test.py index e26ac426a..c6a6611e1 100644 --- a/gramps/gen/lib/test/date_test.py +++ b/gramps/gen/lib/test/date_test.py @@ -245,7 +245,8 @@ class ParserDateTest(BaseDateTest): "dateval fails is_equal in format %d:\n" " '%s' != '%s'\n" " '%s' != '%s'\n" % - (date_format, dateval, ndate, dateval.to_struct(), ndate.to_struct())) + (date_format, dateval, ndate, + dateval.__dict__, ndate.__dict__)) def test_basic(self): self.do_case("basic test") @@ -380,7 +381,7 @@ class MatchDateTest(BaseDateTest): d1, ("did not match" if expected else "matched"), d2, - date1.to_struct(), date2.to_struct())) + date1.__dict__, date2.__dict__)) def test_match(self): for testdata in self.tests: diff --git a/gramps/gen/merge/diff.py b/gramps/gen/merge/diff.py index c72923281..8340ee8fd 100644 --- a/gramps/gen/merge/diff.py +++ b/gramps/gen/merge/diff.py @@ -22,11 +22,20 @@ This package implements an object difference engine. """ +import json + from gramps.cli.user import User from ..db.utils import import_as_dict +from ..lib.serialize import to_json from ..const import GRAMPS_LOCALE as glocale _ = glocale.translation.gettext +def to_struct(obj): + """ + Convert an object into a struct. + """ + return json.loads(to_json(obj)) + def diff_dates(json1, json2): """ Compare two json date objects. Returns True if different. @@ -110,7 +119,7 @@ def diff_dbs(db1, db2, user=None): if handles1[p1] == handles2[p2]: # in both item1 = db1.get_table_func(item,"handle_func")(handles1[p1]) item2 = db2.get_table_func(item,"handle_func")(handles2[p2]) - diff = diff_items(item, item1.to_struct(), item2.to_struct()) + diff = diff_items(item, to_struct(item1), to_struct(item2)) if diff: diffs += [(item, item1, item2)] # else same! diff --git a/gramps/gui/editors/editdate.py b/gramps/gui/editors/editdate.py index d6dc3abc1..eb91e1948 100644 --- a/gramps/gui/editors/editdate.py +++ b/gramps/gui/editors/editdate.py @@ -258,7 +258,7 @@ class EditDate(ManagedWindow): newyear=the_newyear) # didn't throw yet? self.validated_date = d - LOG.debug("validated_date set to: {0}".format(d.to_struct())) + LOG.debug("validated_date set to: {0}".format(d.__dict__)) self.ok_button.set_sensitive(1) self.calendar_box.set_sensitive(1) return True diff --git a/gramps/plugins/importer/importgeneweb.py b/gramps/plugins/importer/importgeneweb.py index 201f132c0..3afba25dd 100644 --- a/gramps/plugins/importer/importgeneweb.py +++ b/gramps/plugins/importer/importgeneweb.py @@ -909,7 +909,7 @@ class GeneWebParser: LOG.warning(_( "Invalid date {date} in {gw_snippet}, " "preserving date as text." - ).format(date=e.date.to_struct(), gw_snippet=field)) + ).format(date=e.date.__dict__, gw_snippet=field)) date.set(modifier=Date.MOD_TEXTONLY, text=field) return date else: diff --git a/gramps/plugins/importer/importxml.py b/gramps/plugins/importer/importxml.py index 20b068168..7ccc5fd5e 100644 --- a/gramps/plugins/importer/importxml.py +++ b/gramps/plugins/importer/importxml.py @@ -2499,7 +2499,7 @@ class GrampsParser(UpdateCallback): # TRANSLATORS: leave the {date} and {xml} untranslated in the format string, # but you may re-order them if needed. LOG.warning(_("Invalid date {date} in XML {xml}, preserving XML as text" - ).format(date=date_error.date.to_struct(), xml=xml)) + ).format(date=date_error.date.__dict__, xml=xml)) date_value.set(modifier=Date.MOD_TEXTONLY, text=xml) def start_datestr(self, attrs): diff --git a/gramps/plugins/test/test_imports.py b/gramps/plugins/test/test_imports.py index 1b1507243..0d6ec18d1 100644 --- a/gramps/plugins/test/test_imports.py +++ b/gramps/plugins/test/test_imports.py @@ -30,7 +30,7 @@ from unittest.mock import patch #import logging from gramps.gen.db.utils import import_as_dict -from gramps.gen.merge.diff import diff_dbs +from gramps.gen.merge.diff import diff_dbs, to_struct from gramps.gen.simple import SimpleAccess from gramps.gen.utils.id import set_det_id from gramps.cli.user import User @@ -75,8 +75,8 @@ class CompleteCheck(unittest.TestCase): if diffs: for diff in diffs: obj_type, item1, item2 = diff - msg = self._report_diff(obj_type, item1.to_struct(), - item2.to_struct()) + msg = self._report_diff(obj_type, to_struct(item1), + to_struct(item2)) if msg != "": if hasattr(item1, "gramps_id"): self.msg += "%s: %s handle=%s\n" % \