* src/plugins/WriteGedcom.py: support different end of line characters

* src/GedcomInfo.py: support different end of line characters
* src/data/gedcom.xml: indicate cr-lf for Windows based tools


svn: r1798
This commit is contained in:
Don Allingham 2003-06-28 17:35:00 +00:00
parent 315e2ccf40
commit f3d2163bd9
3 changed files with 147 additions and 124 deletions

View File

@ -66,6 +66,7 @@ class GedcomDescription:
self.gramps2tag_map = {} self.gramps2tag_map = {}
self.tag2gramps_map = {} self.tag2gramps_map = {}
self.prefix = PREFIX_YES self.prefix = PREFIX_YES
self.endl = "\n"
def set_dest(self,val): def set_dest(self,val):
self.dest = val self.dest = val
@ -73,6 +74,12 @@ class GedcomDescription:
def get_dest(self): def get_dest(self):
return self.dest return self.dest
def set_endl(self,val):
self.endl = val.replace('\\r','\r').replace('\\n','\n')
def get_endl(self):
return self.endl
def set_adopt(self,val): def set_adopt(self,val):
self.adopt = val self.adopt = val
@ -194,6 +201,8 @@ class GedInfoParser:
self.parent.add_description(name,self.current) self.parent.add_description(name,self.current)
elif tag == "dest": elif tag == "dest":
self.current.set_dest(attrs['val']) self.current.set_dest(attrs['val'])
elif tag == "endl":
self.current.set_endl(attrs['val'])
elif tag == "adopt": elif tag == "adopt":
val = attrs['val'] val = attrs['val']
if val == 'none': if val == 'none':

View File

@ -6,6 +6,7 @@
<conc val="standard"/> <conc val="standard"/>
<alternate_names val="none"/> <alternate_names val="none"/>
<prefix val="no"/> <prefix val="no"/>
<endl val="\r\n"/>
<calendar val="no"/> <calendar val="no"/>
<extended_events> <extended_events>
</extended_events> </extended_events>
@ -19,6 +20,7 @@
<conc val="broken"/> <conc val="broken"/>
<alternate_names val="event_aka"/> <alternate_names val="event_aka"/>
<prefix val="no"/> <prefix val="no"/>
<endl val="\r\n"/>
<calendar val="no"/> <calendar val="no"/>
<extended_events> <extended_events>
</extended_events> </extended_events>
@ -32,6 +34,7 @@
<conc val="broken"/> <conc val="broken"/>
<alternate_names val="alias"/> <alternate_names val="alias"/>
<prefix val="no"/> <prefix val="no"/>
<endl val="\r\n"/>
<calendar val="no"/> <calendar val="no"/>
<extended_events> <extended_events>
<event tag="_DEG" value="Degree"/> <event tag="_DEG" value="Degree"/>
@ -49,6 +52,7 @@
<conc val="broken"/> <conc val="broken"/>
<alternate_names val="none"/> <alternate_names val="none"/>
<prefix val="no"/> <prefix val="no"/>
<endl val="\n"/>
<calendar val="no"/> <calendar val="no"/>
<extended_events> <extended_events>
</extended_events> </extended_events>
@ -62,6 +66,7 @@
<conc val="standard"/> <conc val="standard"/>
<alternate_names val="none"/> <alternate_names val="none"/>
<prefix val="no"/> <prefix val="no"/>
<endl val="\n"/>
<calendar val="yes"/> <calendar val="yes"/>
<extended_events> <extended_events>
</extended_events> </extended_events>
@ -74,6 +79,7 @@
<adopt val="legacy"/> <adopt val="legacy"/>
<conc val="broken"/> <conc val="broken"/>
<prefix val="no"/> <prefix val="no"/>
<endl val="\r\n"/>
<alternate_names val="standard"/> <alternate_names val="standard"/>
<calendar val="no"/> <calendar val="no"/>
<extended_events> <extended_events>
@ -88,6 +94,7 @@
<conc val="standard"/> <conc val="standard"/>
<alternate_names val="aka"/> <alternate_names val="aka"/>
<prefix val="no"/> <prefix val="no"/>
<endl val="\r\n"/>
<calendar val="no"/> <calendar val="no"/>
<extended_events> <extended_events>
</extended_events> </extended_events>
@ -101,6 +108,7 @@
<conc val="broken"/> <conc val="broken"/>
<alternate_names val="none"/> <alternate_names val="none"/>
<prefix val="no"/> <prefix val="no"/>
<endl val="\r\n"/>
<calendar val="no"/> <calendar val="no"/>
<extended_events> <extended_events>
</extended_events> </extended_events>
@ -114,6 +122,7 @@
<conc val="broken"/> <conc val="broken"/>
<alternate_names val="_alias"/> <alternate_names val="_alias"/>
<prefix val="no"/> <prefix val="no"/>
<endl val="\r\n"/>
<calendar val="no"/> <calendar val="no"/>
<extended_events> <extended_events>
</extended_events> </extended_events>
@ -127,6 +136,7 @@
<conc val="broken"/> <conc val="broken"/>
<alternate_names val="none"/> <alternate_names val="none"/>
<prefix val="no"/> <prefix val="no"/>
<endl val="\r\n"/>
<calendar val="no"/> <calendar val="no"/>
<extended_events> <extended_events>
</extended_events> </extended_events>

View File

@ -250,14 +250,14 @@ def make_date(subdate):
# #
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
def fmtline(text,limit,level): def fmtline(text,limit,level,endl):
new_text = [] new_text = []
while len(text) > limit: while len(text) > limit:
new_text.append(text[0:limit-1]) new_text.append(text[0:limit-1])
text = text[limit:] text = text[limit:]
if len(text) > 0: if len(text) > 0:
new_text.append(text) new_text.append(text)
app = "\n%d CONC " % (level+1) app = "%s%d CONC " % (endl,level+1)
return string.join(new_text,app) return string.join(new_text,app)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -399,7 +399,7 @@ class GedcomWriter:
filter_obj.set_menu(self.filter_menu) filter_obj.set_menu(self.filter_menu)
gedmap = GedcomInfo.GedcomInfoDB() gedmap = GedcomInfo.GedcomInfoDB()
target_obj = self.topDialog.get_widget("target") target_obj = self.topDialog.get_widget("target")
myMenu = gtk.Menu() myMenu = gtk.Menu()
for name in gedmap.get_name_list(): for name in gedmap.get_name_list():
@ -437,6 +437,7 @@ class GedcomWriter:
act_tgt = self.target_menu.get_active() act_tgt = self.target_menu.get_active()
self.target_ged = act_tgt.get_data("data") self.target_ged = act_tgt.get_data("data")
self.nl = self.target_ged.get_endl()
self.dest = self.target_ged.get_dest() self.dest = self.target_ged.get_dest()
self.adopt = self.target_ged.get_adopt() self.adopt = self.target_ged.get_adopt()
@ -538,6 +539,9 @@ class GedcomWriter:
self.export_data(self.name) self.export_data(self.name)
def writeln(self,text):
self.g.write('%s%s' % (text,self.nl))
def export_data(self,filename): def export_data(self,filename):
try: try:
self.g = open(filename,"w") self.g = open(filename,"w")
@ -553,56 +557,56 @@ class GedcomWriter:
date = string.split(time.ctime(time.time())) date = string.split(time.ctime(time.time()))
self.g.write("0 HEAD\n") self.writeln("0 HEAD")
self.g.write("1 SOUR GRAMPS\n") self.writeln("1 SOUR GRAMPS")
self.g.write("2 VERS %s\n" % const.version) self.writeln("2 VERS %s" % const.version)
self.g.write("2 NAME GRAMPS\n") self.writeln("2 NAME GRAMPS")
if self.dest: if self.dest:
self.g.write("1 DEST %s\n" % self.dest) self.writeln("1 DEST %s" % self.dest)
self.g.write("1 DATE %s %s %s\n" % (date[2],string.upper(date[1]),date[4])) self.writeln("1 DATE %s %s %s" % (date[2],string.upper(date[1]),date[4]))
if self.cnvtxt == ansel_utf8.utf8_to_ansel: if self.cnvtxt == ansel_utf8.utf8_to_ansel:
self.g.write("1 CHAR ANSEL\n") self.writeln("1 CHAR ANSEL")
elif self.cnvtxt == iso8859: elif self.cnvtxt == iso8859:
self.g.write("1 CHAR ANSI\n") self.writeln("1 CHAR ANSI")
else: else:
self.g.write("1 CHAR UTF-8\n") self.writeln("1 CHAR UTF-8")
self.g.write("1 SUBM @SUBM@\n") self.writeln("1 SUBM @SUBM@")
self.g.write("1 FILE %s\n" % filename) self.writeln("1 FILE %s" % filename)
self.write_copy() self.write_copy()
self.g.write("1 GEDC\n") self.writeln("1 GEDC")
self.g.write("2 VERS 5.5\n") self.writeln("2 VERS 5.5")
self.g.write('2 FORM LINEAGE-LINKED\n') self.writeln('2 FORM LINEAGE-LINKED')
self.gnu_fdl() self.gnu_fdl()
self.g.write("0 @SUBM@ SUBM\n") self.writeln("0 @SUBM@ SUBM")
owner = self.db.getResearcher() owner = self.db.getResearcher()
if owner.getName(): if owner.getName():
self.g.write("1 NAME %s\n" % self.cnvtxt(owner.getName())) self.writeln("1 NAME %s" % self.cnvtxt(owner.getName()))
else: else:
self.g.write('1 NAME Not Provided\n') self.writeln('1 NAME Not Provided')
if owner.getAddress(): if owner.getAddress():
cnt = 0 cnt = 0
self.g.write("1 ADDR %s\n" % self.cnvtxt(owner.getAddress())) self.writeln("1 ADDR %s" % self.cnvtxt(owner.getAddress()))
if owner.getCity(): if owner.getCity():
self.g.write("2 CONT %s\n" % self.cnvtxt(owner.getCity())) self.writeln("2 CONT %s" % self.cnvtxt(owner.getCity()))
cnt = 1 cnt = 1
if owner.getState(): if owner.getState():
self.g.write("2 CONT %s\n" % self.cnvtxt(owner.getState())) self.writeln("2 CONT %s" % self.cnvtxt(owner.getState()))
cnt = 1 cnt = 1
if owner.getPostalCode(): if owner.getPostalCode():
self.g.write("2 CONT %s\n" % self.cnvtxt(owner.getPostalCode())) self.writeln("2 CONT %s" % self.cnvtxt(owner.getPostalCode()))
cnt = 1 cnt = 1
if owner.getCountry(): if owner.getCountry():
self.g.write("2 CONT %s\n" % self.cnvtxt(owner.getCountry())) self.writeln("2 CONT %s" % self.cnvtxt(owner.getCountry()))
cnt = 1 cnt = 1
if owner.getPhone(): if owner.getPhone():
self.g.write("2 PHON %s\n" % self.cnvtxt(owner.getPhone())) self.writeln("2 PHON %s" % self.cnvtxt(owner.getPhone()))
cnt = 1 cnt = 1
if cnt == 0: if cnt == 0:
self.g.write('2 CONT Not Provided\n') self.writeln('2 CONT Not Provided')
else: else:
self.g.write('1 ADDR Not Provided\n') self.writeln('1 ADDR Not Provided')
self.g.write('2 CONT Not Provided\n') self.writeln('2 CONT Not Provided')
pkeys = self.plist.keys() pkeys = self.plist.keys()
pkeys.sort() pkeys.sort()
@ -625,7 +629,7 @@ class GedcomWriter:
if not self.cl: if not self.cl:
self.sbar.set_fraction(1.0) self.sbar.set_fraction(1.0)
self.g.write("0 TRLR\n") self.writeln("0 TRLR")
self.g.close() self.g.close()
def write_copy(self): def write_copy(self):
@ -636,10 +640,10 @@ class GedcomWriter:
if self.copy == 0: if self.copy == 0:
o = self.db.getResearcher().getName() o = self.db.getResearcher().getName()
self.g.write('1 COPR Copyright (c) %d %s.\n' % (y,o)) self.writeln('1 COPR Copyright (c) %d %s.' % (y,o))
elif self.copy == 1: elif self.copy == 1:
o = self.db.getResearcher().getName() o = self.db.getResearcher().getName()
self.g.write('1 COPR Copyright (c) %d %s. See additional copyright NOTE below.\n' % (y,o)) self.writeln('1 COPR Copyright (c) %d %s. See additional copyright NOTE below.' % (y,o))
def gnu_fdl(self): def gnu_fdl(self):
import time import time
@ -651,7 +655,7 @@ class GedcomWriter:
y = t[0] y = t[0]
o = self.db.getResearcher().getName() o = self.db.getResearcher().getName()
self.g.write('1 NOTE Copyright (c) %d %s.\n' % (y,o)) self.writeln('1 NOTE Copyright (c) %d %s.' % (y,o))
try: try:
f = open(const.fdl,"r") f = open(const.fdl,"r")
for line in f.readlines(): for line in f.readlines():
@ -666,16 +670,16 @@ class GedcomWriter:
for key in self.flist.keys(): for key in self.flist.keys():
family = self.db.getFamily(key) family = self.db.getFamily(key)
father_alive = mother_alive = 0 father_alive = mother_alive = 0
self.g.write("0 @%s@ FAM\n" % self.fid(family.getId())) self.writeln("0 @%s@ FAM" % self.fid(family.getId()))
self.prefn(family) self.prefn(family)
person = family.getFather() person = family.getFather()
if person != None and self.plist.has_key(person.getId()): if person != None and self.plist.has_key(person.getId()):
self.g.write("1 HUSB @%s@\n" % self.pid(person.getId())) self.writeln("1 HUSB @%s@" % self.pid(person.getId()))
father_alive = person.probablyAlive() father_alive = person.probablyAlive()
person = family.getMother() person = family.getMother()
if person != None and self.plist.has_key(person.getId()): if person != None and self.plist.has_key(person.getId()):
self.g.write("1 WIFE @%s@\n" % self.pid(person.getId())) self.writeln("1 WIFE @%s@" % self.pid(person.getId()))
mother_alive = person.probablyAlive() mother_alive = person.probablyAlive()
if not self.restrict or ( not father_alive and not mother_alive ): if not self.restrict or ( not father_alive and not mother_alive ):
@ -692,32 +696,32 @@ class GedcomWriter:
val = self.target_ged.gramps2tag(name) val = self.target_ged.gramps2tag(name)
if val: if val:
self.g.write("1 %s %s\n" % (self.cnvtxt(val), self.writeln("1 %s %s" % (self.cnvtxt(val),
self.cnvtxt(event.getDescription()))) self.cnvtxt(event.getDescription())))
else: else:
self.g.write("1 EVEN %s\n" % self.cnvtxt(event.getDescription())) self.writeln("1 EVEN %s" % self.cnvtxt(event.getDescription()))
self.g.write("2 TYPE %s\n" % self.cnvtxt(name)) self.writeln("2 TYPE %s" % self.cnvtxt(name))
self.dump_event_stats(event) self.dump_event_stats(event)
for person in family.getChildList(): for person in family.getChildList():
if not self.plist.has_key(person.getId()): if not self.plist.has_key(person.getId()):
continue continue
self.g.write("1 CHIL @%s@\n" % self.pid(person.getId())) self.writeln("1 CHIL @%s@" % self.pid(person.getId()))
if self.adopt == GedcomInfo.ADOPT_FTW: if self.adopt == GedcomInfo.ADOPT_FTW:
if person.getMainParents() == family: if person.getMainParents() == family:
self.g.write('2 _FREL Natural\n') self.writeln('2 _FREL Natural')
self.g.write('2 _MREL Natural\n') self.writeln('2 _MREL Natural')
else: else:
for f in person.getParentList(): for f in person.getParentList():
if f[0] == family: if f[0] == family:
self.g.write('2 _FREL %s\n' % f[2]) self.writeln('2 _FREL %s' % f[2])
self.g.write('2 _MREL %s\n' % f[1]) self.writeln('2 _MREL %s' % f[1])
break break
if self.adopt == GedcomInfo.ADOPT_LEGACY: if self.adopt == GedcomInfo.ADOPT_LEGACY:
for f in person.getAltParentList(): for f in person.getAltParentList():
if f[0] == family: if f[0] == family:
self.g.write('2 _STAT %s\n' % f[2]) self.writeln('2 _STAT %s' % f[2])
break break
index = index + 1 index = index + 1
@ -733,17 +737,17 @@ class GedcomWriter:
index = 0.0 index = 0.0
for key in self.slist.keys(): for key in self.slist.keys():
source = self.db.getSource(key) source = self.db.getSource(key)
self.g.write("0 @%s@ SOUR\n" % self.sid(source.getId())) self.writeln("0 @%s@ SOUR" % self.sid(source.getId()))
if source.getTitle(): if source.getTitle():
self.g.write("1 TITL %s\n" % fmtline(self.cnvtxt(source.getTitle()),248,1)) self.writeln("1 TITL %s" % fmtline(self.cnvtxt(source.getTitle()),248,1,self.nl))
if source.getAuthor(): if source.getAuthor():
self.g.write("1 AUTH %s\n" % self.cnvtxt(source.getAuthor())) self.writeln("1 AUTH %s" % self.cnvtxt(source.getAuthor()))
if source.getPubInfo(): if source.getPubInfo():
self.g.write("1 PUBL %s\n" % self.cnvtxt(source.getPubInfo())) self.writeln("1 PUBL %s" % self.cnvtxt(source.getPubInfo()))
if source.getTitle(): if source.getTitle():
self.g.write("1 ABBR %s\n" % self.cnvtxt(source.getTitle())) self.writeln("1 ABBR %s" % self.cnvtxt(source.getTitle()))
if source.getCallNumber(): if source.getCallNumber():
self.g.write("1 CALN %s\n" % self.cnvtxt(source.getCallNumber())) self.writeln("1 CALN %s" % self.cnvtxt(source.getCallNumber()))
if source.getNote(): if source.getNote():
self.write_long_text("NOTE",1,self.cnvtxt(source.getNote())) self.write_long_text("NOTE",1,self.cnvtxt(source.getNote()))
index = index + 1 index = index + 1
@ -755,7 +759,7 @@ class GedcomWriter:
self.sbar.set_fraction(1.0) self.sbar.set_fraction(1.0)
def write_person(self,person): def write_person(self,person):
self.g.write("0 @%s@ INDI\n" % self.pid(person.getId())) self.writeln("0 @%s@ INDI" % self.pid(person.getId()))
self.prefn(person) self.prefn(person)
self.write_person_name(person.getPrimaryName(),person.getNickName()) self.write_person_name(person.getPrimaryName(),person.getNickName())
@ -764,27 +768,27 @@ class GedcomWriter:
self.write_person_name(name,"") self.write_person_name(name,"")
if person.getGender() == RelLib.Person.male: if person.getGender() == RelLib.Person.male:
self.g.write("1 SEX M\n") self.writeln("1 SEX M")
elif person.getGender() == RelLib.Person.female: elif person.getGender() == RelLib.Person.female:
self.g.write("1 SEX F\n") self.writeln("1 SEX F")
if not self.restrict or not person.probablyAlive(): if not self.restrict or not person.probablyAlive():
birth = person.getBirth() birth = person.getBirth()
if not (self.private and birth.getPrivacy()): if not (self.private and birth.getPrivacy()):
if not birth.getDateObj().isEmpty() or birth.getPlaceName(): if not birth.getDateObj().isEmpty() or birth.getPlaceName():
self.g.write("1 BIRT\n") self.writeln("1 BIRT")
self.dump_event_stats(birth) self.dump_event_stats(birth)
death = person.getDeath() death = person.getDeath()
if not (self.private and death.getPrivacy()): if not (self.private and death.getPrivacy()):
if not death.getDateObj().isEmpty() or death.getPlaceName(): if not death.getDateObj().isEmpty() or death.getPlaceName():
self.g.write("1 DEAT\n") self.writeln("1 DEAT")
self.dump_event_stats(death) self.dump_event_stats(death)
uid = person.getPafUid() uid = person.getPafUid()
if uid: if uid:
self.g.write("1 _UID %s\n" % uid) self.writeln("1 _UID %s" % uid)
ad = 0 ad = 0
@ -804,7 +808,7 @@ class GedcomWriter:
if self.adopt == GedcomInfo.ADOPT_EVENT and val == "ADOP": if self.adopt == GedcomInfo.ADOPT_EVENT and val == "ADOP":
ad = 1 ad = 1
self.g.write('1 ADOP\n') self.writeln('1 ADOP')
fam = None fam = None
for f in person.getParentList(): for f in person.getParentList():
mrel = string.lower(f[1]) mrel = string.lower(f[1])
@ -813,24 +817,24 @@ class GedcomWriter:
fam = f[0] fam = f[0]
break break
if fam: if fam:
self.g.write('2 FAMC @%s@\n' % self.fid(fam.getId())) self.writeln('2 FAMC @%s@' % self.fid(fam.getId()))
if mrel == frel: if mrel == frel:
self.g.write('3 ADOP BOTH\n') self.writeln('3 ADOP BOTH')
elif mrel == "adopted": elif mrel == "adopted":
self.g.write('3 ADOP WIFE\n') self.writeln('3 ADOP WIFE')
else: else:
self.g.write('3 ADOP HUSB\n') self.writeln('3 ADOP HUSB')
elif val : elif val :
self.g.write("1 %s %s\n" % (self.cnvtxt(val),\ self.writeln("1 %s %s" % (self.cnvtxt(val),\
self.cnvtxt(event.getDescription()))) self.cnvtxt(event.getDescription())))
else: else:
self.g.write("1 EVEN %s\n" % self.cnvtxt(event.getDescription())) self.writeln("1 EVEN %s" % self.cnvtxt(event.getDescription()))
self.g.write("2 TYPE %s\n" % self.cnvtxt(event.getName())) self.writeln("2 TYPE %s" % self.cnvtxt(event.getName()))
self.dump_event_stats(event) self.dump_event_stats(event)
if self.adopt == GedcomInfo.ADOPT_EVENT and ad == 0 and len(person.getParentList()) != 0: if self.adopt == GedcomInfo.ADOPT_EVENT and ad == 0 and len(person.getParentList()) != 0:
self.g.write('1 ADOP\n') self.writeln('1 ADOP')
fam = None fam = None
for f in person.getParentList(): for f in person.getParentList():
mrel = string.lower(f[1]) mrel = string.lower(f[1])
@ -839,13 +843,13 @@ class GedcomWriter:
fam = f[0] fam = f[0]
break break
if fam: if fam:
self.g.write('2 FAMC @%s@\n' % self.fid(fam.getId())) self.writeln('2 FAMC @%s@' % self.fid(fam.getId()))
if mrel == frel: if mrel == frel:
self.g.write('3 ADOP BOTH\n') self.writeln('3 ADOP BOTH')
elif mrel == "adopted": elif mrel == "adopted":
self.g.write('3 ADOP WIFE\n') self.writeln('3 ADOP WIFE')
else: else:
self.g.write('3 ADOP HUSB\n') self.writeln('3 ADOP HUSB')
for attr in person.getAttributeList(): for attr in person.getAttributeList():
if self.private and attr.getPrivacy(): if self.private and attr.getPrivacy():
@ -856,11 +860,11 @@ class GedcomWriter:
else: else:
val = "" val = ""
if val : if val :
self.g.write("1 %s\n" % val) self.writeln("1 %s" % val)
else: else:
self.g.write("1 EVEN\n") self.writeln("1 EVEN")
self.g.write("2 TYPE %s\n" % self.cnvtxt(name)) self.writeln("2 TYPE %s" % self.cnvtxt(name))
self.g.write("2 PLAC %s\n" % string.replace(self.cnvtxt(attr.getValue()),'\r',' ')) self.writeln("2 PLAC %s" % string.replace(self.cnvtxt(attr.getValue()),'\r',' '))
if attr.getNote(): if attr.getNote():
self.write_long_text("NOTE",2,self.cnvtxt(attr.getNote())) self.write_long_text("NOTE",2,self.cnvtxt(attr.getNote()))
for srcref in attr.getSourceRefList(): for srcref in attr.getSourceRefList():
@ -869,18 +873,18 @@ class GedcomWriter:
for addr in person.getAddressList(): for addr in person.getAddressList():
if self.private and addr.getPrivacy(): if self.private and addr.getPrivacy():
continue continue
self.g.write("1 RESI\n") self.writeln("1 RESI")
self.print_date("2 DATE",addr.getDateObj()) self.print_date("2 DATE",addr.getDateObj())
if self.resi == 0: if self.resi == 0:
self.write_long_text("ADDR",2,self.cnvtxt(addr.getStreet())) self.write_long_text("ADDR",2,self.cnvtxt(addr.getStreet()))
if addr.getCity(): if addr.getCity():
self.g.write("3 CITY %s\n" % self.cnvtxt(addr.getCity())) self.writeln("3 CITY %s" % self.cnvtxt(addr.getCity()))
if addr.getState(): if addr.getState():
self.g.write("3 STAE %s\n" % self.cnvtxt(addr.getState())) self.writeln("3 STAE %s" % self.cnvtxt(addr.getState()))
if addr.getPostal(): if addr.getPostal():
self.g.write("3 POST %s\n" % self.cnvtxt(addr.getPostal())) self.writeln("3 POST %s" % self.cnvtxt(addr.getPostal()))
if addr.getCountry(): if addr.getCountry():
self.g.write("3 CTRY %s\n" % self.cnvtxt(addr.getCountry())) self.writeln("3 CTRY %s" % self.cnvtxt(addr.getCountry()))
else: else:
text = addr.getStreet() text = addr.getStreet()
text = addr_append(text,addr.getCity()) text = addr_append(text,addr.getCity())
@ -888,7 +892,7 @@ class GedcomWriter:
text = addr_append(text,addr.getPostal()) text = addr_append(text,addr.getPostal())
text = addr_append(text,addr.getCountry()) text = addr_append(text,addr.getCountry())
if text: if text:
self.g.write("2 PLAC %s\n" % string.replace(self.cnvtxt(text),'\r',' ')) self.writeln("2 PLAC %s" % string.replace(self.cnvtxt(text),'\r',' '))
if addr.getNote(): if addr.getNote():
self.write_long_text("NOTE",2,self.cnvtxt(addr.getNote())) self.write_long_text("NOTE",2,self.cnvtxt(addr.getNote()))
for srcref in addr.getSourceRefList(): for srcref in addr.getSourceRefList():
@ -896,23 +900,23 @@ class GedcomWriter:
for family in person.getParentList(): for family in person.getParentList():
if self.flist.has_key(family[0].getId()): if self.flist.has_key(family[0].getId()):
self.g.write("1 FAMC @%s@\n" % self.fid(family[0].getId())) self.writeln("1 FAMC @%s@" % self.fid(family[0].getId()))
if self.adopt == GedcomInfo.ADOPT_PEDI: if self.adopt == GedcomInfo.ADOPT_PEDI:
if string.lower(family[1]) == "adopted": if string.lower(family[1]) == "adopted":
self.g.write("2 PEDI Adopted\n") self.writeln("2 PEDI Adopted")
for family in person.getFamilyList(): for family in person.getFamilyList():
if family != None and self.flist.has_key(family.getId()): if family != None and self.flist.has_key(family.getId()):
self.g.write("1 FAMS @%s@\n" % self.fid(family.getId())) self.writeln("1 FAMS @%s@" % self.fid(family.getId()))
if self.obje: if self.obje:
for url in person.getUrlList(): for url in person.getUrlList():
self.g.write('1 OBJE\n') self.writeln('1 OBJE')
self.g.write('2 FORM URL\n') self.writeln('2 FORM URL')
if url.get_description(): if url.get_description():
self.g.write('2 TITL %s\n' % url.get_description()) self.writeln('2 TITL %s' % url.get_description())
if url.get_path(): if url.get_path():
self.g.write('2 FILE %s\n' % url.get_path()) self.writeln('2 FILE %s' % url.get_path())
if person.getNote(): if person.getNote():
self.write_long_text("NOTE",1,self.cnvtxt(person.getNote())) self.write_long_text("NOTE",1,self.cnvtxt(person.getNote()))
@ -927,7 +931,7 @@ class GedcomWriter:
prefix = "%d %s" % (level,tag) prefix = "%d %s" % (level,tag)
textlines = string.split(note,'\n') textlines = string.split(note,'\n')
if len(note) == 0: if len(note) == 0:
self.g.write("%s\n" % prefix) self.writeln(prefix)
else: else:
for line in textlines: for line in textlines:
ll = len(line) ll = len(line)
@ -937,14 +941,14 @@ class GedcomWriter:
while (ll > brkpt and line[brkpt] in string.whitespace): while (ll > brkpt and line[brkpt] in string.whitespace):
brkpt = brkpt+1 brkpt = brkpt+1
if ll == brkpt: if ll == brkpt:
self.g.write("%s %s\n" % (prefix,line)) self.writeln("%s %s" % (prefix,line))
line = '' line = ''
break break
else: else:
self.g.write("%s %s\n" % (prefix,line[0:brkpt+1])) self.writeln("%s %s" % (prefix,line[0:brkpt+1]))
line = line[brkpt+1:] line = line[brkpt+1:]
else: else:
self.g.write("%s %s\n" % (prefix,line)) self.writeln("%s %s" % (prefix,line))
line = "" line = ""
if len(line) > 0: if len(line) > 0:
prefix = "%d CONC" % (level+1) prefix = "%d CONC" % (level+1)
@ -956,7 +960,7 @@ class GedcomWriter:
prefix = "%d %s" % (level,tag) prefix = "%d %s" % (level,tag)
textlines = string.split(note,'\n') textlines = string.split(note,'\n')
if len(note) == 0: if len(note) == 0:
self.g.write("%s\n" % prefix) self.writeln(prefix)
else: else:
for line in textlines: for line in textlines:
ll = len(line) ll = len(line)
@ -966,14 +970,14 @@ class GedcomWriter:
while (ll > brkpt and line[brkpt] not in string.whitespace): while (ll > brkpt and line[brkpt] not in string.whitespace):
brkpt = brkpt+1 brkpt = brkpt+1
if ll == brkpt: if ll == brkpt:
self.g.write("%s %s\n" % (prefix,line)) self.writeln("%s %s" % (prefix,line))
line = '' line = ''
break break
else: else:
self.g.write("%s %s\n" % (prefix,line[0:brkpt+1])) self.writeln("%s %s" % (prefix,line[0:brkpt+1]))
line = line[brkpt+1:] line = line[brkpt+1:]
else: else:
self.g.write("%s %s\n" % (prefix,line)) self.writeln("%s %s" % (prefix,line))
line = "" line = ""
if len(line) > 0: if len(line) > 0:
prefix = "%d CONC" % (level+1) prefix = "%d CONC" % (level+1)
@ -985,9 +989,9 @@ class GedcomWriter:
dateobj = event.getDateObj() dateobj = event.getDateObj()
self.print_date("2 DATE",dateobj) self.print_date("2 DATE",dateobj)
if event.getPlaceName(): if event.getPlaceName():
self.g.write("2 PLAC %s\n" % string.replace(self.cnvtxt(event.getPlaceName()),'\r',' ')) self.writeln("2 PLAC %s" % string.replace(self.cnvtxt(event.getPlaceName()),'\r',' '))
if event.getCause(): if event.getCause():
self.g.write("2 CAUS %s\n" % self.cnvtxt(event.getCause())) self.writeln("2 CAUS %s" % self.cnvtxt(event.getCause()))
if event.getNote(): if event.getNote():
self.write_long_text("NOTE",2,self.cnvtxt(event.getNote())) self.write_long_text("NOTE",2,self.cnvtxt(event.getNote()))
for srcref in event.getSourceRefList(): for srcref in event.getSourceRefList():
@ -996,16 +1000,16 @@ class GedcomWriter:
def write_ord(self,name,ord,index,statlist): def write_ord(self,name,ord,index,statlist):
if ord == None: if ord == None:
return return
self.g.write('%d %s\n' % (index,name)) self.writeln('%d %s' % (index,name))
self.print_date("%d DATE" % (index + 1), ord.getDateObj()) self.print_date("%d DATE" % (index + 1), ord.getDateObj())
if ord.getFamily(): if ord.getFamily():
self.g.write('%d FAMC @%s@\n' % (index+1,self.fid(ord.getFamily().getId()))) self.writeln('%d FAMC @%s@' % (index+1,self.fid(ord.getFamily().getId())))
if ord.getTemple(): if ord.getTemple():
self.g.write('%d TEMP %s\n' % (index+1,ord.getTemple())) self.writeln('%d TEMP %s' % (index+1,ord.getTemple()))
if ord.getPlaceName(): if ord.getPlaceName():
self.g.write("2 PLAC %s\n" % string.replace(self.cnvtxt(ord.getPlaceName()),'\r',' ')) self.writeln("2 PLAC %s" % string.replace(self.cnvtxt(ord.getPlaceName()),'\r',' '))
if ord.getStatus() != 0: if ord.getStatus() != 0:
self.g.write("2 STAT %s\n" % self.cnvtxt(statlist[ord.getStatus()])) self.writeln("2 STAT %s" % self.cnvtxt(statlist[ord.getStatus()]))
if ord.getNote(): if ord.getNote():
self.write_long_text("NOTE",index+1,self.cnvtxt(ord.getNote())) self.write_long_text("NOTE",index+1,self.cnvtxt(ord.getNote()))
for srcref in ord.getSourceRefList(): for srcref in ord.getSourceRefList():
@ -1016,14 +1020,14 @@ class GedcomWriter:
if date.isEmpty(): if date.isEmpty():
val = date.getText() val = date.getText()
if val: if val:
self.g.write("%s %s\n" % (prefix,self.cnvtxt(val))) self.writeln("%s %s" % (prefix,self.cnvtxt(val)))
else: else:
if date.isRange(): if date.isRange():
val = "FROM %s TO %s" % (make_date(start), val = "FROM %s TO %s" % (make_date(start),
make_date(date.get_stop_date())) make_date(date.get_stop_date()))
else: else:
val = make_date(start) val = make_date(start)
self.g.write("%s %s\n" % (prefix,val)) self.writeln("%s %s" % (prefix,val))
def write_person_name(self,name,nick): def write_person_name(self,name,nick):
firstName = self.cnvtxt(name.getFirstName()) firstName = self.cnvtxt(name.getFirstName())
@ -1033,34 +1037,34 @@ class GedcomWriter:
title = self.cnvtxt(name.getTitle()) title = self.cnvtxt(name.getTitle())
if suffix == "": if suffix == "":
if not surPref: if not surPref:
self.g.write("1 NAME %s /%s/\n" % (firstName,surName)) self.writeln("1 NAME %s /%s/" % (firstName,surName))
else: else:
self.g.write("1 NAME %s /%s %s/\n" % (firstName,surPref,surName)) self.writeln("1 NAME %s /%s %s/" % (firstName,surPref,surName))
else: else:
if not surPref: if not surPref:
self.g.write("1 NAME %s /%s %s/, %s\n" % (firstName,surPref,surName,suffix)) self.writeln("1 NAME %s /%s %s/, %s" % (firstName,surPref,surName,suffix))
else: else:
self.g.write("1 NAME %s /%s/, %s\n" % (firstName,surName,suffix)) self.writeln("1 NAME %s /%s/, %s" % (firstName,surName,suffix))
if name.getFirstName(): if name.getFirstName():
self.g.write("2 GIVN %s\n" % firstName) self.writeln("2 GIVN %s" % firstName)
if self.prefix: if self.prefix:
if surPref: if surPref:
self.g.write('2 SPFX %s\n' % surPref) self.writeln('2 SPFX %s' % surPref)
if surName: if surName:
self.g.write("2 SURN %s\n" % surName) self.writeln("2 SURN %s" % surName)
else: else:
if surPref: if surPref:
self.g.write("2 SURN %s %s\n" % (surPref,surName)) self.writeln("2 SURN %s %s" % (surPref,surName))
elif surName: elif surName:
self.g.write("2 SURN %s\n" % surName) self.writeln("2 SURN %s" % surName)
if name.getSuffix(): if name.getSuffix():
self.g.write("2 NSFX %s\n" % suffix) self.writeln("2 NSFX %s" % suffix)
if name.getTitle(): if name.getTitle():
self.g.write("2 NPFX %s\n" % title) self.writeln("2 NPFX %s" % title)
if nick: if nick:
self.g.write('2 NICK %s\n' % nick) self.writeln('2 NICK %s' % nick)
if name.getNote(): if name.getNote():
self.write_long_text("NOTE",2,self.cnvtxt(name.getNote())) self.write_long_text("NOTE",2,self.cnvtxt(name.getNote()))
for srcref in name.getSourceRefList(): for srcref in name.getSourceRefList():
@ -1071,14 +1075,14 @@ class GedcomWriter:
return return
if self.source_refs: if self.source_refs:
self.g.write("%d SOUR @%s@\n" % self.writeln("%d SOUR @%s@" %
(level,self.sid(ref.getBase().getId()))) (level,self.sid(ref.getBase().getId())))
if ref.getPage() != "": if ref.getPage() != "":
self.g.write("%d PAGE %s\n" % (level+1,ref.getPage())) self.writeln("%d PAGE %s" % (level+1,ref.getPage()))
ref_text = ref.getText() ref_text = ref.getText()
if ref_text != "" or not ref.getDate().isEmpty(): if ref_text != "" or not ref.getDate().isEmpty():
self.g.write('%d DATA\n' % (level+1)) self.writeln('%d DATA' % (level+1))
if ref_text != "": if ref_text != "":
self.write_long_text("TEXT",level+2,self.cnvtxt(ref_text)) self.write_long_text("TEXT",level+2,self.cnvtxt(ref_text))
pfx = "%d DATE" % (level+2) pfx = "%d DATE" % (level+2)
@ -1099,7 +1103,7 @@ class GedcomWriter:
if not ref.getDate().isEmpty(): if not ref.getDate().isEmpty():
self.print_date("", ref.getDate()) self.print_date("", ref.getDate())
else: else:
self.g.write("\n") self.writeln("")
if ref.getText(): if ref.getText():
self.write_long_text("TEXT",level+1,self.cnvtxt(ref_text)) self.write_long_text("TEXT",level+1,self.cnvtxt(ref_text))
@ -1112,12 +1116,12 @@ class GedcomWriter:
def prefn(self,person): def prefn(self,person):
match = _get_int.search(person.getId()) match = _get_int.search(person.getId())
if match: if match:
self.g.write('1 REFN %d\n' % int(match.groups()[0])) self.writeln('1 REFN %d' % int(match.groups()[0]))
def frefn(self,family): def frefn(self,family):
match = _get_int.search(family.getId()) match = _get_int.search(family.getId())
if match: if match:
self.g.write('1 REFN %d\n' % int(match.groups()[0])) self.writeln('1 REFN %d' % int(match.groups()[0]))
def pid(self,id): def pid(self,id):
return id return id