XML parsing speed improvements and HTML web site generation

svn: r164
This commit is contained in:
Don Allingham 2001-06-19 20:48:35 +00:00
parent 29d1173095
commit 8592a66179
11 changed files with 537 additions and 342 deletions

View File

@ -1,3 +1,7 @@
Version 0.3.1
* Improved Web Site generation (changed from Individual Web Pages)
* Faster load times for XML database
Version 0.3.0
* Support for RTF (export to MSWord) and limited support for KWord
and LaTeX added.

View File

@ -51,7 +51,7 @@ class Date:
def __init__(self):
self.start = SingleDate()
self.stop = SingleDate()
self.stop = None
self.range = 0
self.text = ""
@ -59,6 +59,8 @@ class Date:
return self.start
def get_stop_date(self):
if self.stop == None:
self.stop = SingleDate()
return self.stop
def getYear(self):
@ -71,12 +73,18 @@ class Date:
return self.get_start_date().getDay()
def getStopYear(self):
if self.stop == None:
self.stop = SingleDate()
return self.get_stop_date().getYear()
def getStopMonth(self):
if self.stop == None:
self.stop = SingleDate()
return self.get_stop_date().getMonth()
def getStopDay(self):
if self.stop == None:
self.stop = SingleDate()
return self.get_stop_date().getDay()
#--------------------------------------------------------------------
@ -90,6 +98,8 @@ class Date:
if match:
matches = match.groups()
self.start.set(matches[1])
if self.stop == None:
self.stop = SingleDate()
self.stop.set(matches[3])
self.range = 1
else:
@ -169,6 +179,8 @@ class Date:
if match:
matches = match.groups()
self.start.set(matches[1])
if self.stop == None:
self.stop = SingleDate()
self.stop.set(matches[3])
self.range = 1
else:
@ -242,6 +254,9 @@ class SingleDate:
string.lower(mname[10][0:3]) : 10,
string.lower(mname[11][0:3]) : 11 }
em2num ={ "jan" : 0, "feb" : 1, "mar" : 2, "apr" : 3,
"may" : 4, "jun" : 5, "jul" : 6, "aug" : 7,
"sep" : 8, "oct" : 9, "nov" : 10,"dec" : 11 }
m2v = { _("abt") : about ,
_("about") : about,
@ -510,11 +525,11 @@ class SingleDate:
retval = str(self.year)
if self.mode == SingleDate.about:
retval = "%s %s" % (_("ABT"),retval)
retval = "%s %s" % (_("abt"),retval)
if self.mode == SingleDate.before:
retval = "%s %s" % (_("BEFORE"),retval)
retval = "%s %s" % (_("before"),retval)
elif self.mode == SingleDate.after:
retval = "%s %s" % (_("AFTER"),retval)
retval = "%s %s" % (_("after"),retval)
return retval

View File

@ -41,7 +41,13 @@ else:
except:
sax = 2
#-------------------------------------------------------------------------
#
# Unicode to latin conversion
#
#-------------------------------------------------------------------------
from latin_utf8 import utf8_to_latin
u2l = utf8_to_latin
#-------------------------------------------------------------------------
#
@ -103,7 +109,7 @@ class GrampsParser(handler.ContentHandler):
self.callback = callback
self.entries = 0
self.count = 0
self.increment = 50
self.increment = 100
self.event = None
self.name = None
self.tempDefault = None
@ -206,8 +212,7 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def start_father(self,attrs):
father = self.db.findPersonNoMap(attrs["ref"])
self.family.setFather(father)
self.family.Father = self.db.findPersonNoMap(attrs["ref"])
#---------------------------------------------------------------------
#
@ -215,8 +220,7 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def start_mother(self,attrs):
mother = self.db.findPersonNoMap(attrs["ref"])
self.family.setMother(mother)
self.family.Mother = self.db.findPersonNoMap(attrs["ref"])
#---------------------------------------------------------------------
#
@ -224,8 +228,7 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def start_child(self,attrs):
child = self.db.findPersonNoMap(attrs["ref"])
self.family.addChild(child)
self.family.Children.append(self.db.findPersonNoMap(attrs["ref"]))
#---------------------------------------------------------------------
#
@ -269,9 +272,9 @@ class GrampsParser(handler.ContentHandler):
family = self.db.findFamilyNoMap(attrs["ref"])
if attrs.has_key("type"):
type = attrs["type"]
self.person.addAltFamily(family,type)
self.person.AltFamilyList.append((family,type))
else:
self.person.setMainFamily(family)
self.person.MainFamily = family
#---------------------------------------------------------------------
#
@ -279,8 +282,7 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def start_parentin(self,attrs):
family = self.db.findFamilyNoMap(attrs["ref"])
self.person.addFamily(family)
self.person.FamilyList.append(self.db.findFamilyNoMap(attrs["ref"]))
#---------------------------------------------------------------------
#
@ -355,8 +357,7 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def start_created(self,attrs):
self.entries = string.atoi(attrs["people"]) + \
string.atoi(attrs["families"])
self.entries = int(attrs["people"]) + int(attrs["families"])
#---------------------------------------------------------------------
#
@ -365,7 +366,7 @@ class GrampsParser(handler.ContentHandler):
#---------------------------------------------------------------------
def stop_attribute(self,tag):
if self.in_old_attr:
self.attribute.setValue(tag)
self.attribute.setValue(u2l(tag))
self.in_old_attr = 0
self.attribute = None
@ -375,7 +376,7 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def stop_attr_type(self,tag):
self.attribute.setType(tag)
self.attribute.setType(u2l(tag))
#---------------------------------------------------------------------
#
@ -383,7 +384,7 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def stop_attr_value(self,tag):
self.attribute.setValue(tag)
self.attribute.setValue(u2l(tag))
#---------------------------------------------------------------------
#
@ -399,7 +400,7 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def stop_event(self,tag):
self.event.setName(self.event_type)
self.event.name = self.event_type
if self.event_type == "Birth":
self.person.setBirth(self.event)
@ -410,9 +411,9 @@ class GrampsParser(handler.ContentHandler):
elif self.event_type == "Divorce":
self.family.setDivorce(self.event)
elif self.person:
self.person.addEvent(self.event)
self.person.EventList.append(self.event)
else:
self.family.addEvent(self.event)
self.family.EventList.append(self.event)
self.event = None
#---------------------------------------------------------------------
@ -421,7 +422,7 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def stop_name(self,tag):
self.person.setPrimaryName(self.name)
self.person.PrimaryName = self.name
self.name = None
#---------------------------------------------------------------------
@ -430,7 +431,7 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def stop_place(self,tag):
self.event.setPlace(tag)
self.event.place = u2l(tag)
#---------------------------------------------------------------------
#
@ -450,7 +451,7 @@ class GrampsParser(handler.ContentHandler):
if self.address:
self.address.setDate(tag)
else:
self.event.getDateObj().quick_set(tag)
self.event.date.quick_set(tag)
#---------------------------------------------------------------------
#
@ -458,14 +459,14 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def stop_first(self,tag):
self.name.setFirstName(tag)
self.name.FirstName = u2l(tag)
#---------------------------------------------------------------------
#
#
#
#---------------------------------------------------------------------
def stop_family(self,tag):
def stop_families(self,tag):
self.family = None
#---------------------------------------------------------------------
@ -473,7 +474,7 @@ class GrampsParser(handler.ContentHandler):
#
#
#---------------------------------------------------------------------
def stop_person(self,tag):
def stop_people(self,tag):
self.person = None
#---------------------------------------------------------------------
@ -482,7 +483,7 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def stop_description(self,tag):
self.event.setDescription(tag)
self.event.setDescription(u2l(tag))
#---------------------------------------------------------------------
#
@ -490,10 +491,7 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def stop_gender(self,tag):
if tag == "M":
self.person.setGender(Person.male)
else:
self.person.setGender(Person.female)
self.person.gender = (tag == "M")
#---------------------------------------------------------------------
#
@ -501,7 +499,7 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def stop_stitle(self,tag):
self.source.setTitle(tag)
self.source.setTitle(u2l(tag))
#---------------------------------------------------------------------
#
@ -525,7 +523,7 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def stop_sauthor(self,tag):
self.source.setAuthor(tag)
self.source.setAuthor(u2l(tag))
#---------------------------------------------------------------------
#
@ -538,19 +536,19 @@ class GrampsParser(handler.ContentHandler):
self.source_ref.setDate(date)
def stop_street(self,tag):
self.address.setStreet(tag)
self.address.setStreet(u2l(tag))
def stop_city(self,tag):
self.address.setCity(tag)
self.address.setCity(u2l(tag))
def stop_state(self,tag):
self.address.setState(tag)
self.address.setState(u2l(tag))
def stop_country(self,tag):
self.address.setCountry(tag)
self.address.setCountry(u2l(tag))
def stop_postal(self,tag):
self.address.setPostal(tag)
self.address.setPostal(u2l(tag))
#---------------------------------------------------------------------
#
@ -558,7 +556,7 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def stop_spage(self,tag):
self.source_ref.setPage(tag)
self.source_ref.setPage(u2l(tag))
#---------------------------------------------------------------------
#
@ -566,7 +564,7 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def stop_spubinfo(self,tag):
self.source.setPubInfo(tag)
self.source.setPubInfo(u2l(tag))
#---------------------------------------------------------------------
#
@ -574,7 +572,7 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def stop_scallno(self,tag):
self.source.setCallNumber(tag)
self.source.setCallNumber(u2l(tag))
#---------------------------------------------------------------------
#
@ -586,7 +584,7 @@ class GrampsParser(handler.ContentHandler):
self.use_p = 0
note = fix_spaces(self.stext_list)
else:
note = tag
note = u2l(tag)
self.source_ref.setText(note)
#---------------------------------------------------------------------
@ -599,7 +597,7 @@ class GrampsParser(handler.ContentHandler):
self.use_p = 0
note = fix_spaces(self.scomments_list)
else:
note = tag
note = u2l(tag)
self.source_ref.setComments(note)
#---------------------------------------------------------------------
@ -608,7 +606,7 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def stop_last(self,tag):
self.name.setSurname(tag)
self.name.Surname = u2l(tag)
#---------------------------------------------------------------------
#
@ -616,7 +614,7 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def stop_suffix(self,tag):
self.name.setSuffix(tag)
self.name.Suffix = u2l(tag)
#---------------------------------------------------------------------
#
@ -624,7 +622,7 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def stop_title(self,tag):
self.name.setTitle(tag)
self.name.Title = u2l(tag)
#---------------------------------------------------------------------
#
@ -632,7 +630,7 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def stop_nick(self,tag):
self.person.setNickName(tag)
self.person.setNickName(u2l(tag))
#---------------------------------------------------------------------
#
@ -645,7 +643,7 @@ class GrampsParser(handler.ContentHandler):
self.use_p = 0
note = fix_spaces(self.note_list)
else:
note = tag
note = u2l(tag)
if self.address:
self.address.setNote(note)
elif self.attribute:
@ -677,7 +675,7 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def stop_resname(self,tag):
self.resname = tag
self.resname = u2l(tag)
#---------------------------------------------------------------------
#
@ -685,7 +683,7 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def stop_resaddr(self,tag):
self.resaddr = tag
self.resaddr = u2l(tag)
#---------------------------------------------------------------------
#
@ -693,7 +691,7 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def stop_rescity(self,tag):
self.rescity = tag
self.rescity = u2l(tag)
#---------------------------------------------------------------------
#
@ -701,7 +699,7 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def stop_resstate(self,tag):
self.resstate = tag
self.resstate = u2l(tag)
#---------------------------------------------------------------------
#
@ -709,7 +707,7 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def stop_rescountry(self,tag):
self.rescon = tag
self.rescon = u2l(tag)
#---------------------------------------------------------------------
#
@ -717,7 +715,7 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def stop_respostal(self,tag):
self.respos = tag
self.respos = u2l(tag)
#---------------------------------------------------------------------
#
@ -725,7 +723,7 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def stop_resphone(self,tag):
self.resphone = tag
self.resphone = u2l(tag)
#---------------------------------------------------------------------
#
@ -733,7 +731,7 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def stop_resemail(self,tag):
self.resemail = tag
self.resemail = u2l(tag)
#---------------------------------------------------------------------
#
@ -743,11 +741,11 @@ class GrampsParser(handler.ContentHandler):
def stop_ptag(self,tag):
self.use_p = 1
if self.in_note:
self.note_list.append(tag)
self.note_list.append(u2l(tag))
elif self.in_stext:
self.stext_list.append(tag)
self.stext_list.append(u2l(tag))
elif self.in_scomments:
self.scomments_list.append(tag)
self.scomments_list.append(u2l(tag))
#---------------------------------------------------------------------
#
@ -775,7 +773,7 @@ class GrampsParser(handler.ContentHandler):
"date" : (None, stop_date),
"description": (None, stop_description),
"event" : (start_event, stop_event),
"families" : (None, None),
"families" : (None, stop_families),
"family" : (start_family, None),
"father" : (start_father, None),
"first" : (None, stop_first),
@ -788,8 +786,8 @@ class GrampsParser(handler.ContentHandler):
"note" : (start_note, stop_note),
"p" : (None, stop_ptag),
"parentin" : (start_parentin,None),
"people" : (start_people, None),
"person" : (start_person, stop_person),
"people" : (start_people, stop_people),
"person" : (start_person, None),
"img" : (start_photo, None),
"place" : (None, stop_place),
"postal" : (None, stop_postal),
@ -849,7 +847,7 @@ class GrampsParser(handler.ContentHandler):
def endElement(self,tag):
if self.func:
self.func(self,utf8_to_latin(self.data))
self.func(self,self.data)
self.func_index = self.func_index - 1
self.func,self.data = self.func_list[self.func_index]

View File

@ -41,6 +41,10 @@ try:
except:
no_pil = 1
t_one_line_re = re.compile(r"^(.*)<TITLE>.*</TITLE>(.*)$")
t_start_re = re.compile(r"^(.*)<TITLE>.*$")
t_stop_re = re.compile(r"^(.*)</TITLE>")
#------------------------------------------------------------------------
#
# Default template
@ -142,6 +146,19 @@ class HtmlDoc(TextDoc):
self.f = open(self.filename,"w")
for line in self.top:
match = t_one_line_re.match(line)
if match:
m = match.groups()
self.f.write('%s<TITLE>%s</TITLE>%s\n' % (m[0],self.title,m[1]))
continue
match = t_start_re.match(line)
if match:
m =match.groups()
self.f.write('%s<TITLE>%s\n' % (m[0],self.title))
continue
if t_stop_re.match(line):
self.f.write('</TITLE>\n')
continue
self.f.write(line)
self.f.write('<style type="text/css">\n<!--\n')

View File

@ -175,6 +175,7 @@ if __name__ == "__main__":
t1 = time.time()
profile.run('loadData(db,file,lcb)')
# loadData(db,file,lcb)
t2 = time.time()
print t2 - t1

View File

@ -35,7 +35,7 @@ class Note:
def get(self):
return self.text
#-------------------------------------------------------------------------
#
# Photo class. Contains information about a photo stored in the database
@ -192,8 +192,8 @@ class Name:
self.Surname = ""
self.Suffix = ""
self.Title = ""
self.source_ref = SourceRef()
self.note = Note()
self.source_ref = None
self.note = None
def setName(self,first,last,suffix):
self.FirstName = first
@ -236,22 +236,31 @@ class Name:
else:
return "%s %s, %s" % (self.FirstName, self.Surname, self.Suffix)
def setNote(self,text):
self.note.set(text)
def setNote(self,note) :
if self.note == None:
self.note = Note()
self.note.set(note)
def getNote(self):
return self.note.get()
def getNote(self) :
if self.note == None:
return ""
else:
return self.note.get()
def setNoteObj(self,obj):
self.note = obj
def setNoteObj(self,note) :
self.note = note
def getNoteObj(self,obj):
def getNoteObj(self):
if self.note == None:
self.note = Note()
return self.note
def setSourceRef(self,id) :
self.source_ref = id
def getSourceRef(self) :
if not self.source_ref:
self.source_ref = SourceRef()
return self.source_ref
#-------------------------------------------------------------------------
@ -289,7 +298,7 @@ class Person:
def __init__(self):
self.id = -1
self.PrimaryName = Name()
self.PrimaryName = None
self.EventList = []
self.FamilyList = []
self.AltFamilyList = []
@ -297,19 +306,21 @@ class Person:
self.photoList = []
self.nickname = ""
self.alternateNames = []
self.gender = Person.female
self.death = Event()
self.birth = Event()
self.gender = 0
self.death = None
self.birth = None
self.addressList = []
self.attributeList = []
self.urls = []
self.note = Note()
self.note = None
self.paf_uid = ""
def setPrimaryName(self,name) :
self.PrimaryName = name
def getPrimaryName(self) :
if not self.PrimaryName:
self.PrimaryName = Name()
return self.PrimaryName
def setPafUid(self,val) :
@ -355,9 +366,15 @@ class Person:
self.death = event
def getBirth(self) :
if self.birth == None:
self.birth = Event()
self.birth.name = "Birth"
return self.birth
def getDeath(self) :
if self.death == None:
self.death = Event()
self.death.name = "Death"
return self.death
def addPhoto(self,photo):
@ -437,18 +454,24 @@ class Person:
def getMainFamily(self) :
return self.MainFamily
def setNote(self,text):
self.note.set(text)
def setNote(self,note) :
if self.note == None:
self.note = Note()
self.note.set(note)
def getNote(self):
return self.note.get()
def getNote(self) :
if self.note == None:
return ""
else:
return self.note.get()
def setNoteObj(self,obj):
self.note = obj
def setNoteObj(self,note) :
self.note = note
def getNoteObj(self,obj):
def getNoteObj(self):
if self.note == None:
self.note = Note()
return self.note
#-------------------------------------------------------------------------
#
@ -462,8 +485,8 @@ class Event:
self.date = Date()
self.description = ""
self.name = ""
self.source_ref = SourceRef()
self.note = Note()
self.source_ref = None
self.note = None
def set(self,name,date,place,description):
self.name = name
@ -493,6 +516,8 @@ class Event:
self.source_ref = id
def getSourceRef(self) :
if not self.source_ref:
self.source_ref = SourceRef()
return self.source_ref
def setPlace(self,place) :
@ -502,15 +527,22 @@ class Event:
return self.place
def setNote(self,note) :
if self.note == None:
self.note = Note()
self.note.set(note)
def getNote(self) :
return self.note.get()
if self.note == None:
return ""
else:
return self.note.get()
def setNoteObj(self,note) :
self.note = note
def getNoteObj(self) :
def getNoteObj(self):
if self.note == None:
self.note = Note()
return self.note
def setDescription(self,description) :
@ -623,12 +655,18 @@ class Family:
self.Marriage = event
def getMarriage(self):
if self.Marriage == None:
self.Marriage = Event()
self.Marriage.name = "Marriage"
return self.Marriage
def setDivorce(self,event):
self.Divorce = event
def getDivorce(self):
if self.Divorce == None:
self.Divorce = Event()
self.Divorce.name = "Marriage"
return self.Divorce
def addEvent(self,event) :

View File

@ -195,6 +195,11 @@ class TableStyle:
def get_columns(self):
return self.columns
def set_column_widths(self, list):
self.columns = len(list)
for i in range(self.columns):
self.colwid[i] = list[i]
def set_column_width(self,index,width):
self.colwid[index] = width
@ -577,6 +582,7 @@ class TextDoc:
self.bmargin = 2.54
self.lmargin = 2.54
self.rmargin = 2.54
self.title = ""
self.font = FontStyle()
self.style_list = styles.get_styles()
@ -597,6 +603,9 @@ class TextDoc:
def creator(self,name):
self.name = name
def set_title(self,name):
self.title = name
def add_table_style(self,name,style):
self.table_styles[name] = TableStyle(style)

View File

@ -2134,7 +2134,8 @@ def on_statusbar_unmap(obj):
#
#-------------------------------------------------------------------------
def export_callback(obj,plugin_function):
plugin_function(database,active_person)
if active_person:
plugin_function(database,active_person)
#-------------------------------------------------------------------------
#

View File

@ -429,6 +429,8 @@ def dump_person(person,prefix,templateTop,templateBottom,targetDir):
if not alive:
print_event(html,_("Birth"),person.getBirth())
print_event(html,_("Death"),person.getDeath())
for event in person.getEventList():
print_event(html,event.getName(),event)
family = person.getMainFamily()
if family != None:

View File

@ -35,6 +35,9 @@ from libglade import *
import const
from latin_ansel import latin_to_ansel
from latin_utf8 import latin_to_utf8
cnvtxt = latin_to_ansel
topDialog = None
db = None
@ -235,89 +238,21 @@ def sortById(first,second):
#
#
#-------------------------------------------------------------------------
def writeNote(g,id,note):
g.write("1 NOTE @NI%s@\n" % id)
g.write("0 @NI%s@ NOTE\n" % id)
first = 0
realfirst = 0
words = []
def write_long_text(g,tag,level,note):
prefix = "%d %s" % (level,tag)
textlines = string.split(note,'\n')
lineLen = 0
text = ""
for line in textlines:
if line == "":
continue
line = latin_to_ansel(line)
for word in string.split(line):
text = text + " " + word
if len(text) > 72 :
if first == 0 or realfirst == 0:
g.write("1 CONC%s \n" % text)
realfirst = 1
else:
g.write("1 CONT%s\n" % text)
first = 0
text = ""
if len(text) > 0:
if first == 0 or realfirst == 0:
g.write("1 CONC%s \n" % text)
realfirst = 1
else:
g.write("1 CONT%s\n" % text)
first = 1
text = ""
g.write("1 CONT\n")
first = 1
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def write_comment(g,note):
g.write("3 NOTE ")
first = 0
realfirst = 0
words = []
textlines = string.split(note,'\n')
lineLen = 0
text = ""
for line in textlines:
if line == "":
continue
line = latin_to_ansel(line)
for word in string.split(line):
text = text + " " + word
if len(text) > 72 :
if realfirst == 0:
g.write("%s \n" % text)
realfirst = 1
elif first == 0:
g.write("1 CONC%s \n" % text)
realfirst = 1
else:
g.write("1 CONT%s\n" % text)
first = 0
text = ""
if len(text) > 0:
if realfirst == 0:
g.write("%s \n" % text)
realfirst = 1
elif first == 0:
g.write("1 CONC%s \n" % text)
realfirst = 1
else:
g.write("1 CONT%s\n" % text)
first = 1
text = ""
g.write("1 CONT\n")
first = 1
while len(line) > 0:
if len(line) > 70:
g.write("%s %s\n" % (prefix,line[0:70]))
line = line[70:]
else:
g.write("%s %s\n" % (prefix,line))
line = ""
if len(line) > 0:
prefix = "%d CONC" % (level + 1)
else:
prefix = "%d CONT" % (level + 1)
#-------------------------------------------------------------------------
#
@ -326,24 +261,13 @@ def write_comment(g,note):
#-------------------------------------------------------------------------
def dump_event_stats(g,event):
if event.getSaveDate() != "":
g.write("2 DATE %s\n" % latin_to_ansel(event.getSaveDate()))
g.write("2 DATE %s\n" % cnvtxt(event.getSaveDate()))
if event.getPlace() != "":
g.write("2 PLAC %s\n" % latin_to_ansel(event.getPlace()))
source = event.getSourceRef()
if source:
base = source.getBase()
if base:
g.write("2 SOUR @" + str(base.getId()) + "@\n")
text = latin_to_ansel(string.strip(source.getPage()))
if text != "":
g.write("3 PAGE " + text + "\n")
text = latin_to_ansel(string.strip(source.getText()))
if text != "":
g.write("3 DATA\n")
g.write("4 TEXT " + text + "\n")
comments = latin_to_ansel(string.strip(source.getComments()))
if comments != "":
write_comment(g,comments)
g.write("2 PLAC %s\n" % cnvtxt(event.getPlace()))
if event.getNote() != "":
write_long_text(g,"NOTE",2,event.getNote())
if event.getSourceRef() != None:
write_source_ref(g,2,event.getSourceRef())
#-------------------------------------------------------------------------
#
@ -371,6 +295,160 @@ def probably_alive(person):
return 0
return 1
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def write_person_name(g,name,nick):
firstName = cnvtxt(name.getFirstName())
surName = cnvtxt(name.getSurname())
suffix = cnvtxt(name.getSuffix())
title = cnvtxt(name.getTitle())
if suffix == "":
g.write("1 NAME %s /%s/\n" % (firstName,surName))
else:
g.write("1 NAME %s /%s/, %s\n" % (firstName,surName, suffix))
if name.getFirstName() != "":
g.write("2 GIVN %s\n" % firstName)
if name.getSurname() != "":
g.write("2 SURN %s\n" % surName)
if name.getSuffix() != "":
g.write("2 NSFX %s\n" % suffix)
if name.getTitle() != "":
g.write("2 TITL %s\n" % title)
if nick != "":
g.write('2 NICK %s\n' % nick)
if name.getNote() != "":
write_long_text(g,"NOTE",2,name.getNote())
if name.getSourceRef() != None:
write_source_ref(g,2,name.getSourceRef())
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def write_source_ref(g,level,ref):
if ref.getBase() == None:
return
g.write("%d SOUR @S%s@\n" % (level,str(ref.getBase().getId())))
if ref.getPage() != "":
g.write("%d PAGE %s\n" % (level+1,ref.getPage()))
if ref.getText() != "" or ref.getDate().getDate() != "":
g.write('%d DATA\n' % level+1)
if ref.getText():
write_long_text(g,"TEXT",level+1,ref.get_text())
if ref.getDate().getDate():
g.write("%d DATE %s\n",ref.getDate().getSaveDate())
if ref.getComments() != "":
write_long_text(g,"NOTE",level+1,ref.getComments())
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def write_person(g,person):
g.write("0 @I%s@ INDI\n" % person.getId())
write_person_name(g,person.getPrimaryName(),person.getNickName())
for name in person.getAlternateNames():
write_person_name(g,name,"")
if person.getGender() == Person.male:
g.write("1 SEX M\n")
else:
g.write("1 SEX F\n")
if not probably_alive(person):
birth = person.getBirth()
if birth.getSaveDate() != "" or birth.getPlace() != "":
g.write("1 BIRT\n")
dump_event_stats(g,birth)
death = person.getDeath()
if death.getSaveDate() != "" or death.getPlace() != "":
g.write("1 DEAT\n")
dump_event_stats(g,death)
uid = person.getPafUid()
if uid != "":
g.write("1 _UID %s\n" % uid)
for event in person.getEventList():
name = event.getName()
if const.personalConstantEvents.has_key(name):
val = const.personalConstantEvents[name]
else:
val = ""
if val != "" :
g.write("1 %s %s\n" % (cnvtxt(val),cnvtxt(event.getDescription())))
else:
g.write("1 EVEN %s\n" % cnvtxt(event.getDescription()))
g.write("2 TYPE %s\n" % cnvtxt(event.getName()))
dump_event_stats(g,event)
for attr in person.getAttributeList():
name = attr.getType()
if const.personalConstantAttributes.has_key(name):
val = const.personalConstantEvents[name]
else:
val = ""
if val != "" :
g.write("1 %s\n" % val)
else:
g.write("1 EVEN\n")
g.write("2 TYPE %s\n" % cnvtxt(name))
g.write("2 PLAC %s\n" % cnvtxt(attr.getValue()))
if attr.getNote() != "":
write_long_text(g,"NOTE",2,attr.getNote())
if attr.getSourceRef() != None:
write_source_ref(g,2,attr.getSourceRef())
for addr in person.getAddressList():
write_long_text(g,"RESI",1,addr.getStreet())
if addr.getCity() != "":
g.write("2 CITY %s\n" % addr.getCity())
if addr.getState() != "":
g.write("2 STAE %s\n" % addr.getState())
if addr.getPostalCode() != "":
g.write("2 POST %s\n" % addr.getPostalCode())
if addr.getCountry() != "":
g.write("2 CTRY %s\n" % addr.getCountry())
if addr.getNote() != "":
write_long_text(g,"NOTE",2,addr.getNote())
if addr.getSourceRef() != None:
write_source_ref(g,2,addr.getSourceRef())
family = person.getMainFamily()
if family != None and family in family_list:
g.write("1 FAMC @F%s@\n" % str(family.getId()))
g.write("2 PEDI birth\n")
for family in person.getAltFamilyList():
g.write("1 FAMC @F%s@\n" % str(family[0].getId()))
if string.lower(family[1]) == "adopted":
g.write("2 PEDI adopted\n")
for family in person.getFamilyList():
if family != None and family in family_list:
g.write("1 FAMS @F%s@\n" % family.getId())
for url in person.getUrlList():
g.write('1 OBJE\n')
g.write('2 FORM URL\n')
if url.get_description() != "":
g.write('2 TITL %s\n' % url.get_description())
if url.get_path() != "":
g.write('2 FILE %s\n' % url.get_path())
if person.getNote() != "":
write_long_text(g,"NOTE",1,person.getNote())
#-------------------------------------------------------------------------
#
#
@ -388,7 +466,10 @@ def exportData(database, filename):
g.write("2 NAME Gramps\n")
g.write("1 DEST GRAMPS\n")
g.write("1 DATE %s %s %s\n" % (date[2],string.upper(date[1]),date[4]))
g.write("1 CHAR ANSEL\n");
if cnvtxt == latin_to_ansel:
g.write("1 CHAR ANSEL\n");
else:
g.write("1 CHAR UNICODE\n");
g.write("1 SUBM @SUBM@\n")
g.write("1 FILE %s\n" % filename)
g.write("1 GEDC\n")
@ -396,98 +477,24 @@ def exportData(database, filename):
g.write("0 @SUBM@ SUBM\n")
owner = database.getResearcher()
if owner.getName() != "":
g.write("1 NAME " + latin_to_ansel(owner.getName()) +"\n")
g.write("1 NAME " + cnvtxt(owner.getName()) +"\n")
if owner.getAddress() != "":
g.write("1 ADDR " + latin_to_ansel(owner.getAddress()) + "\n")
g.write("1 ADDR " + cnvtxt(owner.getAddress()) + "\n")
if owner.getCity() != "":
g.write("2 CITY " + latin_to_ansel(owner.getCity()) + "\n")
g.write("2 CITY " + cnvtxt(owner.getCity()) + "\n")
if owner.getState() != "":
g.write("2 STAE " + latin_to_ansel(owner.getState()) + "\n")
g.write("2 STAE " + cnvtxt(owner.getState()) + "\n")
if owner.getPostalCode() != "":
g.write("2 POST " + latin_to_ansel(owner.getPostalCode()) + "\n")
g.write("2 POST " + cnvtxt(owner.getPostalCode()) + "\n")
if owner.getCountry() != "":
g.write("2 CTRY " + latin_to_ansel(owner.getCountry()) + "\n")
g.write("2 CTRY " + cnvtxt(owner.getCountry()) + "\n")
if owner.getPhone() != "":
g.write("1 PHON " + latin_to_ansel(owner.getPhone()) + "\n")
g.write("1 PHON " + cnvtxt(owner.getPhone()) + "\n")
people_list.sort(sortById)
for person in people_list:
g.write("0 @I%s@ INDI\n" % person.getId())
name = person.getPrimaryName()
firstName = latin_to_ansel(name.getFirstName())
surName = latin_to_ansel(name.getSurname())
suffix = latin_to_ansel(name.getSuffix())
if suffix == "":
g.write("1 NAME %s /%s/\n" % (firstName,surName))
else:
g.write("1 NAME %s /%s/, %s\n" % (firstName,surName, suffix))
if name.getFirstName() != "":
g.write("2 GIVN %s\n" % firstName)
if name.getSurname() != "":
g.write("2 SURN %s\n" % surName)
if name.getSuffix() != "":
g.write("2 NSFX %s\n" % suffix)
if person.getGender() == Person.male:
g.write("1 SEX M\n")
else:
g.write("1 SEX F\n")
if not probably_alive(person):
birth = person.getBirth()
if birth.getSaveDate() != "" or birth.getPlace() != "":
g.write("1 BIRT\n")
dump_event_stats(g,birth)
death = person.getDeath()
if death.getSaveDate() != "" or death.getPlace() != "":
g.write("1 DEAT\n")
dump_event_stats(g,death)
uid = person.getPafUid()
if uid != "":
g.write("1 _UID " + uid + "\n")
write_person(g,person)
for event in person.getEventList():
name = event.getName()
if const.personalConstantEvents.has_key(name):
val = const.personalConstantEvents[name]
else:
val = ""
if val != "" :
g.write("1 " + const.personalConstantEvents[name] + \
" " + event.getDescription() + "\n")
else:
g.write("1 EVEN " + latin_to_ansel(event.getDescription()) + "\n")
g.write("2 TYPE " + latin_to_ansel(event.getName()) + "\n")
dump_event_stats(g,event)
for attr in person.getAttributeList():
name = attr.getType()
if const.personalConstantAttributes.has_key(name):
val = const.personalConstantEvents[name]
else:
val = ""
if val != "" :
g.write("1 " + val + "\n")
else:
g.write("1 EVEN " + "\n")
g.write("2 TYPE " + latin_to_ansel(name) + "\n")
g.write("2 PLAC " + latin_to_ansel(attr.getValue()) + "\n")
family = person.getMainFamily()
if family != None and family in family_list:
g.write("1 FAMC @F%s@\n" % family.getId())
for family in person.getFamilyList():
if family != None and family in family_list:
g.write("1 FAMS @F%s@\n" % family.getId())
if person.getNote() != "":
writeNote(g,person.getId(),person.getNote())
for family in family_list:
g.write("0 @F%s@ FAM\n" % family.getId())
person = family.getFather()
@ -512,17 +519,17 @@ def exportData(database, filename):
dump_event_stats(g,event)
for event in family.getEventList():
text = event.getName()
name = event.getName()
if const.familyConstantEvents.has_key(name):
val = const.personalConstantEvents[name]
val = const.familyConstantEvents[name]
else:
val = ""
if val != "": # and val[0] != "_":
g.write("1 %s\n" % const.familyConstantEvents[text])
if val != "":
g.write("1 %s\n" % const.familyConstantEvents[name])
else:
g.write("1 EVEN\n")
g.write("2 TYPE %s\n" % latin_to_ansel(event.getName()))
g.write("2 TYPE %s\n" % cnvtxt(name))
dump_event_stats(g,event)
@ -530,22 +537,74 @@ def exportData(database, filename):
g.write("1 CHIL @I%s@\n" % person.getId())
for source in source_list:
g.write("0 @" + str(source.getId()) + "@ SOUR\n")
g.write("0 @S%s@ SOUR\n" % str(source.getId()))
if source.getTitle() != "":
g.write("1 TITL " + latin_to_ansel(source.getTitle()) + "\n")
g.write("1 TITL %s\n" % cnvtxt(source.getTitle()))
if source.getAuthor() != "":
g.write("1 AUTH " + latin_to_ansel(source.getAuthor()) + "\n")
g.write("1 AUTH %s\n" % cnvtxt(source.getAuthor()))
if source.getPubInfo() != "":
g.write("1 PUBL " + latin_to_ansel(source.getPubInfo()) + "\n")
g.write("1 PUBL %s\n" % cnvtxt(source.getPubInfo()))
if source.getTitle() != "":
g.write("1 ABBR " + latin_to_ansel(source.getTitle()) + "\n")
g.write("1 ABBR %s\n" % cnvtxt(source.getTitle()))
if source.getCallNumber() != "":
g.write("1 CALN " + latin_to_ansel(source.getCallNumber()) + "\n")
g.write("1 CALN %s\n" % cnvtxt(source.getCallNumber()))
if source.getNote() != "":
write_long_text(g,"NOTE",1,source.getNote())
g.write("0 TRLR\n")
g.close()
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def gedcom_date(date):
if date.range == 1:
s1 = ged_subdate(date.get_start_date())
s2 = ged_subdate(date.get_stop_date())
return "BET %s AND %s" % (s1,s2)
elif date.range == -1:
return "(%s)" % date.text
else:
return ged_subdate(self.start)
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def ged_subdate(date):
if date.month == -1 and date.day == -1 and date.year == -1 :
return ""
elif date.day == -1:
if date.month == -1:
retval = str(date.year)
elif date.year == -1:
retval = "(%s)" % SingleDate.emname[date.month]
else:
retval = "%s %d" % (SingleDate.emname[date.month],date.year)
elif date.month == -1:
retval = str(date.year)
else:
month = SingleDate.emname[date.month]
if date.year == -1:
retval = "(%d %s)" % (date.day,month)
else:
retval = "%d %s %d" % (date.day,month,date.year)
if date.mode == SingleDate.about:
retval = "ABT %s" % retval
if date.mode == SingleDate.before:
retval = "BEF %s" % retval
elif date.mode == SingleDate.after:
retval = "AFT %s" % retval
return retval
#-------------------------------------------------------------------------
#
#
@ -555,11 +614,17 @@ def on_ok_clicked(obj):
global db
global topDialog
global restrict
global cnvtxt
restrict = topDialog.get_widget("restrict").get_active()
filter_obj = topDialog.get_widget("filter").get_menu().get_active()
filter = filter_obj.get_data("filter")
if topDialog.get_widget("ansel").get_active():
cnvtxt = latin_to_ansel
else:
cnvtxt = latin_to_utf8
name = topDialog.get_widget("filename").get_text()
filter()

View File

@ -121,62 +121,6 @@
</child>
</widget>
<widget>
<class>GtkHBox</class>
<name>hbox1</name>
<homogeneous>False</homogeneous>
<spacing>0</spacing>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
<widget>
<class>GtkLabel</class>
<name>label1</name>
<label>Filter</label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>5</xpad>
<ypad>0</ypad>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
</widget>
<widget>
<class>GtkOptionMenu</class>
<name>filter</name>
<can_focus>True</can_focus>
<items></items>
<initial_choice>0</initial_choice>
<child>
<padding>5</padding>
<expand>False</expand>
<fill>False</fill>
</child>
</widget>
</widget>
<widget>
<class>GtkCheckButton</class>
<name>restrict</name>
<can_focus>True</can_focus>
<label>Restrict data on living people</label>
<active>True</active>
<draw_indicator>True</draw_indicator>
<child>
<padding>5</padding>
<expand>False</expand>
<fill>False</fill>
</child>
</widget>
<widget>
<class>GnomeFileEntry</class>
<name>fileentry1</name>
@ -203,6 +147,107 @@
<text></text>
</widget>
</widget>
<widget>
<class>GtkFrame</class>
<name>frame2</name>
<border_width>5</border_width>
<label>Filter</label>
<label_xalign>0</label_xalign>
<shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type>
<child>
<padding>0</padding>
<expand>True</expand>
<fill>True</fill>
</child>
<widget>
<class>GtkOptionMenu</class>
<name>filter</name>
<border_width>5</border_width>
<can_focus>True</can_focus>
<items>
</items>
<initial_choice>0</initial_choice>
</widget>
</widget>
<widget>
<class>GtkFrame</class>
<name>frame3</name>
<border_width>5</border_width>
<label>Encoding</label>
<label_xalign>0</label_xalign>
<shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type>
<child>
<padding>0</padding>
<expand>True</expand>
<fill>True</fill>
</child>
<widget>
<class>GtkVBox</class>
<name>vbox2</name>
<homogeneous>False</homogeneous>
<spacing>0</spacing>
<widget>
<class>GtkRadioButton</class>
<name>ansel</name>
<border_width>2</border_width>
<can_focus>True</can_focus>
<label>ANSEL</label>
<active>False</active>
<draw_indicator>True</draw_indicator>
<group>enc</group>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
</widget>
<widget>
<class>GtkRadioButton</class>
<name>radiobutton2</name>
<border_width>2</border_width>
<can_focus>True</can_focus>
<label>UNICODE</label>
<active>False</active>
<draw_indicator>True</draw_indicator>
<group>enc</group>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
</widget>
</widget>
</widget>
<widget>
<class>GtkFrame</class>
<name>frame1</name>
<border_width>5</border_width>
<label>Options</label>
<label_xalign>0</label_xalign>
<shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type>
<child>
<padding>0</padding>
<expand>True</expand>
<fill>True</fill>
</child>
<widget>
<class>GtkCheckButton</class>
<name>restrict</name>
<border_width>5</border_width>
<can_focus>True</can_focus>
<label>Restrict data on living people</label>
<active>True</active>
<draw_indicator>True</draw_indicator>
</widget>
</widget>
</widget>
</widget>
</widget>