Speed improvements for GEDCOM export

svn: r1056
This commit is contained in:
Don Allingham 2002-06-26 03:21:20 +00:00
parent c7fcad14b6
commit a47feef81e
8 changed files with 148 additions and 58 deletions

View File

@ -21,6 +21,10 @@
The AddSpouse module provides the AddSpouse class that allows the user to The AddSpouse module provides the AddSpouse class that allows the user to
add a new spouse to the active person. add a new spouse to the active person.
""" """
__author__ = "Donald N. Allingham"
__version__ = "$Revision$"
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# internationalization # internationalization

View File

@ -22,6 +22,9 @@ The AttrEdit module provides the AddressEditor class. This provides a
mechanism for the user to edit address information. mechanism for the user to edit address information.
""" """
__author__ = "Donald N. Allingham"
__version__ = "$Revision$"
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# GTK/Gnome modules # GTK/Gnome modules
@ -36,8 +39,8 @@ import libglade
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import const import const
import Utils import Utils
from RelLib import *
import Sources import Sources
from RelLib import Attribute
from intl import gettext from intl import gettext
_ = gettext _ = gettext
@ -47,7 +50,7 @@ _ = gettext
# AttributeEditor class # AttributeEditor class
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class AttributeEditor(Sources.SourceTab): class AttributeEditor:
""" """
Displays a dialog that allows the user to edit an attribute. Displays a dialog that allows the user to edit an attribute.
""" """
@ -60,6 +63,7 @@ class AttributeEditor(Sources.SourceTab):
title - The title of the dialog box title - The title of the dialog box
list - list of options for the pop down menu list - list of options for the pop down menu
""" """
self.parent = parent self.parent = parent
self.attrib = attrib self.attrib = attrib
self.top = libglade.GladeXML(const.dialogFile, "attr_edit") self.top = libglade.GladeXML(const.dialogFile, "attr_edit")

View File

@ -75,7 +75,6 @@ class EditPerson:
def __init__(self,person,db,callback=None): def __init__(self,person,db,callback=None):
"""Creates an edit window. Associates a person with the window.""" """Creates an edit window. Associates a person with the window."""
self.person = person self.person = person
print 1/0
self.original_id = person.getId() self.original_id = person.getId()
self.db = db self.db = db
self.callback = callback self.callback = callback

View File

@ -28,6 +28,9 @@ class GrampsXML(GrampsDB):
def get_base(self): def get_base(self):
return const.xmlFile return const.xmlFile
def new(self):
GrampsDB.new(self)
def save(self,name,callback): def save(self,name,callback):
WriteXML.exportData(self,name,callback) WriteXML.exportData(self,name,callback)

View File

@ -1935,6 +1935,9 @@ class GrampsDB(Persistent):
self.sourceMap = {} self.sourceMap = {}
self.placeMap = {} self.placeMap = {}
self.objectMap = {} self.objectMap = {}
self.personTable = {}
self.placeTable = {}
self.sourceTable = {}
self.smapIndex = 0 self.smapIndex = 0
self.pmapIndex = 0 self.pmapIndex = 0
self.fmapIndex = 0 self.fmapIndex = 0

View File

@ -130,3 +130,60 @@ def latin_to_ansel(s):
buff.close() buff.close()
return ans return ans
if __name__ == "__main__":
print 'static unsigned char s0[] = {'
for i in range(256):
if i == 255:
suf = '};\n\n'
else:
suf = ','
if i%16 == 0 and i != 0:
print '\n',
try:
print "%3d%s" % (_s0[i],suf),
except:
print "%3d%s" % (i,suf),
print 'static unsigned char t0[] = {'
for i in range(256):
if i == 255:
suf = '};\n\n'
else:
suf = ','
if i%16 == 0 and i != 0:
print '\n',
try:
print "%3d%s" % (ord(_t0[i]),suf),
except KeyError:
print '0%s' % suf,
print 'static unsigned char* t1[] = {'
for i in range(256):
if i == 255:
suf = '};\n\n'
else:
suf = ','
if i%8== 0 and i != 0:
print '\n',
try:
t = _t1[i]
print '"\\%03o\\%03o"%s' % (ord(t[0]),ord(t[1]),suf),
except KeyError:
print '"\\%03o"%s' % (i,suf),
for key in _s1.keys():
print 'static unsigned char s_%x[] = {' % key
for i in range(256):
if i == 255:
suf = '};\n\n'
else:
suf = ','
if i%16 == 0 and i != 0:
print '\n',
try:
print "%3d%s" % (_s1[key][i],suf),
except:
print "%3d%s" % (i,suf),

View File

@ -48,7 +48,12 @@ import gnome.mime
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from RelLib import * from RelLib import *
import Date import Date
import latin_ansel try:
from ansel import ansel_to_latin
except:
from latin_ansel import ansel_to_latin
import ansel
import latin_utf8 import latin_utf8
import intl import intl
import Utils import Utils
@ -105,7 +110,7 @@ fromtoRegexp = re.compile(r"\s*FROM\s+@#D([^@]+)@\s*(.*)\s+TO\s+@#D([^@]+)@\s*(.
# #
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
def importData(database, filename): def importData(database, filename, cb=None):
global callback global callback
@ -139,7 +144,10 @@ def importData(database, filename):
statusWindow.destroy() statusWindow.destroy()
Utils.modified() Utils.modified()
if callback: if cb:
statusWindow.destroy()
cb(1)
elif callback:
callback(1) callback(1)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -1383,7 +1391,7 @@ class GedcomParser:
self.cnv = latin_utf8.utf8_to_latin self.cnv = latin_utf8.utf8_to_latin
elif matches[2] == "ANSEL": elif matches[2] == "ANSEL":
self.code = ANSEL self.code = ANSEL
self.cnv = latin_ansel.ansel_to_latin self.cnv = ansel_to_latin
self.ignore_sub_junk(2) self.ignore_sub_junk(2)
self.update(self.encoding_obj,matches[2]) self.update(self.encoding_obj,matches[2])
elif matches[1] == "GEDC": elif matches[1] == "GEDC":

View File

@ -38,7 +38,11 @@ import gnome.ui
import libglade import libglade
from GedcomInfo import * from GedcomInfo import *
from latin_ansel import latin_to_ansel try:
from ansel import latin_to_ansel
except:
from latin_ansel import latin_to_ansel
from latin_utf8 import latin_to_utf8 from latin_utf8 import latin_to_utf8
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -84,15 +88,15 @@ def add_familys_sources(family,slist,private):
continue continue
for source_ref in event.getSourceRefList(): for source_ref in event.getSourceRefList():
sbase = source_ref.getBase() sbase = source_ref.getBase()
if sbase != None and sbase not in slist: if sbase != None and not slist.has_key(sbase):
slist.append(sbase) slist[sbase.getId()] = 1
for attr in family.getAttributeList(): for attr in family.getAttributeList():
if private and attr.getPrivacy(): if private and attr.getPrivacy():
continue continue
for source_ref in attr.getSourceRefList(): for source_ref in attr.getSourceRefList():
sbase = source_ref.getBase() sbase = source_ref.getBase()
if sbase != None and sbase not in slist: if sbase != None and not slist.has_key(sbase.getId()):
slist.append(sbase) slist[sbase.getId()] = 1
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -109,32 +113,32 @@ def add_persons_sources(person,slist,private):
continue continue
for source_ref in event.getSourceRefList(): for source_ref in event.getSourceRefList():
sbase = source_ref.getBase() sbase = source_ref.getBase()
if sbase != None and sbase not in slist: if sbase != None and not slist.has_key(sbase.getId()):
slist.append(sbase) slist[sbase.getId()] = 1
for event in person.getAddressList(): for event in person.getAddressList():
if private and event.getPrivacy(): if private and event.getPrivacy():
continue continue
for source_ref in event.getSourceRefList(): for source_ref in event.getSourceRefList():
sbase = source_ref.getBase() sbase = source_ref.getBase()
if sbase != None and sbase not in slist: if sbase != None and not slist.has_key(sbase.getId()):
slist.append(sbase) slist[sbase.getId()] = 1
for event in person.getAttributeList(): for event in person.getAttributeList():
if private and event.getPrivacy(): if private and event.getPrivacy():
continue continue
for source_ref in event.getSourceRefList(): for source_ref in event.getSourceRefList():
sbase = source_ref.getBase() sbase = source_ref.getBase()
if sbase != None and sbase not in slist: if sbase != None and not slist.has_key(sbase.getId()):
slist.append(sbase) slist[sbase.getId()] = 1
for name in person.getAlternateNames() + [person.getPrimaryName()]: for name in person.getAlternateNames() + [person.getPrimaryName()]:
if private and name.getPrivacy(): if private and name.getPrivacy():
continue continue
for source_ref in name.getSourceRefList(): for source_ref in name.getSourceRefList():
sbase = source_ref.getBase() sbase = source_ref.getBase()
if sbase != None and sbase not in slist: if sbase != None and not slist.has_key(sbase.getId()):
slist.append(sbase) slist[sbase.getId()] = 1
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -303,9 +307,9 @@ class GedcomWriter:
self.restrict = 1 self.restrict = 1
self.private = 1 self.private = 1
self.cnvtxt = latin_to_ansel self.cnvtxt = latin_to_ansel
self.plist = [] self.plist = {}
self.slist = [] self.slist = {}
self.flist = [] self.flist = {}
self.adopt = ADOPT_EVENT self.adopt = ADOPT_EVENT
self.fidval = 0 self.fidval = 0
self.fidmap = {} self.fidmap = {}
@ -381,17 +385,20 @@ class GedcomWriter:
name = self.topDialog.get_widget("filename").get_text() name = self.topDialog.get_widget("filename").get_text()
if cfilter == None: if cfilter == None:
self.plist = self.db.getPersonMap().values() for p in self.db.getPersonKeys():
self.plist[p] = 1
else: else:
self.plist = cfilter.apply(self.db.getPersonMap().values()) for p in cfilter.apply(self.db.getPersonMap().values()):
self.plist[p.getId()] = 1
self.flist = [] self.flist = {}
self.slist = [] self.slist = {}
for p in self.plist[:]: for key in self.plist.keys():
p = self.db.getPerson(key)
add_persons_sources(p,self.slist,self.private) add_persons_sources(p,self.slist,self.private)
for family in p.getFamilyList(): for family in p.getFamilyList():
add_familys_sources(family,self.slist,self.private) add_familys_sources(family,self.slist,self.private)
self.flist.append(family) self.flist[family.getId()] = 1
Utils.destroy_passed_object(obj) Utils.destroy_passed_object(obj)
@ -412,7 +419,6 @@ class GedcomWriter:
closebtn.set_sensitive(0) closebtn.set_sensitive(0)
self.export_data(name) self.export_data(name)
closebtn.set_sensitive(1) closebtn.set_sensitive(1)
def export_data(self,filename): def export_data(self,filename):
@ -477,12 +483,14 @@ class GedcomWriter:
self.g.write('1 ADDR Not Provided\n') self.g.write('1 ADDR Not Provided\n')
self.g.write('2 CONT Not Provided\n') self.g.write('2 CONT Not Provided\n')
self.plist.sort(sortById) pkeys = self.plist.keys()
pkeys.sort()
nump = float(len(self.plist)) nump = float(len(self.plist))
index = 0.0 index = 0.0
for person in self.plist: for key in pkeys:
self.write_person(person) self.write_person(self.db.getPerson(key))
index = index + 1 index = index + 1
if index%100 == 0:
self.pbar.set_value((100*index)/nump) self.pbar.set_value((100*index)/nump)
while(gtk.events_pending()): while(gtk.events_pending()):
gtk.mainiteration() gtk.mainiteration()
@ -497,17 +505,18 @@ class GedcomWriter:
def write_families(self): def write_families(self):
nump = float(len(self.flist)) nump = float(len(self.flist))
index = 0.0 index = 0.0
for family in self.flist: for key in self.flist.keys():
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.g.write("0 @%s@ FAM\n" % self.fid(family.getId()))
self.prefn(family) self.prefn(family)
person = family.getFather() person = family.getFather()
if person != None and person in self.plist: if person != None and self.plist.has_key(person.getId()):
self.g.write("1 HUSB @%s@\n" % self.pid(person.getId())) self.g.write("1 HUSB @%s@\n" % self.pid(person.getId()))
father_alive = person.probablyAlive() father_alive = person.probablyAlive()
person = family.getMother() person = family.getMother()
if person != None and person in self.plist: if person != None and self.plist.has_key(person.getId()):
self.g.write("1 WIFE @%s@\n" % self.pid(person.getId())) self.g.write("1 WIFE @%s@\n" % self.pid(person.getId()))
mother_alive = person.probablyAlive() mother_alive = person.probablyAlive()
@ -534,7 +543,7 @@ class GedcomWriter:
self.dump_event_stats(event) self.dump_event_stats(event)
for person in family.getChildList(): for person in family.getChildList():
if person not in self.plist: if not self.plist.has_key(person.getId()):
continue continue
self.g.write("1 CHIL @%s@\n" % self.pid(person.getId())) self.g.write("1 CHIL @%s@\n" % self.pid(person.getId()))
if self.adopt == ADOPT_FTW: if self.adopt == ADOPT_FTW:
@ -554,6 +563,7 @@ class GedcomWriter:
break break
index = index + 1 index = index + 1
if index % 100 == 0:
self.fbar.set_value((100*index)/nump) self.fbar.set_value((100*index)/nump)
while(gtk.events_pending()): while(gtk.events_pending()):
gtk.mainiteration() gtk.mainiteration()
@ -562,7 +572,8 @@ class GedcomWriter:
def write_sources(self): def write_sources(self):
nump = float(len(self.slist)) nump = float(len(self.slist))
index = 0.0 index = 0.0
for source in self.slist: for key in self.slist.keys():
source = self.db.getSource(key)
self.g.write("0 @%s@ SOUR\n" % self.sid(source.getId())) self.g.write("0 @%s@ SOUR\n" % 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.g.write("1 TITL %s\n" % fmtline(self.cnvtxt(source.getTitle()),248,1))
@ -575,8 +586,9 @@ class GedcomWriter:
if source.getCallNumber() != "": if source.getCallNumber() != "":
self.g.write("1 CALN %s\n" % self.cnvtxt(source.getCallNumber())) self.g.write("1 CALN %s\n" % self.cnvtxt(source.getCallNumber()))
if source.getNote() != "": if source.getNote() != "":
self.write_long_text("NOTE",1,source.getNote()) self.write_long_text("NOTE",1,self.cnvtxt(source.getNote()))
index = index + 1 index = index + 1
if index % 100 == 0:
self.sbar.set_value((100*index)/nump) self.sbar.set_value((100*index)/nump)
while(gtk.events_pending()): while(gtk.events_pending()):
gtk.mainiteration() gtk.mainiteration()
@ -690,7 +702,7 @@ class GedcomWriter:
self.g.write("2 TYPE %s\n" % self.cnvtxt(name)) self.g.write("2 TYPE %s\n" % self.cnvtxt(name))
self.g.write("2 PLAC %s\n" % self.cnvtxt(attr.getValue())) self.g.write("2 PLAC %s\n" % self.cnvtxt(attr.getValue()))
if attr.getNote() != "": if attr.getNote() != "":
self.write_long_text("NOTE",2,attr.getNote()) self.write_long_text("NOTE",2,self.cnvtxt(attr.getNote()))
for srcref in attr.getSourceRefList(): for srcref in attr.getSourceRefList():
self.write_source_ref(2,srcref) self.write_source_ref(2,srcref)
@ -718,19 +730,19 @@ class GedcomWriter:
if text: if text:
self.g.write("2 PLAC %s\n" % text) self.g.write("2 PLAC %s\n" % text)
if addr.getNote() != "": if addr.getNote() != "":
self.write_long_text("NOTE",3,addr.getNote()) self.write_long_text("NOTE",3,self.cnvtxt(addr.getNote()))
for srcref in addr.getSourceRefList(): for srcref in addr.getSourceRefList():
self.write_source_ref(3,srcref) self.write_source_ref(3,srcref)
for family in person.getParentList(): for family in person.getParentList():
if family in self.flist: if self.flist.has_key(family[0].getId()):
self.g.write("1 FAMC @%s@\n" % self.fid(family[0].getId())) self.g.write("1 FAMC @%s@\n" % self.fid(family[0].getId()))
if self.adopt == ADOPT_PEDI: if self.adopt == ADOPT_PEDI:
if string.lower(family[1]) == "adopted": if string.lower(family[1]) == "adopted":
self.g.write("2 PEDI Adopted\n") self.g.write("2 PEDI Adopted\n")
for family in person.getFamilyList(): for family in person.getFamilyList():
if family != None and family in self.flist: if family != None and self.flist.has_key(family.getId()):
self.g.write("1 FAMS @%s@\n" % self.fid(family.getId())) self.g.write("1 FAMS @%s@\n" % self.fid(family.getId()))
if self.obje: if self.obje:
@ -743,7 +755,7 @@ class GedcomWriter:
self.g.write('2 FILE %s\n' % url.get_path()) self.g.write('2 FILE %s\n' % url.get_path())
if person.getNote() != "": if person.getNote() != "":
self.write_long_text("NOTE",1,person.getNote()) self.write_long_text("NOTE",1,self.cnvtxt(person.getNote()))
def write_long_text(self,tag,level,note): def write_long_text(self,tag,level,note):
if self.conc == CONC_OK: if self.conc == CONC_OK:
@ -817,7 +829,7 @@ class GedcomWriter:
if event.getCause() != "": if event.getCause() != "":
self.g.write("2 CAUS %s\n" % self.cnvtxt(event.getCause())) self.g.write("2 CAUS %s\n" % self.cnvtxt(event.getCause()))
if event.getNote() != "": if event.getNote() != "":
self.write_long_text("NOTE",2,event.getNote()) self.write_long_text("NOTE",2,self.cnvtxt(event.getNote()))
for srcref in event.getSourceRefList(): for srcref in event.getSourceRefList():
self.write_source_ref(2,srcref) self.write_source_ref(2,srcref)
@ -835,7 +847,7 @@ class GedcomWriter:
if ord.getStatus() != 0: if ord.getStatus() != 0:
self.g.write("2 STAT %s\n" % self.cnvtxt(statlist[ord.getStatus()])) self.g.write("2 STAT %s\n" % self.cnvtxt(statlist[ord.getStatus()]))
if ord.getNote() != "": if ord.getNote() != "":
self.write_long_text("NOTE",index+1,ord.getNote()) self.write_long_text("NOTE",index+1,self.cnvtxt(ord.getNote()))
for srcref in ord.getSourceRefList(): for srcref in ord.getSourceRefList():
self.write_source_ref(index+1,srcref) self.write_source_ref(index+1,srcref)
@ -895,7 +907,7 @@ class GedcomWriter:
if nick != "": if nick != "":
self.g.write('2 NICK %s\n' % nick) self.g.write('2 NICK %s\n' % nick)
if name.getNote() != "": if name.getNote() != "":
self.write_long_text("NOTE",2,name.getNote()) self.write_long_text("NOTE",2,self.cnvtxt(name.getNote()))
for srcref in name.getSourceRefList(): for srcref in name.getSourceRefList():
self.write_source_ref(2,srcref) self.write_source_ref(2,srcref)