* src/WriteGedcom.py: export more objects, better conformance with

the spec, preserve timestamps on objects
* src/const.py.in: add table of GEDCOM tags that take a value on the
same line


svn: r5346
This commit is contained in:
Julio Sánchez 2005-10-24 19:50:05 +00:00
parent 3aab27ab99
commit 1e404f7146
3 changed files with 123 additions and 40 deletions

View File

@ -1,3 +1,9 @@
2005-10-24 Julio Sanchez <jsanchez@users.sourceforge.net>
* src/WriteGedcom.py: export more objects, better conformance with
the spec, preserve timestamps on objects
* src/const.py.in: add table of GEDCOM tags that take a value on the
same line
2005-10-23 Don Allingham <don@gramps-project.org>
* src/ReadGedcom.py: handle progress bar
* src/gedcomimport.glade: add progress bar and expanders

View File

@ -717,11 +717,16 @@ class GedcomWriter:
val = self.target_ged.gramps2tag(name)
if val:
self.writeln("1 %s %s" % (self.cnvtxt(val),
self.cnvtxt(event.get_description())))
if not event.get_date_object().is_empty() or event.get_place_handle():
self.writeln("1 %s" % self.cnvtxt(val))
else:
self.writeln("1 %s Y" % self.cnvtxt(val))
if event.get_description() != "":
self.writeln("2 TYPE %s" % event.get_description())
else:
self.writeln("1 EVEN %s" % self.cnvtxt(event.get_description()))
self.writeln("2 TYPE %s" % self.cnvtxt(name))
self.writeln("1 EVEN")
self.writeln("2 TYPE %s" % ' '.join([self.cnvtxt(name),
event.get_description()]))
self.dump_event_stats(event)
@ -753,13 +758,10 @@ class GedcomWriter:
if self.images:
photos = family.get_media_list ()
else:
photos = []
for photo in photos:
if self.private and photo.get_privacy():
continue
self.write_photo(photo,1)
for photo in photos:
if self.private and photo.get_privacy():
continue
self.write_photo(photo,1)
self.write_change(1,family.get_change_time())
@ -783,6 +785,13 @@ class GedcomWriter:
self.writeln("1 PUBL %s" % self.cnvtxt(source.get_publication_info()))
if source.get_abbreviation():
self.writeln("1 ABBR %s" % self.cnvtxt(source.get_abbreviation()))
if self.images:
photos = source.get_media_list ()
for photo in photos:
if self.private and photo.get_privacy():
continue
self.write_photo(photo,1)
if source.get_note():
self.write_long_text("NOTE",1,self.cnvtxt(source.get_note()))
index = index + 1
@ -826,21 +835,23 @@ class GedcomWriter:
birth = self.db.get_event_from_handle(birth_handle)
if birth_handle and birth and not (self.private and birth.get_privacy()):
if not birth.get_date_object().is_empty() or birth.get_place_handle():
if birth.get_description() != "":
self.writeln("1 BIRT %s" % birth.get_description())
else:
self.writeln("1 BIRT")
self.dump_event_stats(birth)
self.writeln("1 BIRT")
else:
self.writeln("1 BIRT Y")
if birth.get_description() != "":
self.writeln("2 TYPE %s" % birth.get_description())
self.dump_event_stats(birth)
death_handle = person.get_death_handle()
death = self.db.get_event_from_handle(death_handle)
if death_handle and death and not (self.private and death.get_privacy()):
if not death.get_date_object().is_empty() or death.get_place_handle():
if death.get_description() != "":
self.writeln("1 DEAT %s" % death.get_description())
else:
self.writeln("1 DEAT")
self.dump_event_stats(death)
self.writeln("1 DEAT")
else:
self.writeln("1 DEAT Y")
if death.get_description() != "":
self.writeln("2 TYPE %s" % death.get_description())
self.dump_event_stats(death)
ad = 0
@ -883,12 +894,29 @@ class GedcomWriter:
else:
self.writeln('3 ADOP HUSB')
elif val :
self.writeln("1 %s %s" % (self.cnvtxt(val),\
self.cnvtxt(event.get_description())))
if const.personalGedcomAttributeTakesParam.has_key(val):
if event.get_description():
self.writeln("1 %s %s" % (self.cnvtxt(val),\
self.cnvtxt(event.get_description())))
else:
self.writeln("1 %s" % self.cnvtxt(val))
else:
if not event.get_date_object().is_empty() or event.get_place_handle():
self.writeln("1 %s" % self.cnvtxt(val))
else:
self.writeln("1 %s Y" % self.cnvtxt(val))
if event.get_description():
self.writeln("2 TYPE %s" % self.cnvtxt(event.get_description()))
else:
self.writeln("1 EVEN %s" % self.cnvtxt(event.get_description()))
self.writeln("2 TYPE %s" % self.cnvtxt(event.get_name()))
# Actually, it is against the spec to put anything
# after EVEN on the same line, possibly an option is
# needed on how to handle this
if event.get_description() != "":
self.writeln("1 EVEN %s" % event.get_description())
else:
self.writeln("1 EVEN")
self.writeln("2 TYPE %s" % self.cnvtxt(name))
self.dump_event_stats(event)
if self.adopt == GedcomInfo.ADOPT_EVENT and ad == 0 and len(person.get_parent_family_handle_list()) != 0:
@ -973,13 +1001,10 @@ class GedcomWriter:
if self.images:
photos = person.get_media_list ()
else:
photos = []
for photo in photos:
if self.private and photo.get_privacy():
continue
self.write_photo(photo,1)
for photo in photos:
if self.private and photo.get_privacy():
continue
self.write_photo(photo,1)
for family in person.get_parent_family_handle_list():
if self.flist.has_key(family[0]):
@ -1090,9 +1115,10 @@ class GedcomWriter:
def dump_event_stats(self,event):
dateobj = event.get_date_object()
self.print_date("2 DATE",dateobj)
place = None
if event.get_place_handle():
place_name = self.db.get_place_from_handle(event.get_place_handle()).get_title()
self.writeln("2 PLAC %s" % self.cnvtxt(place_name).replace('\r',' '))
place = self.db.get_place_from_handle(event.get_place_handle())
self.write_place(place,2)
if event.get_cause():
self.writeln("2 CAUS %s" % self.cnvtxt(event.get_cause()))
if event.get_note():
@ -1100,6 +1126,18 @@ class GedcomWriter:
for srcref in event.get_source_references():
self.write_source_ref(2,srcref)
if self.images:
photos = event.get_media_list()
for photo in photos:
if self.private and photo.get_privacy():
continue
self.write_photo(photo,2)
if place:
for photo in place.get_media_list():
if self.private and photo.get_privacy():
continue
self.write_photo(photo,2)
def write_ord(self,name,ord,index,statlist):
if ord == None:
return
@ -1113,8 +1151,7 @@ class GedcomWriter:
if ord.get_temple():
self.writeln('%d TEMP %s' % (index+1,ord.get_temple()))
if ord.get_place_handle():
place_name = self.db.get_place_from_handle(ord.get_place_handle()).get_title()
self.writeln("2 PLAC %s" % self.cnvtxt(place_name).replace('\r',' '))
self.write_place(self.db.get_place_from_handle(ord.get_place_handle()),2)
if ord.get_status() != 0:
self.writeln("2 STAT %s" % self.cnvtxt(statlist[ord.get_status()]))
if ord.get_note():
@ -1223,12 +1260,26 @@ class GedcomWriter:
if ref.get_note():
self.write_long_text("NOTE",level+1,self.cnvtxt(ref.get_note()))
mime2ged = {
"image/bmp" : "bmp",
"image/gif" : "gif",
"image/jpeg" : "jpeg",
"image/x-pcx" : "pcx",
"image/tiff" : "tiff",
"audio/x-wav" : "wav"
}
def write_photo(self,photo,level):
photo_obj_id = photo.get_reference_handle()
photo_obj = self.db.get_object_from_handle(photo_obj_id)
print photo_obj, photo_obj.get_mime_type()
if photo_obj and photo_obj.get_mime_type() == "image/jpeg":
if photo_obj:
mime = photo_obj.get_mime_type()
if self.mime2ged.has_key(mime):
form = self.mime2ged[mime]
else:
form = mime
path = photo_obj.get_path ()
imgdir = os.path.join(self.dirname,self.images_path)
if not os.path.isfile(path):
@ -1250,7 +1301,8 @@ class GedcomWriter:
return
self.writeln('%d OBJE' % level)
self.writeln('%d FORM jpeg' % (level+1) )
if form:
self.writeln('%d FORM %s' % (level+1, form) )
self.writeln('%d TITL %s' % (level+1, photo_obj.get_description()))
dirname = os.path.join (self.dirname, self.images_path)
basename = os.path.basename (path)
@ -1259,6 +1311,10 @@ class GedcomWriter:
if photo_obj.get_note():
self.write_long_text("NOTE",level+1,self.cnvtxt(photo_obj.get_note()))
def write_place(self,place,level):
place_name = place.get_title()
self.writeln("%d PLAC %s" % (level,self.cnvtxt(place_name).replace('\r',' ')))
def fid(self,id):
family = self.db.get_family_from_handle (id)
return family.get_gramps_id ()

View File

@ -411,6 +411,27 @@ def save_event(st):
return family_events.find_key(st)
return st
#-------------------------------------------------------------------------
#
# GEDCOM tags representing attributes that may take a parameter, value or
# description on the same line as the tag
#
#-------------------------------------------------------------------------
personalGedcomAttributeTakesParam = {
"CAST" : 1,
"DSCR" : 1,
"EDUC" : 1,
"IDNO" : 1,
"NATI" : 1,
"NCHI" : 1,
"NMR" : 1,
"OCCU" : 1,
"PROP" : 1,
"RELI" : 1,
"SSN" : 1,
"TITL" : 1
}
#-------------------------------------------------------------------------
#
#