* src/GrampsDb/_ReadXML.py: Parse old and new XML.

* src/GrampsDb/_WriteXML.py (dump_child_ref, dump_person_ref): Add
	methods.
	* src/RelLib/_ChildRef.py (ChildRef.set_mother_relation): Adapt to
	new types;
	(ChildRef.set_father_relation): Adapt to new types.
	* src/RelLib/_GrampsType.py (GrampsType.get_custom): Add method.
	(GrampsType.set): Allow setting from the same class instance.
	(GrampsType.is_default): Add method.


svn: r6358
This commit is contained in:
Alex Roitman 2006-04-19 02:23:08 +00:00
parent 249b1ba53d
commit e12c7b0de3
5 changed files with 124 additions and 42 deletions

View File

@ -3,6 +3,15 @@
* src/DisplayTabs.py: remove property button stuff
2006-04-18 Alex Roitman <shura@gramps-project.org>
* src/GrampsDb/_ReadXML.py: Parse old and new XML.
* src/GrampsDb/_WriteXML.py (dump_child_ref, dump_person_ref): Add
methods.
* src/RelLib/_ChildRef.py (ChildRef.set_mother_relation): Adapt to
new types;
(ChildRef.set_father_relation): Adapt to new types.
* src/RelLib/_GrampsType.py (GrampsType.get_custom): Add method.
(GrampsType.set): Allow setting from the same class instance.
(GrampsType.is_default): Add method.
* src/DisplayTabs.py (BackRefList.create_buttons): Allow an
additional argument to keep the caller happy.

View File

@ -345,6 +345,7 @@ class GrampsParser:
self.increment = 100
self.event = None
self.eventref = None
self.childref = None
self.name = None
self.tempDefault = None
self.home = None
@ -374,6 +375,7 @@ class GrampsParser:
"bookmarks" : (None, None),
"child" : (self.start_child,None),
"childof" : (self.start_childof,None),
"childref" : (self.start_childref,self.stop_childref),
"city" : (None, self.stop_city),
"country" : (None, self.stop_country),
"comment" : (None, self.stop_comment),
@ -860,12 +862,28 @@ class GrampsParser:
person = self.find_person_by_gramps_id(self.map_gid(attrs["ref"]))
handle = person_handle
# Here we are handling the old XML, in which
# frel and mrel belonged to the "childof" tag
# If that were the case then childref_map has the childref ready
if self.childref_map.has_key((self.family.handle,handle)):
self.family.add_child_ref(self.childref_map[(self.family.handle,handle)])
else:
ref = RelLib.ChildRef()
ref.ref = handle
self.family.add_child_ref(ref)
self.family.add_child_ref(
self.childref_map[(self.family.handle,handle)])
def start_childref(self,attrs):
# Here we are handling the new XML, in which frel and mrel
# belong to the "child" tag under family.
childref = RelLib.ChildRef()
childref.ref = attrs['hlink'].replace('_','')
self.childref.private = bool(attrs.get('priv'))
mrel = RelLib.ChildRefType().set_from_xml_str(attrs.get('mrel'))
frel = RelLib.ChildRefType().set_from_xml_str(attrs.get('frel'))
if not mrel.is_default():
childref.set_mother_relation(mrel)
if not frel.is_default() ):
childref.set_father_relation(frel)
self.family.add_child_reference(self.childref)
def start_url(self,attrs):
if not attrs.has_key("href"):
@ -924,11 +942,14 @@ class GrampsParser:
family = self.find_family_by_gramps_id(self.map_fid(attrs["ref"]))
handle = family.handle
mrel = crel_map.get(attrs.get('mrel'),RelLib.ChildRefType())
frel = crel_map.get(attrs.get('frel'),RelLib.ChildRefType())
# Here we are handling the old XML, in which
# frel and mrel belonged to the "childof" tag
mrel = RelLib.ChildRefType().set_from_xml_str(attrs.get('mrel'))
frel = RelLib.ChildRefType().set_from_xml_str(attrs.get('frel'))
if mrel != RelLib.ChildRefType.BIRTH or \
frel != RelLib.ChildRefType.BIRTH:
# Only need to worry about this if there are non-default rels
# Otherwise, if both are default, the family's child tag will do
if not ( mrel.is_default() and frel.is_default() ):
childref = RelLib.ChildRef()
childref.ref = self.person.handle
childref.set_mother_relation(mrel)
@ -994,6 +1015,8 @@ class GrampsParser:
self.name.add_source_reference(self.source_ref)
elif self.placeobj:
self.placeobj.add_source_reference(self.source_ref)
elif self.childref:
self.childref.add_source_reference(self.source_ref)
elif self.family:
self.family.add_source_reference(self.source_ref)
elif self.person:
@ -1356,6 +1379,9 @@ class GrampsParser:
self.repo.type = _ConstXML.tuple_from_xml(
_ConstXML.repository_types,tag)
def stop_childref(self,tag):
self.childref = None
def stop_eventref(self,tag):
self.eventref = None
@ -1583,6 +1609,8 @@ class GrampsParser:
self.event.set_note_object(self.note)
elif self.person:
self.person.set_note_object(self.note)
elif self.childref:
self.childref.set_note_object(self.note)
elif self.family:
self.family.set_note_object(self.note)
elif self.placeobj:

View File

@ -414,32 +414,14 @@ class XmlWriter:
self.write_url_list(person.get_url_list(),index+1)
for family_handle in person.get_parent_family_handle_list():
family = self.db.get_family_from_handle(family_handle)
for child_ref in family.get_child_ref_list():
if child_ref.ref == person.handle:
mval = child_ref.get_mother_relation()
fval = child_ref.get_father_relation()
break
else:
continue
if mval != RelLib.ChildRefType.BIRTH:
mrel=' mrel="%s"' % _ConstXML.str_for_xml(
_ConstXML.child_relations,mval)
else:
mrel=''
if fval != RelLib.ChildRefType.BIRTH:
frel=' frel="%s"' % _ConstXML.str_for_xml(
_ConstXML.child_relations,fval)
else:
frel=''
self.g.write(' %s<childof hlink="_%s"%s%s/>\n' % \
(sp,family_handle, mrel, frel))
self.write_ref("childof",family_handle,index+1)
for family_handle in person.get_family_handle_list():
self.write_ref("parentin",family_handle,index+1)
for person_ref in person.get_person_ref_list():
self.dump_person_ref(person_ref,index+1)
self.write_note("note",person.get_note_object(),index+1)
for s in person.get_source_references():
self.dump_source_ref(s,index+2)
@ -461,9 +443,8 @@ class XmlWriter:
self.write_media_list(family.get_media_list(),index+1)
if len(family.get_child_ref_list()) > 0:
for child_ref in family.get_child_ref_list():
self.write_ref("child",child_ref.ref,index+1)
self.dump_child_ref(child_ref,index+1)
self.write_attribute_list(family.get_attribute_list())
self.write_note("note",family.get_note_object(),index+1)
for s in family.get_source_references():
@ -519,6 +500,50 @@ class XmlWriter:
self.dump_source_ref(s,index+2)
self.g.write('%s</address>\n' % sp)
def dump_person_ref(self,personref,index=1):
if not personref or not personref.ref:
return
sp = " "*index
priv_text = conf_priv(personref)
rel_text = ' rel="%s"'
sreflist = personref.get_source_references()
if (len(sreflist) == 0) and personref.get_note() =="":
self.write_ref('personref',personref.ref,index,close=True,
extra_text=priv_text+rel_text)
else:
self.write_ref('personref',personref.ref,index,close=False,
extra_text=priv_text+rel_text)
for sref in sreflist:
self.dump_source_ref(sref,index+1)
self.write_note("note",personref.get_note_object(),index+1)
self.g.write('%s</personref>\n' % sp)
def dump_child_ref(self,childref,index=1):
if not childref or not childref.ref:
return
sp = " "*index
priv_text = conf_priv(childref)
if childref.frel.is_default():
frel_text = ''
else:
frel_text = ' frel="%s"' % childref.frel.xml_str()
if childref.mrel.is_default():
mrel_text = ''
else:
mrel_text = ' mrel="%s"' % childref.mrel.xml_str()
sreflist = childref.get_source_references()
if (len(sreflist) == 0) and childref.get_note() =="":
self.write_ref('childref',childref.ref,index,close=True,
extra_text=priv_text+frel_text+mrel_text)
else:
self.write_ref('childref',childref.ref,index,close=False,
extra_text=priv_text+frel_text+mrel_text)
for sref in sreflist:
self.dump_source_ref(sref,index+1)
self.write_note("note",childref.get_note_object(),index+1)
self.g.write('%s</childref>\n' % sp)
def dump_event_ref(self,eventref,index=1):
if not eventref or not eventref.ref:
return

View File

@ -127,8 +127,7 @@ class ChildRef(BaseObject,PrivacyBase,SourceBase,NoteBase,RefBase):
def set_mother_relation(self,rel):
"""Sets relation between the person and mother"""
assert(isinstance(rel,ChildRefType))
self.mrel = rel
self.mrel.set(rel)
def get_mother_relation(self):
"""Returns the relation between the person and mother"""
@ -136,8 +135,7 @@ class ChildRef(BaseObject,PrivacyBase,SourceBase,NoteBase,RefBase):
def set_father_relation(self,frel):
"""Sets relation between the person and father"""
assert(isinstance(frel,ChildRefType))
self.frel = frel
self.frel.set(frel)
def get_father_relation(self):
"""Returns the relation between the person and father"""

View File

@ -40,7 +40,10 @@ class GrampsType:
self.set(value)
def set(self, value):
if type(value) == tuple:
if isinstance(value,self.__class__):
self.val = value.val
self.string = value.string
elif type(value) == tuple:
self.val = value[0]
self.string = value[1]
elif type(value) == int:
@ -68,12 +71,33 @@ class GrampsType:
else:
return self._I2SMAP.get(self.val,_('UNKNOWN'))
def xml_str(self):
"""
This method returns an untranslated string for non-custom values,
or the value, if it is custom.
"""
# FIXME: this needs to be fixed.
return self.string
def set_from_xml_str(self,the_str):
"""
This method sets the type instance based on the untranslated
string (obtained e.g. from XML).
"""
return self
def __int__(self):
return self.val
def get_map(self):
return self._I2SMAP
def is_custom(self):
return self.val == self._CUSTOM
def is_default(self):
return self.val == self._DEFAULT
def get_custom(self):
return self._CUSTOM
@ -92,5 +116,3 @@ class GrampsType:
return cmp(self.string,value.string)
else:
return cmp(self.val,value.val)