2880: old api use in import grdb

svn: r12399
This commit is contained in:
Benny Malengier 2009-03-31 21:21:55 +00:00
parent 1b2135f49c
commit 8d080adb2f

View File

@ -68,7 +68,7 @@ from gen.plug import PluginManager, ImportPlugin
#
#-------------------------------------------------------------------------
_MINVERSION = 9
_DBVERSION = 13
_DBVERSION = 14
#--------------------------------------------------------------------------
#
@ -424,7 +424,8 @@ class GrampsBSDDB(GrampsDbBase, UpdateCallback):
# These env settings are only needed for Txn environment
self.env.set_lk_max_locks(25000)
self.env.set_lk_max_objects(25000)
self.env.set_flags(db.DB_LOG_AUTOREMOVE, 1) # clean up unused logs
self.set_auto_remove()
# The DB_PRIVATE flag must go if we ever move to multi-user setup
env_flags = db.DB_CREATE | db.DB_PRIVATE | \
@ -1639,6 +1640,8 @@ class GrampsBSDDB(GrampsDbBase, UpdateCallback):
self.gramps_upgrade_12()
if version < 13:
self.gramps_upgrade_13()
if version < 14:
self.gramps_upgrade_14()
print "Upgrade time:", int(time.time()-t), "seconds"
def gramps_upgrade_10(self):
@ -2386,7 +2389,326 @@ class GrampsBSDDB(GrampsDbBase, UpdateCallback):
print name, obj
# Return the required tuple
return (new_obj, note_handles)
def gramps_upgrade_14(self):
"""Upgrade database from version 13 to 14."""
print "Upgrading to DB version 14..."
# This upgrade modifies notes and dates
length = (len(self.note_map) + len(self.person_map) +
len(self.event_map) + len(self.family_map) +
len(self.repository_map) + len(self.media_map) +
len(self.place_map) + len(self.source_map))
self.set_total(length)
# ---------------------------------
# Modify Notes
# ---------------------------------
# replace clear text with StyledText in Notes
for handle in self.note_map.keys():
note = self.note_map[handle]
(junk_handle, gramps_id, text, format, note_type,
change, marker, private) = note
styled_text = (text, [])
new_note = (handle, gramps_id, styled_text, format, note_type,
change, marker, private)
the_txn = self.env.txn_begin()
self.note_map.put(str(handle), new_note, txn=the_txn)
the_txn.commit()
self.update()
# ---------------------------------
# Modify Event
# ---------------------------------
# update dates with newyear
for handle in self.event_map.keys():
event = self.event_map[handle]
(junk_handle, gramps_id, the_type, date, description, place,
source_list, note_list, media_list, attribute_list,
change, marker, private) = event
new_date = self.convert_date_14(date)
new_source_list = self.new_source_list_14(source_list)
new_media_list = self.new_media_list_14(media_list)
new_attribute_list = self.new_attribute_list_14(attribute_list)
new_event = (junk_handle, gramps_id, the_type, new_date,
description, place, new_source_list, note_list,
new_media_list, new_attribute_list, change,marker,private)
the_txn = self.env.txn_begin()
self.event_map.put(str(handle), new_event, txn=the_txn)
the_txn.commit()
self.update()
# ---------------------------------
# Modify Person
# ---------------------------------
# update dates with newyear
for handle in self.person_map.keys():
person = self.person_map[handle]
(junk_handle, # 0
gramps_id, # 1
gender, # 2
primary_name, # 3
alternate_names, # 4
death_ref_index, # 5
birth_ref_index, # 6
event_ref_list, # 7
family_list, # 8
parent_family_list, # 9
media_list, # 10
address_list, # 11
attribute_list, # 12
urls, # 13
lds_ord_list, # 14
psource_list, # 15
pnote_list, # 16
change, # 17
marker, # 18
pprivate, # 19
person_ref_list, # 20
) = person
new_address_list = []
for address in address_list:
(privacy, asource_list, anote_list, date, location) = address
new_date = self.convert_date_14(date)
new_asource_list = self.new_source_list_14(asource_list)
new_address_list.append((privacy, new_asource_list, anote_list,
new_date, location))
new_ord_list = []
for ldsord in lds_ord_list:
(lsource_list, lnote_list, date, type, place,
famc, temple, status, lprivate) = ldsord
new_date = self.convert_date_14(date)
new_lsource_list = self.new_source_list_14(lsource_list)
new_ord_list.append( (new_lsource_list, lnote_list, new_date, type,
place, famc, temple, status, lprivate))
new_primary_name = self.convert_name_14(primary_name)
new_alternate_names = [self.convert_name_14(name) for name
in alternate_names]
new_media_list = self.new_media_list_14(media_list)
new_psource_list = self.new_source_list_14(psource_list)
new_attribute_list = self.new_attribute_list_14(attribute_list)
new_person = (junk_handle, # 0
gramps_id, # 1
gender, # 2
new_primary_name, # 3
new_alternate_names, # 4
death_ref_index, # 5
birth_ref_index, # 6
event_ref_list, # 7
family_list, # 8
parent_family_list, # 9
new_media_list, # 10
new_address_list, # 11
new_attribute_list, # 12
urls, # 13
new_ord_list, # 14
new_psource_list, # 15
pnote_list, # 16
change, # 17
marker, # 18
pprivate, # 19
person_ref_list, # 20
)
the_txn = self.env.txn_begin()
self.person_map.put(str(handle), new_person, txn=the_txn)
the_txn.commit()
self.update()
# ---------------------------------
# Modify Family
# ---------------------------------
# update dates with newyear
for handle in self.family_map.keys():
family = self.family_map[handle]
(junk_handle, gramps_id, father_handle, mother_handle,
child_ref_list, the_type, event_ref_list, media_list,
attribute_list, lds_seal_list, source_list, note_list,
change, marker, private) = family
new_media_list = self.new_media_list_14(media_list)
new_source_list = self.new_source_list_14(source_list)
new_attribute_list = self.new_attribute_list_14(attribute_list)
new_seal_list = []
for ldsord in lds_seal_list:
(lsource_list, lnote_list, date, type, place,
famc, temple, status, lprivate) = ldsord
new_date = self.convert_date_14(date)
new_lsource_list = self.new_source_list_14(lsource_list)
new_seal_list.append( (new_lsource_list, lnote_list, new_date, type,
place, famc, temple, status, lprivate))
new_family = (junk_handle, gramps_id, father_handle, mother_handle,
child_ref_list, the_type, event_ref_list, new_media_list,
new_attribute_list, new_seal_list, new_source_list, note_list,
change, marker, private)
the_txn = self.env.txn_begin()
self.family_map.put(str(handle), new_family, txn=the_txn)
the_txn.commit()
self.update()
# ---------------------------------
# Modify Repository
# ---------------------------------
# update dates with newyear
for handle in self.repository_map.keys():
repository = self.repository_map[handle]
# address
(junk_handle, gramps_id, the_type, name, note_list,
address_list, urls, change, marker, private) = repository
new_address_list = []
for address in address_list:
(privacy, asource_list, anote_list, date, location) = address
new_date = self.convert_date_14(date)
new_asource_list = self.new_source_list_14(asource_list)
new_address_list.append((privacy, new_asource_list, anote_list,
new_date, location))
new_repository = (junk_handle, gramps_id, the_type, name, note_list,
new_address_list, urls, change, marker, private)
the_txn = self.env.txn_begin()
self.repository_map.put(str(handle), new_repository, txn=the_txn)
the_txn.commit()
self.update()
# ---------------------------------
# Modify Media
# ---------------------------------
for media_handle in self.media_map.keys():
media = self.media_map[media_handle]
(handle, gramps_id, path, mime, desc,
attribute_list, source_list, note_list, change,
date, marker, private) = media
new_source_list = self.new_source_list_14(source_list)
new_date = self.convert_date_14(date)
new_media = (handle, gramps_id, path, mime, desc,
attribute_list, new_source_list, note_list, change,
new_date, marker, private)
the_txn = self.env.txn_begin()
self.media_map.put(str(handle), new_media, txn=the_txn)
the_txn.commit()
self.update()
# ---------------------------------
# Modify Place
# ---------------------------------
for place_handle in self.place_map.keys():
place = self.place_map[place_handle]
(handle, gramps_id, title, long, lat,
main_loc, alt_loc, urls, media_list, source_list, note_list,
change, marker, private) = place
new_media_list = self.new_media_list_14(media_list)
new_source_list = self.new_source_list_14(source_list)
new_place = (handle, gramps_id, title, long, lat,
main_loc, alt_loc, urls, new_media_list,
new_source_list, note_list, change, marker, private)
the_txn = self.env.txn_begin()
self.place_map.put(str(handle), new_place, txn=the_txn)
the_txn.commit()
self.update()
# ---------------------------------
# Modify Source
# ---------------------------------
for source_handle in self.source_map.keys():
source = self.source_map[source_handle]
(handle, gramps_id, title, author,
pubinfo, note_list, media_list,
abbrev, change, datamap, reporef_list,
marker, private) = source
new_media_list = self.new_media_list_14(media_list)
new_source = (handle, gramps_id, title, author,
pubinfo, note_list, new_media_list,
abbrev, change, datamap, reporef_list,
marker, private)
the_txn = self.env.txn_begin()
self.source_map.put(str(handle), new_source, txn=the_txn)
the_txn.commit()
self.update()
# Bump up database version. Separate transaction to save metadata.
the_txn = self.env.txn_begin()
self.metadata.put('version', 14, txn=the_txn)
the_txn.commit()
def new_source_list_14(self, source_list):
new_source_list = []
for source in source_list:
(date, private, note_list, confidence, ref, page) = source
new_date = self.convert_date_14(date)
new_source_list.append((new_date, private, note_list, confidence, ref, page))
return new_source_list
def new_attribute_list_14(self, attribute_list):
new_attribute_list = []
for attribute in attribute_list:
(private, asource_list, note_list, the_type, value) = attribute
new_asource_list = self.new_source_list_14(asource_list)
new_attribute_list.append((private, new_asource_list, note_list, the_type, value))
return new_attribute_list
def new_media_list_14(self, media_list):
# ---------------------------------
# Event Media list
# ---------------------------------
new_media_list = []
for media in media_list:
(private, source_list, note_list,attribute_list,ref,role) = media
new_source_list = self.new_source_list_14(source_list)
new_attribute_list = self.new_attribute_list_14(attribute_list)
new_media_list.append((private, new_source_list, note_list, new_attribute_list, ref, role))
return new_media_list
def convert_date_14(self, date):
if date:
(calendar, modifier, quality, dateval, text, sortval) = date
return (calendar, modifier, quality, dateval, text, sortval, 0)
else:
return None
def convert_name_14(self, name):
(privacy, source_list, note_list, date,
first_name, surname, suffix, title,
name_type, prefix, patronymic,
group_as, sort_as, display_as, call) = name
new_date = self.convert_date_14(date)
new_source_list = self.new_source_list_14(source_list)
return (privacy, new_source_list, note_list, new_date,
first_name, surname, suffix, title,
name_type, prefix, patronymic,
group_as, sort_as, display_as, call)
def set_auto_remove(self):
"""
BSDDB change log settings using new method with renamed attributes
"""
if db.version() < (4, 7):
# by the book: old method with old attribute
self.env.set_flags(db.DB_LOG_AUTOREMOVE, 1)
else: # look at python interface
# TODO test with new version of pybsddb
try:
# try numeric compare, just first 2 digits
# this won't work with something like "4.10a", but
# hopefully they won't do that
old_version = map(int, db.__version__.split(".",2)[:2]) < (4, 7)
except:
# fallback, weak string compare
old_version = db.__version__ < "4.7"
if old_version:
# undocumented: old method with new attribute
self.env.set_flags(db.DB_LOG_AUTO_REMOVE, 1)
else:
# by the book: new method with new attribute
self.env.log_set_config(db.DB_LOG_AUTO_REMOVE, 1)
class BdbTransaction(Transaction):
def __init__(self, msg, db, batch=False, no_magic=False):
@ -2637,7 +2959,7 @@ def import_table(id_table, add_obj, find_next_gramps_id,
# Then we check gramps_id for conflicts and change it if needed
gramps_id = str(obj.gramps_id)
if gramps_id in id_table:
if id_table.has_key(gramps_id):
gramps_id = find_next_gramps_id()
obj.gramps_id = gramps_id
add_obj(obj, trans)