* src/GrampsDb/_ConstXML.py: Add new file.
* src/GrampsDb/Makefile.am: Ship new file. * src/GrampsDb/_GrampsBSDDB.py: Convert family and parent family relations from integer to tuple on upgrade. * src/GrampsDb/_WriteGedcom.py: Convert from tuple to string. svn: r5839
This commit is contained in:
parent
8ff52f85ac
commit
da0fa1a5cf
@ -8,6 +8,11 @@
|
||||
within load.
|
||||
* src/GenericFilters.py (get_filters): Use default value of
|
||||
'generic' for the namespace argument; Remove unneeded import.
|
||||
* src/GrampsDb/_ConstXML.py: Add new file.
|
||||
* src/GrampsDb/Makefile.am: Ship new file.
|
||||
* src/GrampsDb/_GrampsBSDDB.py: Convert family and parent family
|
||||
relations from integer to tuple on upgrade.
|
||||
* src/GrampsDb/_WriteGedcom.py: Convert from tuple to string.
|
||||
|
||||
2006-01-25 Don Allingham <don@gramps-project.org>
|
||||
* src/DisplayTabs.py: use idle_loop to load data for source
|
||||
|
@ -21,7 +21,8 @@ pkgdata_PYTHON = \
|
||||
_ReadXML.py\
|
||||
_WriteGedcom.py\
|
||||
_WriteGrdb.py\
|
||||
_WriteXML.py
|
||||
_WriteXML.py\
|
||||
_ConstXML.py
|
||||
|
||||
pkgpyexecdir = @pkgpyexecdir@/RelLib
|
||||
pkgpythondir = @pkgpythondir@/RelLib
|
||||
|
217
src/GrampsDb/_ConstXML.py
Normal file
217
src/GrampsDb/_ConstXML.py
Normal file
@ -0,0 +1,217 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2006 Donald N. Allingham
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
# $Id$
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# load GRAMPS libraries
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import RelLib
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Collection of standard types for various kinds of objects
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
child_relations = (
|
||||
(RelLib.Person.CHILD_BIRTH , "Birth"),
|
||||
(RelLib.Person.CHILD_ADOPTED , "Adopted"),
|
||||
(RelLib.Person.CHILD_STEPCHILD , "Stepchild"),
|
||||
(RelLib.Person.CHILD_SPONSORED , "Sponsored"),
|
||||
(RelLib.Person.CHILD_FOSTER , "Foster"),
|
||||
(RelLib.Person.CHILD_UNKNOWN , "Unknown"),
|
||||
)
|
||||
|
||||
events = (
|
||||
# Family events
|
||||
(RelLib.Event.UNKNOWN , "Unknown"),
|
||||
(RelLib.Event.MARRIAGE , "Marriage"),
|
||||
(RelLib.Event.MARR_SETTL , "Marriage Settlement"),
|
||||
(RelLib.Event.MARR_LIC , "Marriage License"),
|
||||
(RelLib.Event.MARR_CONTR , "Marriage Contract"),
|
||||
(RelLib.Event.MARR_BANNS , "Marriage Banns"),
|
||||
(RelLib.Event.ENGAGEMENT , "Engagement"),
|
||||
(RelLib.Event.DIVORCE , "Divorce"),
|
||||
(RelLib.Event.DIV_FILING , "Divorce Filing"),
|
||||
(RelLib.Event.ANNULMENT , "Annulment"),
|
||||
(RelLib.Event.MARR_ALT , "Alternate Marriage"),
|
||||
# Personal events
|
||||
(RelLib.Event.UNKNOWN , "Unknown"),
|
||||
(RelLib.Event.ADOPT , "Adopted"),
|
||||
(RelLib.Event.BIRTH , "Birth"),
|
||||
(RelLib.Event.DEATH , "Death"),
|
||||
(RelLib.Event.ADULT_CHRISTEN , "Adult Christening"),
|
||||
(RelLib.Event.BAPTISM , "Baptism"),
|
||||
(RelLib.Event.BAR_MITZVAH , "Bar Mitzvah"),
|
||||
(RelLib.Event.BAS_MITZVAH , "Bas Mitzvah"),
|
||||
(RelLib.Event.BLESS , "Blessing"),
|
||||
(RelLib.Event.BURIAL , "Burial"),
|
||||
(RelLib.Event.CAUSE_DEATH , "Cause Of Death"),
|
||||
(RelLib.Event.CENSUS , "Census"),
|
||||
(RelLib.Event.CHRISTEN , "Christening"),
|
||||
(RelLib.Event.CONFIRMATION , "Confirmation"),
|
||||
(RelLib.Event.CREMATION , "Cremation"),
|
||||
(RelLib.Event.DEGREE , "Degree"),
|
||||
(RelLib.Event.DIV_FILING , "Divorce Filing"),
|
||||
(RelLib.Event.EDUCATION , "Education"),
|
||||
(RelLib.Event.ELECTED , "Elected"),
|
||||
(RelLib.Event.EMIGRATION , "Emigration"),
|
||||
(RelLib.Event.FIRST_COMMUN , "First Communion"),
|
||||
(RelLib.Event.IMMIGRATION , "Immigration"),
|
||||
(RelLib.Event.GRADUATION , "Graduation"),
|
||||
(RelLib.Event.MED_INFO , "Medical Information"),
|
||||
(RelLib.Event.MILITARY_SERV , "Military Service"),
|
||||
(RelLib.Event.NATURALIZATION , "Naturalization"),
|
||||
(RelLib.Event.NOB_TITLE , "Nobility Title"),
|
||||
(RelLib.Event.NUM_MARRIAGES , "Number of Marriages"),
|
||||
(RelLib.Event.OCCUPATION , "Occupation"),
|
||||
(RelLib.Event.ORDINATION , "Ordination"),
|
||||
(RelLib.Event.PROBATE , "Probate"),
|
||||
(RelLib.Event.PROPERTY , "Property"),
|
||||
(RelLib.Event.RELIGION , "Religion"),
|
||||
(RelLib.Event.RESIDENCE , "Residence"),
|
||||
(RelLib.Event.RETIREMENT , "Retirement"),
|
||||
(RelLib.Event.WILL , "Will"),
|
||||
)
|
||||
|
||||
attributes = (
|
||||
(RelLib.Attribute.UNKNOWN , "Unknown"),
|
||||
(RelLib.Attribute.CASTE , "Caste"),
|
||||
(RelLib.Attribute.DESCRIPTION , "Description"),
|
||||
(RelLib.Attribute.ID , "Identification Number"),
|
||||
(RelLib.Attribute.NATIONAL , "National Origin"),
|
||||
(RelLib.Attribute.NUM_CHILD , "Number of Children"),
|
||||
(RelLib.Attribute.SSN , "Social Security Number"),
|
||||
)
|
||||
|
||||
family_relations = (
|
||||
(RelLib.Family.MARRIED , "Married"),
|
||||
(RelLib.Family.UNMARRIED , "Unmarried"),
|
||||
(RelLib.Family.CIVIL_UNION , "Civil Union"),
|
||||
(RelLib.Family.UNKNOWN , "Unknown"),
|
||||
)
|
||||
|
||||
name_types = (
|
||||
(RelLib.Name.UNKNOWN , "Unknown"),
|
||||
(RelLib.Name.AKA , "Also Known As"),
|
||||
(RelLib.Name.BIRTH , "Birth Name"),
|
||||
(RelLib.Name.MARRIED , "Married Name"),
|
||||
)
|
||||
|
||||
source_media_types = (
|
||||
(RelLib.RepoRef.UNKNOWN , "Unknown"),
|
||||
(RelLib.RepoRef.AUDIO , "Audio"),
|
||||
(RelLib.RepoRef.BOOK , "Book"),
|
||||
(RelLib.RepoRef.CARD , "Card"),
|
||||
(RelLib.RepoRef.ELECTRONIC , "Electronic"),
|
||||
(RelLib.RepoRef.FICHE , "Fiche"),
|
||||
(RelLib.RepoRef.FILM , "Film"),
|
||||
(RelLib.RepoRef.MAGAZINE , "Magazine"),
|
||||
(RelLib.RepoRef.MANUSCRIPT , "Manuscript"),
|
||||
(RelLib.RepoRef.MAP , "Map"),
|
||||
(RelLib.RepoRef.NEWSPAPER , "Newspaper"),
|
||||
(RelLib.RepoRef.PHOTO , "Photo"),
|
||||
(RelLib.RepoRef.TOMBSTONE , "Tombstone"),
|
||||
(RelLib.RepoRef.VIDEO , "Video"),
|
||||
)
|
||||
|
||||
event_roles = (
|
||||
(RelLib.EventRef.UNKNOWN , "Unknown"),
|
||||
(RelLib.EventRef.PRIMARY , "Primary"),
|
||||
(RelLib.EventRef.CLERGY , "Clergy"),
|
||||
(RelLib.EventRef.CELEBRANT , "Celebrant"),
|
||||
(RelLib.EventRef.AIDE , "Aide"),
|
||||
(RelLib.EventRef.BRIDE , "Bride"),
|
||||
(RelLib.EventRef.GROOM , "Groom"),
|
||||
(RelLib.EventRef.WITNESS , "Witness"),
|
||||
(RelLib.EventRef.FAMILY , "Family"),
|
||||
)
|
||||
|
||||
repository_types = (
|
||||
(RelLib.Repository.UNKNOWN , "Unknown"),
|
||||
(RelLib.Repository.LIBRARY , "Library"),
|
||||
(RelLib.Repository.CEMETERY , "Cemetery"),
|
||||
(RelLib.Repository.CHURCH , "Church"),
|
||||
(RelLib.Repository.ARCHIVE , "Archive"),
|
||||
(RelLib.Repository.ALBUM , "Album"),
|
||||
(RelLib.Repository.WEBSITE , "Web site"),
|
||||
(RelLib.Repository.BOOKSTORE , "Bookstore"),
|
||||
(RelLib.Repository.COLLECTION , "Collection"),
|
||||
(RelLib.Repository.SAFE , "Safe"),
|
||||
)
|
||||
|
||||
marker_types = (
|
||||
(RelLib.PrimaryObject.MARKER_NONE , ""),
|
||||
(RelLib.PrimaryObject.MARKER_COMPLETE , "complete"),
|
||||
(RelLib.PrimaryObject.MARKER_TODO , "todo"),
|
||||
)
|
||||
|
||||
# mapping from the tuple collection to the appropriate CUSTOM integer
|
||||
custom_types = {
|
||||
child_relations : RelLib.Person.CHILD_CUSTOM,
|
||||
events : RelLib.Event.CUSTOM,
|
||||
attributes : RelLib.Attribute.CUSTOM,
|
||||
family_relations : RelLib.Family.CUSTOM,
|
||||
name_types : RelLib.Name.CUSTOM,
|
||||
source_media_types : RelLib.RepoRef.CUSTOM,
|
||||
event_roles : RelLib.EventRef.CUSTOM,
|
||||
repository_types : RelLib.Repository.CUSTOM,
|
||||
marker_types : RelLib.PrimaryObject.MARKER_CUSTOM,
|
||||
}
|
||||
|
||||
def str_for_xml(tuples,the_tuple):
|
||||
"""
|
||||
This function checks the_tuple against the collection of tuples
|
||||
and returns the string to store in the XML file.
|
||||
"""
|
||||
|
||||
# use list comprehension to quickly find a match, if any
|
||||
match_list = [ item for item in tuples if item[0] == the_tuple[0] ]
|
||||
|
||||
# If match_list is not empty, then we have got a match,
|
||||
# so we simply return the string of that standard item
|
||||
if match_list:
|
||||
return match_list[0][1]
|
||||
|
||||
# empty match_list means there's nothing with that integer,
|
||||
# so we simply return the string from the_tuple
|
||||
else:
|
||||
return the_tuple[1]
|
||||
|
||||
def tuple_from_xml(tuples,the_str):
|
||||
"""
|
||||
This function checks the_str against the collection of tuples
|
||||
and returns the tuple to use for the type internally.
|
||||
"""
|
||||
|
||||
# use list comprehension to quickly find a match, if any
|
||||
match_list = [ item for item in tuples if item[1] == the_str ]
|
||||
|
||||
# If match_list is not empty, then we have got a match,
|
||||
# so we return the tuple made from the only item in the list.
|
||||
if match_list:
|
||||
return (match_list[0][0],'')
|
||||
|
||||
# empty match_list means there's nothing with that string,
|
||||
# so we return the tuple of custom type and the original string
|
||||
else:
|
||||
return (custom_types[tuples],the_str)
|
@ -1336,6 +1336,13 @@ class GrampsBSDDB(GrampsDbBase):
|
||||
new_type = (Name.UNKNOWN,"")
|
||||
name.type = new_type
|
||||
|
||||
# In all parent family instances, convert relationships from
|
||||
# string to a tuple.
|
||||
new_parent_family_list = [ (family_handle,(mrel,''),(frel,''))
|
||||
for (family_handle,mrel,frel)
|
||||
in person.parent_family_list[:] ]
|
||||
person.parent_family_list = new_parent_family_list
|
||||
|
||||
# In all Attributes, convert type from string to a tuple
|
||||
for attribute in person.attribute_list:
|
||||
convert_attribute_9(attribute)
|
||||
@ -1376,6 +1383,9 @@ class GrampsBSDDB(GrampsDbBase):
|
||||
event_ref.role = (EventRef.PRIMARY,'')
|
||||
family.event_ref_list.append(event_ref)
|
||||
|
||||
# Change relationship type from int to tuple
|
||||
family.type = (family.type,'')
|
||||
|
||||
# In all Attributes, convert type from string to a tuple
|
||||
for attribute in family.attribute_list:
|
||||
convert_attribute_9(attribute)
|
||||
@ -1586,7 +1596,7 @@ def convert_url_9(url):
|
||||
url.type = (Url.WEB_FTP,'')
|
||||
else:
|
||||
url.type = (Url.CUSTOM,'')
|
||||
|
||||
|
||||
def low_level_9(the_db):
|
||||
"""
|
||||
This is a low-level repair routine.
|
||||
|
@ -1,7 +1,7 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2000-2005 Donald N. Allingham
|
||||
# Copyright (C) 2000-2006 Donald N. Allingham
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@ -52,6 +52,7 @@ import const
|
||||
import RelLib
|
||||
import Date
|
||||
from QuestionDialog import ErrorDialog
|
||||
import _ConstXML
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@ -270,8 +271,8 @@ class XmlWriter:
|
||||
self.write_line("nick",person.get_nick_name(),3)
|
||||
birth = self.db.get_event_from_handle(person.get_birth_handle())
|
||||
death = self.db.get_event_from_handle(person.get_death_handle())
|
||||
self.dump_my_event("Birth",birth,3)
|
||||
self.dump_my_event("Death",death,3)
|
||||
self.dump_event(birth,3)
|
||||
self.dump_event(death,3)
|
||||
for event_handle in person.get_event_list():
|
||||
event = self.db.get_event_from_handle(event_handle)
|
||||
self.dump_event(event,3)
|
||||
@ -302,12 +303,16 @@ class XmlWriter:
|
||||
self.write_url_list(person.get_url_list())
|
||||
|
||||
for alt in person.get_parent_family_handle_list():
|
||||
if alt[1] != RelLib.Person.CHILD_BIRTH:
|
||||
mrel=' mrel="%s"' % const.child_rel_notrans[alt[1]]
|
||||
if alt[1][0] != RelLib.Person.CHILD_BIRTH:
|
||||
mrel=' mrel="%s"' % _ConstXML.str_for_xml(
|
||||
_ConstXML.child_relations,alt[1])
|
||||
# const.child_rel_notrans[alt[1]]
|
||||
else:
|
||||
mrel=''
|
||||
if alt[2] != RelLib.Person.CHILD_BIRTH:
|
||||
frel=' frel="%s"' % const.child_rel_notrans[alt[2]]
|
||||
if alt[2][0] != RelLib.Person.CHILD_BIRTH:
|
||||
frel=' frel="%s"' % _ConstXML.str_for_xml(
|
||||
_ConstXML.child_relations,alt[2])
|
||||
# const.child_rel_notrans[alt[2]]
|
||||
else:
|
||||
frel=''
|
||||
self.g.write(" <childof hlink=\"%s\"%s%s/>\n" % \
|
||||
@ -465,13 +470,9 @@ class XmlWriter:
|
||||
self.g.write(self.fix(text.rstrip()))
|
||||
self.g.write("</%s>\n" % val)
|
||||
|
||||
def dump_event(self,event,index=1):
|
||||
if event:
|
||||
self.dump_my_event(event.get_name(),event,index)
|
||||
|
||||
def write_witness(self,witness_list,index):
|
||||
if not witness_list:
|
||||
return
|
||||
#if not witness_list:
|
||||
return
|
||||
for w in witness_list:
|
||||
sp = " "*index
|
||||
com = self.fix(w.get_comment())
|
||||
@ -487,16 +488,17 @@ class XmlWriter:
|
||||
self.g.write(' %s<comment>%s</comment>\n' % (sp,com))
|
||||
self.g.write('%s</witness>\n' % sp)
|
||||
|
||||
def dump_my_event(self,name,event,index=1):
|
||||
def dump_event(self,event,index=1):
|
||||
if not event or event.is_empty():
|
||||
return
|
||||
|
||||
sp = " " * index
|
||||
name = const.save_event(name)
|
||||
self.g.write('%s<event type="%s"%s>\n' % (sp,self.fix(name),conf_priv(event)))
|
||||
etype = _ConstXML.str_for_xml(_ConstXML.events,event.get_type())
|
||||
self.g.write('%s<event type="%s"%s>\n' %
|
||||
(sp,self.fix(etype),conf_priv(event)))
|
||||
self.write_date(event.get_date_object(),index+1)
|
||||
|
||||
self.write_witness(event.get_witness_list(),index+1)
|
||||
#self.write_witness(event.get_witness_list(),index+1)
|
||||
self.write_ref("place",event.get_place_handle(),index+1)
|
||||
self.write_line("cause",event.get_cause(),index+1)
|
||||
self.write_line("description",event.get_description(),index+1)
|
||||
@ -563,22 +565,26 @@ class XmlWriter:
|
||||
self.g.write('%s<%s id="%s" handle="%s" change="%d"' %
|
||||
(" "*index,label,person.get_gramps_id(),"_"+person.get_handle(),
|
||||
person.get_change_time()))
|
||||
comp = person.get_complete_flag()
|
||||
if comp:
|
||||
self.g.write(' complete="1"')
|
||||
marker = _ConstXML.str_for_xml(_ConstXML.marker_types,
|
||||
person.get_marker())
|
||||
if marker:
|
||||
self.g.write(' marker="%s"' % marker)
|
||||
self.g.write('>\n')
|
||||
|
||||
def write_family_handle(self,family,index=1):
|
||||
if family:
|
||||
rel = family.get_relationship()
|
||||
comp = family.get_complete_flag()
|
||||
rel = _ConstXML.str_for_xml(_ConstXML.family_relations,
|
||||
family.get_relationship())
|
||||
marker = _ConstXML.str_for_xml(_ConstXML.marker_types,
|
||||
family.get_marker())
|
||||
sp = " " * index
|
||||
self.g.write('%s<family id="%s" handle="%s" change="%d"' %
|
||||
(sp,family.get_gramps_id(),"_"+family.get_handle(),family.get_change_time()))
|
||||
if comp:
|
||||
self.g.write(' complete="1"')
|
||||
if marker:
|
||||
self.g.write(' marker="%s"' % marker)
|
||||
if rel != "":
|
||||
self.g.write(' type="%s">\n' % const.save_frel(rel))
|
||||
self.g.write(' type="%s">\n' % rel )
|
||||
# const.save_frel(rel))
|
||||
else:
|
||||
self.g.write('>\n')
|
||||
|
||||
@ -672,7 +678,8 @@ class XmlWriter:
|
||||
|
||||
def dump_name(self,name,alternative=False,index=1):
|
||||
sp = " "*index
|
||||
name_type = name.get_type()
|
||||
name_type = _ConstXML.str_for_xml(_ConstXML.name_types,
|
||||
name.get_type())
|
||||
self.g.write('%s<name' % sp)
|
||||
if alternative:
|
||||
self.g.write(' alt="1"')
|
||||
@ -758,7 +765,10 @@ class XmlWriter:
|
||||
sp = ' ' * indent
|
||||
for attr in list:
|
||||
self.g.write('%s<attribute%s type="%s" value="%s"' % \
|
||||
(sp,conf_priv(attr),const.save_attr(attr.get_type()),
|
||||
(sp,conf_priv(attr),
|
||||
_ConstXML.str_for_xml(_ConstXML.attributes,
|
||||
attr.get_type()),
|
||||
#const.save_attr(attr.get_type()),
|
||||
self.fix(attr.get_value())))
|
||||
slist = attr.get_source_references()
|
||||
note = attr.get_note()
|
||||
|
Loading…
Reference in New Issue
Block a user