Added an integer newyear code to all dates, db version 14
svn: r10521
This commit is contained in:
parent
1fa86e8c93
commit
d4311078f0
@ -1691,32 +1691,195 @@ class GrampsDBDir(GrampsDbBase, UpdateCallback):
|
||||
|
||||
def gramps_upgrade_14(self):
|
||||
"""Upgrade database from version 13 to 14."""
|
||||
# This upgrade modifies notes
|
||||
length = len(self.note_map)
|
||||
# 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))
|
||||
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_event = (junk_handle, gramps_id, the_type, new_date,
|
||||
description, place, source_list, note_list,
|
||||
media_list, 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
|
||||
arent_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_address_list.append((privacy, 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_ord_list.append( (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_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
|
||||
arent_family_list, # 9
|
||||
media_list, # 10
|
||||
new_address_list, # 11
|
||||
attribute_list, # 12
|
||||
urls, # 13
|
||||
new_ord_list, # 14
|
||||
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_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_seal_list.append( (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, media_list,
|
||||
attribute_list, new_seal_list, 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_address_list.append((privacy, 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()
|
||||
|
||||
# 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 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)
|
||||
return (privacy, source_list, note_list, new_date,
|
||||
first_name, surname, suffix, title,
|
||||
name_type, prefix, patronymic,
|
||||
group_as, sort_as, display_as, call)
|
||||
|
||||
def write_version(self, name):
|
||||
"""Write version number for a newly created DB."""
|
||||
full_name = os.path.abspath(name)
|
||||
@ -1753,7 +1916,6 @@ class GrampsDBDir(GrampsDbBase, UpdateCallback):
|
||||
self.metadata.close()
|
||||
self.env.close()
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# BdbTransaction
|
||||
|
@ -80,7 +80,7 @@ class Date:
|
||||
|
||||
Supports partial dates, compound dates and alternate calendars.
|
||||
"""
|
||||
MOD_NONE = 0
|
||||
MOD_NONE = 0 # CODE
|
||||
MOD_BEFORE = 1
|
||||
MOD_AFTER = 2
|
||||
MOD_ABOUT = 3
|
||||
@ -88,17 +88,23 @@ class Date:
|
||||
MOD_SPAN = 5
|
||||
MOD_TEXTONLY = 6
|
||||
|
||||
QUAL_NONE = 0
|
||||
QUAL_NONE = 0 # BITWISE
|
||||
QUAL_ESTIMATED = 1
|
||||
QUAL_CALCULATED = 2
|
||||
QUAL_INTERPRETED = 4
|
||||
|
||||
CAL_GREGORIAN = 0
|
||||
CAL_GREGORIAN = 0 # CODE
|
||||
CAL_JULIAN = 1
|
||||
CAL_HEBREW = 2
|
||||
CAL_FRENCH = 3
|
||||
CAL_PERSIAN = 4
|
||||
CAL_ISLAMIC = 5
|
||||
|
||||
NEWYEAR_JAN1 = 0 # CODE
|
||||
NEWYEAR_MAR1 = 1
|
||||
NEWYEAR_MAR25 = 2
|
||||
NEWYEAR_SEP1 = 3
|
||||
|
||||
EMPTY = (0, 0, 0, False)
|
||||
|
||||
_POS_DAY = 0
|
||||
@ -181,6 +187,7 @@ class Date:
|
||||
self.dateval = Date.EMPTY
|
||||
self.text = u""
|
||||
self.sortval = 0
|
||||
self.newyear = 0
|
||||
self.set_yr_mon_day(*source)
|
||||
elif type(source) == str:
|
||||
if (calendar != None or
|
||||
@ -196,6 +203,7 @@ class Date:
|
||||
self.dateval = source.dateval
|
||||
self.text = source.text
|
||||
self.sortval = source.sortval
|
||||
self.newyear = source.newyear
|
||||
elif source:
|
||||
self.calendar = source.calendar
|
||||
self.modifier = source.modifier
|
||||
@ -203,6 +211,7 @@ class Date:
|
||||
self.dateval = source.dateval
|
||||
self.text = source.text
|
||||
self.sortval = source.sortval
|
||||
self.newyear = source.newyear
|
||||
else:
|
||||
self.calendar = Date.CAL_GREGORIAN
|
||||
self.modifier = Date.MOD_NONE
|
||||
@ -210,6 +219,7 @@ class Date:
|
||||
self.dateval = Date.EMPTY
|
||||
self.text = u""
|
||||
self.sortval = 0
|
||||
self.newyear = Date.NEWYEAR_JAN1
|
||||
|
||||
def serialize(self, no_text_date=False):
|
||||
"""
|
||||
@ -221,14 +231,14 @@ class Date:
|
||||
text = self.text
|
||||
|
||||
return (self.calendar, self.modifier, self.quality,
|
||||
self.dateval, text, self.sortval)
|
||||
self.dateval, text, self.sortval, self.newyear)
|
||||
|
||||
def unserialize(self, data):
|
||||
"""
|
||||
Load from the format created by serialize.
|
||||
"""
|
||||
(self.calendar, self.modifier, self.quality,
|
||||
self.dateval, self.text, self.sortval) = data
|
||||
self.dateval, self.text, self.sortval, self.newyear) = data
|
||||
return self
|
||||
|
||||
def copy(self, source):
|
||||
@ -242,6 +252,7 @@ class Date:
|
||||
self.dateval = source.dateval
|
||||
self.text = source.text
|
||||
self.sortval = source.sortval
|
||||
self.newyear = source.newyear
|
||||
|
||||
def __cmp__(self, other):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user