From 2a608151c2563588574eca00b1b9d50680677d32 Mon Sep 17 00:00:00 2001 From: Paul Franklin Date: Sat, 3 May 2014 07:00:51 -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 | 60 +++++++++++++++++----------- gramps/gen/db/write.py | 7 +--- gramps/plugins/importer/importcsv.py | 2 +- gramps/plugins/tool/check.py | 2 +- 5 files changed, 40 insertions(+), 37 deletions(-) diff --git a/gramps/gen/db/base.py b/gramps/gen/db/base.py index 56d6b0dd6..c469c2d36 100644 --- a/gramps/gen/db/base.py +++ b/gramps/gen/db/base.py @@ -97,12 +97,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 89bdacb50..f939e5692 100644 --- a/gramps/gen/db/upgrade.py +++ b/gramps/gen/db/upgrade.py @@ -19,40 +19,52 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # -from __future__ import with_statement, unicode_literals - -import sys -import os -import re -from ..lib.markertype import MarkerType -from ..lib.tag import Tag -from ..lib.place import Place -from ..lib.placeref import PlaceRef -from ..lib.placetype import PlaceType -from ..utils.file import create_checksum -import time -import logging -LOG = logging.getLogger(".upgrade") - -from ..const import GRAMPS_LOCALE as glocale -_ = glocale.translation.gettext -from ..constfunc import cuni, UNITYPE, handle2internal - """ methods to upgrade a database from version 13 to current version """ + +#------------------------------------------------------------------------- +# +# Standard python modules +# +#------------------------------------------------------------------------- +from __future__ import with_statement, unicode_literals +import sys +import os +import re +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, handle2internal +from ..lib.markertype import MarkerType from ..lib.nameorigintype import NameOriginType +from ..lib.place import Place +from ..lib.placeref import PlaceRef +from ..lib.placetype import PlaceType +from ..lib.tag import Tag +from ..utils.file import create_checksum +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_17(self): """ Upgrade database from version 16 to 17. @@ -262,7 +274,7 @@ def get_location(loc): return location def add_place(self, name, level, parent, title): - handle = self.create_id() + handle = create_id() place = Place() place.handle = handle self.max_id += 1 @@ -831,7 +843,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() @@ -1066,7 +1078,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 cb404dff2..634beb28a 100644 --- a/gramps/gen/db/write.py +++ b/gramps/gen/db/write.py @@ -85,6 +85,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, @@ -1552,15 +1553,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 fcb640b8c..0b23d5920 100644 --- a/gramps/plugins/importer/importcsv.py +++ b/gramps/plugins/importer/importcsv.py @@ -747,7 +747,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 ca8a71997..a74e85a92 100644 --- a/gramps/plugins/tool/check.py +++ b/gramps/plugins/tool/check.py @@ -1952,7 +1952,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 '