From 753eec39609a58bf2c0a6a0fb57d4fd7d416367a Mon Sep 17 00:00:00 2001 From: Paul Franklin Date: Sat, 3 May 2014 07:00:16 -0700 Subject: [PATCH] 7582: Cannot remove a primary object having a new created backreference This removes the create_id method from gen/db/write.py, since after a recent "from __future__ import unicode_literals" (there) it started producing unicode. Instead the create_id method in gen/utils/id.py is used, as its code is essentially identical, in use in many other places -- and does not produce unicode. --- gramps/gen/db/base.py | 6 ---- gramps/gen/db/upgrade.py | 46 ++++++++++++++++++---------- gramps/gen/db/write.py | 7 ++--- gramps/plugins/importer/importcsv.py | 2 +- gramps/plugins/tool/check.py | 2 +- 5 files changed, 33 insertions(+), 30 deletions(-) diff --git a/gramps/gen/db/base.py b/gramps/gen/db/base.py index 09b700e07..ee753ef51 100644 --- a/gramps/gen/db/base.py +++ b/gramps/gen/db/base.py @@ -87,12 +87,6 @@ class DbReadBase(object): """ raise NotImplementedError - def create_id(self): - """ - Create an id - """ - raise NotImplementedError - def db_has_bm_changes(self): """ Return whethere there were bookmark changes during the session. diff --git a/gramps/gen/db/upgrade.py b/gramps/gen/db/upgrade.py index d1a8968bb..89be680e7 100644 --- a/gramps/gen/db/upgrade.py +++ b/gramps/gen/db/upgrade.py @@ -21,34 +21,46 @@ # $Id$ -from __future__ import with_statement, unicode_literals - -import sys -from ..lib.markertype import MarkerType -from ..lib.tag import Tag -import time -import logging -LOG = logging.getLogger(".upgrade") - -from ..const import GRAMPS_LOCALE as glocale -_ = glocale.translation.gettext -from ..constfunc import cuni, UNITYPE - """ methods to upgrade a database from version 13 to current version """ + +#------------------------------------------------------------------------- +# +# Standard python modules +# +#------------------------------------------------------------------------- +from __future__ import with_statement, unicode_literals +import sys +import time +import logging + from ..config import config if config.get('preferences.use-bsddb3') or sys.version_info[0] >= 3: from bsddb3 import db else: from bsddb import db -from . import BSDDBTxn + +#------------------------------------------------------------------------- +# +# Gramps modules +# +#------------------------------------------------------------------------- +from ..const import GRAMPS_LOCALE as glocale +_ = glocale.translation.gettext +from ..constfunc import cuni, UNITYPE +from ..lib.markertype import MarkerType from ..lib.nameorigintype import NameOriginType +from ..lib.tag import Tag +from ..utils.id import create_id +from . import BSDDBTxn from .write import _mkname, SURNAMES from .dbconst import (PERSON_KEY, FAMILY_KEY, EVENT_KEY, - MEDIA_KEY, PLACE_KEY, REPOSITORY_KEY, SOURCE_KEY) + MEDIA_KEY, PLACE_KEY, REPOSITORY_KEY, SOURCE_KEY) from gramps.gui.dialog import (InfoDialog) +LOG = logging.getLogger(".upgrade") + def gramps_upgrade_16(self): """Upgrade database from version 15 to 16. This upgrade converts all SourceRef child objects to Citation Primary objects. @@ -587,7 +599,7 @@ def convert_source_list_to_citation_list_16(self, source_list): citation_list = [] for source in source_list: (date, private, note_list, confidence, ref, page) = source - new_handle = self.create_id() + new_handle = create_id() new_media_list = [] new_data_map = {} new_change = time.time() @@ -820,7 +832,7 @@ def convert_marker(self, marker_field): if tag_name != '': if tag_name not in self.tags: tag = Tag() - handle = self.create_id() + handle = create_id() tag.set_handle(handle) tag.set_change_time(time.time()) tag.set_name(tag_name) diff --git a/gramps/gen/db/write.py b/gramps/gen/db/write.py index bfb7258c9..dca5dec6f 100644 --- a/gramps/gen/db/write.py +++ b/gramps/gen/db/write.py @@ -78,6 +78,7 @@ from . import (DbBsddbRead, DbWriteBase, BSDDBTxn, from .dbconst import * from ..utils.callback import Callback from ..utils.cast import conv_dbstr_to_unicode +from ..utils.id import create_id from ..updatecallback import UpdateCallback from ..errors import DbError from ..constfunc import (win, conv_to_unicode, cuni, UNITYPE, handle2internal, @@ -1369,15 +1370,11 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback): except IOError: pass - def create_id(self): - return "%08x%08x" % ( int(time.time()*10000), - self.rand.randint(0, maxsize)) - def __add_object(self, obj, transaction, find_next_func, commit_func): if find_next_func and not obj.gramps_id: obj.gramps_id = find_next_func() if not obj.handle: - obj.handle = self.create_id() + obj.handle = create_id() commit_func(obj, transaction) return obj.handle diff --git a/gramps/plugins/importer/importcsv.py b/gramps/plugins/importer/importcsv.py index 9c056b596..5b75be522 100644 --- a/gramps/plugins/importer/importcsv.py +++ b/gramps/plugins/importer/importcsv.py @@ -742,7 +742,7 @@ class CSVParser(object): id_ = self.db.fid2user_format(family_ref[1:-1]) family.set_gramps_id(id_) # add it: - family.set_handle(self.db.create_id()) + family.set_handle(create_id()) if self.default_tag: family.add_tag(self.default_tag.handle) if husband: diff --git a/gramps/plugins/tool/check.py b/gramps/plugins/tool/check.py index ab532e00d..1317c299c 100644 --- a/gramps/plugins/tool/check.py +++ b/gramps/plugins/tool/check.py @@ -1916,7 +1916,7 @@ class CheckIntegrity(object): new_citation.set_confidence_level(sourceref[3]) new_citation.set_reference_handle(sourceref[4]) new_citation.set_page(sourceref[5]) - citation_handle = Utils.create_id() + citation_handle = create_id() new_citation.set_handle(citation_handle) self.replaced_sourceref.append(handle) logging.warning(' FAIL: the source "%s" has a media '