* src/GrampsDb/_WriteGedcom.py: Bring to new API.

svn: r6597
This commit is contained in:
Alex Roitman 2006-05-09 20:36:12 +00:00
parent 99576086d8
commit 19d1245c01
2 changed files with 79 additions and 71 deletions

View File

@ -1,4 +1,5 @@
2006-05-09 Alex Roitman <shura@gramps-project.org> 2006-05-09 Alex Roitman <shura@gramps-project.org>
* src/GrampsDb/_WriteGedcom.py: Bring to new API.
* src/plugins/ExportVCard.py: Bring to new API. * src/plugins/ExportVCard.py: Bring to new API.
* src/plugins/ExportVCalendar.py: Bring to new API. * src/plugins/ExportVCalendar.py: Bring to new API.
* src/plugins/WriteFtree.py: Bring to new API. * src/plugins/WriteFtree.py: Bring to new API.

View File

@ -750,11 +750,8 @@ class GedcomWriter:
event = self.db.get_event_from_handle(event_handle) event = self.db.get_event_from_handle(event_handle)
if not event or self.private and event.get_privacy(): if not event or self.private and event.get_privacy():
continue continue
(index,name) = event.get_type() index = int(event.get_type())
val = event.get_type().xml_str()
val = ""
if Utils.family_events.has_key(index):
val = Utils.family_events[index]
if val == "": if val == "":
val = self.target_ged.gramps2tag(name) val = self.target_ged.gramps2tag(name)
@ -767,45 +764,43 @@ class GedcomWriter:
self.writeln("2 TYPE %s" % event.get_description()) self.writeln("2 TYPE %s" % event.get_description())
else: else:
self.writeln("1 EVEN") self.writeln("1 EVEN")
self.writeln("2 TYPE %s" % ' '.join([self.cnvtxt(name), self.writeln("2 TYPE %s" % ' '.join(
event.get_description()])) [self.cnvtxt(val),
self.cnvtxt(event.get_description())]))
self.dump_event_stats(event) self.dump_event_stats(event)
for attr in family.get_attribute_list(): for attr in family.get_attribute_list():
if self.private and attr.get_privacy(): if self.private and attr.get_privacy():
continue continue
name = attr.get_type() name = attr.get_type().xml_str()
value = self.cnvtxt(attr.get_value()).replace('\r',' ')
if name in ["AFN", "RFN", "_UID"]: if name in ["AFN", "RFN", "_UID"]:
self.writeln("1 %s %s" % ( name, attr.get_value())) self.writeln("1 %s %s" % (name,value))
continue continue
if Utils.personal_attributes.has_key(name): if attr.get_type().is_custom():
val = Utils.personal_attributes[name]
else:
val = ""
value = self.cnvtxt(attr.get_value()).replace('\r',' ')
if val:
if value:
self.writeln("1 %s %s" % (val, value))
else:
self.writeln("1 %s" % val)
else:
self.writeln("1 EVEN") self.writeln("1 EVEN")
if value: if value:
self.writeln("2 TYPE %s %s" % (self.cnvtxt(name), value)) self.writeln("2 TYPE %s %s" %(self.cnvtxt(name),value))
else: else:
self.writeln("2 TYPE %s" % self.cnvtxt(name)) self.writeln("2 TYPE %s" % self.cnvtxt(name))
else:
if value:
self.writeln("1 %s %s" % (name, value))
else:
self.writeln("1 %s" % name)
if attr.get_note(): if attr.get_note():
self.write_long_text("NOTE",2,self.cnvtxt(attr.get_note())) self.write_long_text("NOTE",2,self.cnvtxt(attr.get_note()))
for srcref in attr.get_source_references(): for srcref in attr.get_source_references():
self.write_source_ref(2,srcref) self.write_source_ref(2,srcref)
for person_handle in family.get_child_handle_list(): for child_ref in family.get_child_ref_list():
if not self.plist.has_key(person_handle): if not self.plist.has_key(child_ref.ref):
continue continue
person = self.db.get_person_from_handle(person_handle) person = self.db.get_person_from_handle(child_ref.ref)
if not person: if not person:
continue continue
self.writeln("1 CHIL @%s@" % person.get_gramps_id()) self.writeln("1 CHIL @%s@" % person.get_gramps_id())
@ -814,16 +809,19 @@ class GedcomWriter:
self.writeln('2 _FREL Natural') self.writeln('2 _FREL Natural')
self.writeln('2 _MREL Natural') self.writeln('2 _MREL Natural')
else: else:
for f in person.get_parent_family_handle_list(): if family.get_handle() in \
if f[0] == family.get_handle(): person.get_parent_family_handle_list():
self.writeln('2 _FREL %s' % f[2]) for child_ref in family.get_child_ref_list():
self.writeln('2 _MREL %s' % f[1]) if child_ref.ref == person.handle:
break self.writeln('2 _FREL %s' %
child_ref.frel.xml_str())
self.writeln('2 _MREL %s' %
child_ref.mrel.xml_str())
break
if self.adopt == GedcomInfo.ADOPT_LEGACY: if self.adopt == GedcomInfo.ADOPT_LEGACY:
for f in person.get_parent_family_handle_list(): if family.get_handle() in \
if f[0] == family.get_handle(): person.get_parent_family_handle_list():
self.writeln('2 _STAT %s' % f[2]) self.writeln('2 _STAT %s' % f[2])
break
for srcref in family.get_source_references(): for srcref in family.get_source_references():
self.write_source_ref(1,srcref) self.write_source_ref(1,srcref)
@ -948,10 +946,8 @@ class GedcomWriter:
event = self.db.get_event_from_handle(event_ref.ref) event = self.db.get_event_from_handle(event_ref.ref)
if self.private and event.get_privacy(): if self.private and event.get_privacy():
continue continue
(index,name) = event.get_type() index = int(event.get_type())
val = "" val = event.get_type().xml_str()
if Utils.personal_events.has_key(index):
val = Utils.personal_events[index]
if val == "": if val == "":
val = self.target_ged.gramps2tag(index) val = self.target_ged.gramps2tag(index)
@ -959,18 +955,25 @@ class GedcomWriter:
ad = 1 ad = 1
self.writeln('1 ADOP') self.writeln('1 ADOP')
fam = None fam = None
for f in person.get_parent_family_handle_list(): for fh in person.get_parent_family_handle_list():
mrel = f[1] family = self.db.get_family_from_handle(fh)
frel = f[2] for child_ref in family.get_child_ref_list():
if (mrel == RelLib.ChildRef.CHILD_ADOPTED or if child_ref.ref == person.handle:
frel == RelLib.ChildRef.CHILD_ADOPTED): if \
fam = f[0] child_ref.mrel == \
break RelLib.ChildRefType.ADOPTED \
or child_ref.frel == \
RelLib.ChildRefType.ADOPTED:
frel = child_ref.frel
mrel = child_ref.mrel
fam = family
break
if fam: if fam:
self.writeln('2 FAMC @%s@' % self.fid(fam.get_gramps_id())) self.writeln('2 FAMC @%s@' %
self.fid(fam.get_gramps_id()))
if mrel == frel: if mrel == frel:
self.writeln('3 ADOP BOTH') self.writeln('3 ADOP BOTH')
elif mrel == "adopted": elif mrel == RelLib.ChildRefType.ADOPTED:
self.writeln('3 ADOP WIFE') self.writeln('3 ADOP WIFE')
else: else:
self.writeln('3 ADOP HUSB') self.writeln('3 ADOP HUSB')
@ -993,28 +996,35 @@ class GedcomWriter:
# after EVEN on the same line, possibly an option is # after EVEN on the same line, possibly an option is
# needed on how to handle this # needed on how to handle this
if event.get_description() != "": if event.get_description() != "":
self.writeln("1 EVEN %s" % event.get_description()) self.writeln("1 EVEN %s" %
self.snvtxt(event.get_description()))
else: else:
self.writeln("1 EVEN") self.writeln("1 EVEN")
self.writeln("2 TYPE %s" % self.cnvtxt(name)) self.writeln("2 TYPE %s" % self.cnvtxt(val))
self.dump_event_stats(event) self.dump_event_stats(event)
if self.adopt == GedcomInfo.ADOPT_EVENT and ad == 0 and len(person.get_parent_family_handle_list()) != 0: if self.adopt == GedcomInfo.ADOPT_EVENT and ad == 0 and len(person.get_parent_family_handle_list()) != 0:
self.writeln('1 ADOP') self.writeln('1 ADOP')
fam = None fam = None
for f in person.get_parent_family_handle_list(): for fh in person.get_parent_family_handle_list():
mrel = f[1] family = self.db.get_family_from_handle(fh)
frel = f[2] for child_ref in family.get_child_ref_list():
if (mrel == RelLib.ChildRef.CHILD_ADOPTED or if child_ref.ref == person.handle:
frel == RelLib.ChildRef.CHILD_ADOPTED): if \
fam = f[0] child_ref.mrel == \
break RelLib.ChildRefType.ADOPTED \
or child_ref.frel == \
RelLib.ChildRefType.ADOPTED:
frel = child_ref.frel
mrel = child_ref.mrel
fam = family
break
if fam: if fam:
self.writeln('2 FAMC @%s@' % self.fid(fam.get_gramps_id())) self.writeln('2 FAMC @%s@' % self.fid(fam.get_gramps_id()))
if mrel == frel: if mrel == frel:
self.writeln('3 ADOP BOTH') self.writeln('3 ADOP BOTH')
elif mrel == "adopted": elif mrel == RelLib.ChildRefType.ADOPTED:
self.writeln('3 ADOP WIFE') self.writeln('3 ADOP WIFE')
else: else:
self.writeln('3 ADOP HUSB') self.writeln('3 ADOP HUSB')
@ -1022,28 +1032,25 @@ class GedcomWriter:
for attr in person.get_attribute_list(): for attr in person.get_attribute_list():
if self.private and attr.get_privacy(): if self.private and attr.get_privacy():
continue continue
name = attr.get_type() name = attr.get_type().xml_str()
value = self.cnvtxt(attr.get_value()).replace('\r',' ')
if name in ["AFN", "RFN", "_UID"]: if name in ["AFN", "RFN", "_UID"]:
self.writeln("1 %s %s" % ( name, attr.get_value())) self.writeln("1 %s %s" % (name,value))
continue continue
if Utils.personal_attributes.has_key(name): if attr.get_type().is_custom():
val = Utils.personal_attributes[name]
else:
val = ""
value = self.cnvtxt(attr.get_value()).replace('\r',' ')
if val:
if value:
self.writeln("1 %s %s" % (val, value))
else:
self.writeln("1 %s" % val)
else:
self.writeln("1 EVEN") self.writeln("1 EVEN")
if value: if value:
self.writeln("2 TYPE %s %s" % (self.cnvtxt(name), value)) self.writeln("2 TYPE %s %s" %(self.cnvtxt(name),value))
else: else:
self.writeln("2 TYPE %s" % self.cnvtxt(name)) self.writeln("2 TYPE %s" % self.cnvtxt(name))
else:
if value:
self.writeln("1 %s %s" % (name,value))
else:
self.writeln("1 %s" % name)
if attr.get_note(): if attr.get_note():
self.write_long_text("NOTE",2,self.cnvtxt(attr.get_note())) self.write_long_text("NOTE",2,self.cnvtxt(attr.get_note()))
for srcref in attr.get_source_references(): for srcref in attr.get_source_references():