Remove a few layers of function call to speed things up a bit

svn: r152
This commit is contained in:
Don Allingham 2001-06-17 13:40:57 +00:00
parent 11b66cc9f0
commit a6041c7afd
2 changed files with 284 additions and 212 deletions

View File

@ -105,15 +105,13 @@ class Date:
#
#--------------------------------------------------------------------
def getDate(self):
function = SingleDate.fmtFunc[Date.formatCode]
if self.range == 1:
return _("from") + " " + function(self.start) + " " + \
_("to") + " " + function(self.stop)
if self.range == 0:
return _func(self.start)
elif self.range == -1:
return self.text
else:
return function(self.start)
return _("from") + " " + _func(self.start) + " " + \
_("to") + " " + _func(self.stop)
#--------------------------------------------------------------------
#
@ -121,15 +119,13 @@ class Date:
#
#--------------------------------------------------------------------
def getQuoteDate(self):
function = SingleDate.fmtFunc[Date.formatCode]
if self.range == 1:
return _("from") + " " + function(self.start) + " " + \
_("to") + " " + function(self.stop)
if self.range == 0:
return _func(self.start)
elif self.range == -1 and self.text:
return '"' + self.text + '"'
else:
return function(self.start)
return _("from") + " " + _func(self.start) + " " + \
_("to") + " " + _func(self.stop)
#--------------------------------------------------------------------
#
@ -186,6 +182,24 @@ class Date:
self.range = -1
self.text = text
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def set_format_code(code):
global _func
Date.formatCode = code
_func = SingleDate.fmtFunc[code]
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def get_format_code():
return Date.formatCode
#-------------------------------------------------------------------------
#
#
@ -326,10 +340,7 @@ class SingleDate:
#
#--------------------------------------------------------------------
def setMonth(self,val):
if val > 0 and val < 13:
self.month = val - 1
else:
self.month = -1
self.month = val - 1
#--------------------------------------------------------------------
#
@ -345,8 +356,7 @@ class SingleDate:
#
#--------------------------------------------------------------------
def setDay(self,val):
if val > 0 or val < 32:
self.day = val
self.day = val
#--------------------------------------------------------------------
#
@ -378,9 +388,9 @@ class SingleDate:
#
#--------------------------------------------------------------------
def setMonthStr(self,text):
if SingleDate.m2num.has_key(string.lower(text[0:3])):
try:
self.month = SingleDate.m2num[string.lower(text[0:3])]
else:
except:
self.month = -1
#--------------------------------------------------------------------
@ -389,9 +399,9 @@ class SingleDate:
#
#--------------------------------------------------------------------
def setMonthStrEng(self,text):
if SingleDate.em2num.has_key(string.lower(text[0:3])):
try:
self.month = SingleDate.em2num[string.lower(text[0:3])]
else:
except:
self.month = -1
#--------------------------------------------------------------------
@ -414,13 +424,13 @@ class SingleDate:
pass
elif self.day == -1:
if self.month == -1:
retval = "%d" % self.year
retval = str(self.year)
elif self.year == -1:
retval = SingleDate.emname[self.month]
else:
retval = "%s %d" % (SingleDate.emname[self.month],self.year)
elif self.month == -1:
retval = "%d" % self.year
retval = str(self.year)
else:
month = SingleDate.emname[self.month]
if self.year == -1:
@ -429,7 +439,7 @@ class SingleDate:
retval = "%d %s %d" % (self.day,month,self.year)
if self.mode == SingleDate.about:
retval = "ABT " + retval
retval = "ABT %s" % retval
if self.mode == SingleDate.before:
retval = _("BEFORE") + " " + retval
@ -444,19 +454,18 @@ class SingleDate:
#
#--------------------------------------------------------------------
def getFmt1(self):
retval = ""
if self.month == -1 and self.day == -1 and self.year == -1 :
pass
return ""
elif self.day == -1:
if self.month == -1:
retval = "%d" % self.year
retval = str(self.year)
elif self.year == -1:
retval = SingleDate.mname[self.month]
else:
retval = "%s %d" % (SingleDate.mname[self.month],self.year)
elif self.month == -1:
retval = "%d" % self.year
retval = str(self.year)
else:
month = SingleDate.mname[self.month]
if self.year == -1:
@ -480,35 +489,32 @@ class SingleDate:
#
#--------------------------------------------------------------------
def getFmt2(self):
retval = ""
if self.month == -1 and self.day == -1 and self.year == -1 :
pass
return ""
elif self.month != -1 and self.month != -1:
month = SingleDate.mname[self.month]
if self.year == -1:
retval = "%s %d, ????" % (string.upper(month[0:3]),self.day)
else:
retval = "%s %d, %d" % (string.upper(month[0:3]),self.day,self.year)
elif self.day == -1:
if self.month == -1:
retval = "%d" % self.year
retval = str(self.year)
elif self.year == -1:
month = SingleDate.mname[self.month]
retval = string.upper(month[0:3])
else:
month = SingleDate.mname[self.month]
retval = "%s %d" % (string.upper(month[0:3]),self.year)
elif self.month == -1:
retval = "%d" % self.year
else:
month = SingleDate.mname[self.month]
if self.year == -1:
retval = "%s %d, ????" % (string.upper(month[0:3]),self.day)
else:
retval = "%s %d, %d" % (string.upper(month[0:3]),self.day,self.year)
retval = str(self.year)
if self.mode == SingleDate.about:
retval = "ABT" + ' ' + retval
if self.mode == SingleDate.about:
retval = "%s %s" % (_("ABT"),retval)
if self.mode == SingleDate.before:
retval = _("BEFORE") + " " + retval
retval = "%s %s" % (_("BEFORE"),retval)
elif self.mode == SingleDate.after:
retval = _("AFTER") + " " + retval
retval = "%s %s" % (_("AFTER"),retval)
return retval
@ -524,7 +530,7 @@ class SingleDate:
pass
elif self.day == -1:
if self.month == -1:
retval = "%d" % self.year
retval = str(self.year)
elif self.year == -1:
month = SingleDate.mname[self.month]
retval = string.upper(month[0:3])
@ -532,7 +538,7 @@ class SingleDate:
month = SingleDate.mname[self.month]
retval = "%s %d" % (string.upper(month[0:3]),self.year)
elif self.month == -1:
retval = "%d" % self.year
retval = str(self.year)
else:
month = SingleDate.mname[self.month]
if self.year == -1:
@ -541,12 +547,11 @@ class SingleDate:
retval = "%d %s %d" % (self.day,string.upper(month[0:3]),self.year)
if self.mode == SingleDate.about:
retval = "ABT " + retval
retval = "%s %s" % (_("ABT"),retval)
if self.mode == SingleDate.before:
retval = _("BEFORE") + " " + retval
retval = "%s %s" % (_("BEFORE"),retval)
elif self.mode == SingleDate.after:
retval = _("AFTER") + " " + retval
retval = "%s %s" % (_("AFTER"),retval)
return retval
@ -562,7 +567,7 @@ class SingleDate:
pass
elif self.day == -1:
if self.month == -1:
retval = "%d" % self.year
retval = str(self.year)
elif self.year == -1:
retval = "%d/??/??" % self.month+1
else:
@ -576,12 +581,12 @@ class SingleDate:
retval = "%d/%d/%d" % (self.month+1,self.day,self.year)
if self.mode == SingleDate.about:
retval = "ABT" + ' ' + retval
retval = "%s %s" % (_("ABT"),retval)
if self.mode == SingleDate.before:
retval = "BEFORE " + retval
retval = "%s %s" % (_("BEFORE"),retval)
elif self.mode == SingleDate.after:
retval = "AFTER " + retval
retval = "%s %s" % (_("AFTER"),retval)
return retval
@ -597,7 +602,7 @@ class SingleDate:
pass
elif self.day == -1:
if self.month == -1:
retval = "%d" % self.year
retval = str(self.year)
elif self.year == -1:
retval = "%d-??-??" % self.month+1
else:
@ -611,12 +616,11 @@ class SingleDate:
retval = "%d-%d-%d" % (self.month+1,self.day,self.year)
if self.mode == SingleDate.about:
retval = "ABT" + ' ' + retval
retval = "%s %s" % (_("ABT"),retval)
if self.mode == SingleDate.before:
retval = _("BEFORE") + " " + retval
retval = "%s %s" % (_("BEFORE"),retval)
elif self.mode == SingleDate.after:
retval = _("AFTER") + " " + retval
retval = "%s %s" % (_("AFTER"),retval)
return retval
@ -632,7 +636,7 @@ class SingleDate:
pass
elif self.day == -1:
if self.month == -1:
retval = "%d" % self.year
retval = str(self.year)
elif self.year == -1:
retval = "??/%d/??" % self.month+1
else:
@ -646,12 +650,11 @@ class SingleDate:
retval = "%d/%d/%d" % (self.day,self.month+1,self.year)
if self.mode == SingleDate.about:
retval = "ABT" + ' ' + retval
retval = "%s %s" % (_("ABT"),retval)
if self.mode == SingleDate.before:
retval = _("BEFORE") + " " + retval
retval = "%s %s" % (_("BEFORE"),retval)
elif self.mode == SingleDate.after:
retval = _("AFTER") + " " + retval
retval = "%s %s" % (_("AFTER"),retval)
return retval
@ -679,12 +682,11 @@ class SingleDate:
retval = "%d-%d-%d" % (self.day,self.month+1,self.year)
if self.mode == SingleDate.about:
retval = "ABT" + ' ' + retval
retval = "%s %s" % (_("ABT"),retval)
if self.mode == SingleDate.before:
retval = _("BEFORE") + " " + retval
retval = "%s %s" % (_("BEFORE"),retval)
elif self.mode == SingleDate.after:
retval = _("AFTER") + " " + retval
retval = "%s %s" % (_("AFTER"),retval)
return retval
@ -730,24 +732,24 @@ class SingleDate:
matches = match.groups()
self.getMode(matches[0])
self.setMonthStr(matches[2])
self.setDay(string.atoi(matches[1]))
self.day = int(matches[1])
if len(matches) == 4:
val = matches[3]
if val == None or val[0] == '?':
self.setYear(-1)
self.year = -1
else:
self.setYear(string.atoi(val))
self.year = int(val)
else:
self.setYear(-1)
self.year = -1
return 1
match = SingleDate.fmt5.match(text)
if match != None:
matches = match.groups()
self.getMode(matches[0])
self.setMonth(-1)
self.setDay(-1)
self.setYear(string.atoi(matches[1]))
self.month = -1
self.day = -1
self.year = int(matches[1])
return 1
match = SingleDate.fmt7.match(text)
@ -755,13 +757,13 @@ class SingleDate:
matches = match.groups()
self.getMode(matches[0])
try:
self.setMonth(string.atoi(matches[1]))
self.month = int(matches[1])-1
except:
self.setMonth(-1)
self.month = -1
try:
self.setYear(string.atoi(matches[2]))
self.year = int(matches[2])
except:
self.setYear(-1)
self.year = -1
return 1
match = SingleDate.fmt3.match(text)
@ -770,27 +772,27 @@ class SingleDate:
self.getMode(matches[0])
if Date.entryCode == 0:
try:
self.setMonth(string.atoi(matches[1]))
self.month = int(matches[1])-1
except:
self.setMonth(-1)
self.month = -1
try:
self.setDay(string.atoi(matches[2]))
self.day = int(matches[2])
except:
self.setDay(-1)
self.day = -1
else:
try:
self.setMonth(string.atoi(matches[2]))
self.month = int(matches[2])-1
except:
self.setMonth(-1)
self.month = -1
try:
self.setDay(string.atoi(matches[1]))
self.day = int(matches[1])
except:
self.setDay(-1)
self.day = -1
val = matches[3]
if val == None or val[0] == '?':
self.setYear(-1)
self.year = -1
else:
self.setYear(string.atoi(val))
self.year = int(val)
return 1
match = SingleDate.fmt1.match(text)
@ -800,14 +802,14 @@ class SingleDate:
self.setMonthStr(matches[1])
val = matches[2]
if val:
self.setDay(string.atoi(string.replace(val,',','')))
self.day = int(string.replace(val,',',''))
else:
self.setDay(-1)
self.day = -1
val = matches[3]
if val == None or val[0] == '?':
self.setYear(-1)
self.year = -1
else:
self.setYear(string.atoi(val))
self.year = int(val)
return 1
match = SingleDate.fmt4.match(text)
@ -815,22 +817,22 @@ class SingleDate:
matches = match.groups()
self.getMode(matches[0])
self.setMonthStr(matches[1])
self.setDay(-1)
self.day = -1
if len(matches) == 4:
val = matches[3]
if val == None or val[0] == '?' :
self.setYear(-1)
self.year = -1
else:
self.setYear(string.atoi(val))
self.year = int(val)
return 1
match = SingleDate.fmt6.match(text)
if match != None:
matches = match.groups()
self.getMode(matches[0])
self.setMonth(matches[1])
self.setDay(-1)
self.setYear(-1)
self.month = int(matches[1])-1
self.day = -1
self.year = -1
return 1
raise Date.Error,text
@ -846,19 +848,19 @@ class SingleDate:
matches = match.groups()
self.setMode(matches[0])
self.setMonthStrEng(matches[2])
self.setDay(string.atoi(matches[1]))
self.day = int(matches[1])
if len(matches) == 4:
val = matches[3]
if val == None or val[0] == '?':
self.setYear(-1)
self.year = -1
else:
self.setYear(string.atoi(val))
self.year = int(val)
else:
self.setYear(-1)
self.year = -1
else:
self.setYear(-1)
self.setMonth(-1)
self.setDay(-1)
self.year = -1
self.month = -1
self.day = -1
raise Date.Error,text
#-------------------------------------------------------------------------
@ -876,6 +878,9 @@ def compare_dates(f,s):
else:
return cmp(first.day,second.day)
_func = SingleDate.fmtFunc[0]
if __name__ == "__main__":
def checkit(s):

View File

@ -67,7 +67,7 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def __init__(self,database,callback,base,is_import):
def __init__(self,database,callback,base):
self.call = None
self.stext_list = []
self.scomments_list = []
@ -75,25 +75,17 @@ class GrampsParser(handler.ContentHandler):
self.use_p = 0
self.in_note = 0
self.in_attribute = 0
self.in_old_attr = 0
self.in_stext = 0
self.in_scomments = 0
self.in_people = 0
self.in_name = 0
self.db = database
self.base = base
self.in_family = 0
self.in_source_ref = 0
self.in_source = 0
self.in_address = 0
self.in_event = 0
self.person = None
self.family = None
self.address = None
self.source = None
self.source_ref = None
self.is_import = is_import
self.attribute = None
self.resname = ""
self.resaddr = ""
@ -152,7 +144,6 @@ class GrampsParser(handler.ContentHandler):
def start_event(self,attrs):
self.event = Event()
self.event_type = string.capwords(attrs["type"])
self.in_event = 1
#---------------------------------------------------------------------
#
@ -160,16 +151,15 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def start_attribute(self,attrs):
self.in_attribute = 1
self.attribute = Attribute()
if attrs.has_key('type'):
self.in_old_attr = 1
self.attribute.setType(string.capwords(attrs["type"]))
else:
self.in_old_attr = 0
if self.in_people:
if self.person:
self.person.addAttribute(self.attribute)
elif self.in_family:
elif self.family:
self.family.addAttribute(self.attribute)
#---------------------------------------------------------------------
@ -178,7 +168,6 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def start_address(self,attrs):
self.in_address = 1
self.address = Address()
self.person.addAddress(self.address)
@ -188,10 +177,7 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def start_bmark(self,attrs):
if self.is_import:
person = self.db.findPerson("x%s" % attrs["ref"],self.pmap)
else:
person = self.db.findPersonNoMap(attrs["ref"])
person = self.db.findPersonNoMap(attrs["ref"])
self.db.bookmarks.append(person)
#---------------------------------------------------------------------
@ -203,10 +189,7 @@ class GrampsParser(handler.ContentHandler):
if self.count % self.increment == 0:
self.callback(float(self.count)/float(self.entries))
self.count = self.count + 1
if self.is_import:
self.person = self.db.findPerson("x%s" % attrs["id"],self.pmap)
else:
self.person = self.db.findPersonNoMap(attrs["id"])
self.person = self.db.findPersonNoMap(attrs["id"])
#---------------------------------------------------------------------
#
@ -214,10 +197,7 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def start_people(self,attrs):
self.in_family = 0
self.in_people = 1
self.in_source = 0
if self.is_import == 0 and attrs.has_key("default"):
if attrs.has_key("default"):
self.tempDefault = int(attrs["default"])
#---------------------------------------------------------------------
@ -226,10 +206,7 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def start_father(self,attrs):
if self.is_import:
father = self.db.findPerson("x%s" % attrs["ref"],self.pmap)
else:
father = self.db.findPersonNoMap(attrs["ref"])
father = self.db.findPersonNoMap(attrs["ref"])
self.family.setFather(father)
#---------------------------------------------------------------------
@ -238,10 +215,7 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def start_mother(self,attrs):
if self.is_import:
mother = self.db.findPerson("x%s" % attrs["ref"],self.pmap)
else:
mother = self.db.findPersonNoMap(attrs["ref"])
mother = self.db.findPersonNoMap(attrs["ref"])
self.family.setMother(mother)
#---------------------------------------------------------------------
@ -250,10 +224,7 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def start_child(self,attrs):
if self.is_import:
child = self.db.findPerson("x%s" % attrs["ref"],self.pmap)
else:
child = self.db.findPersonNoMap(attrs["ref"])
child = self.db.findPersonNoMap(attrs["ref"])
self.family.addChild(child)
#---------------------------------------------------------------------
@ -285,10 +256,7 @@ class GrampsParser(handler.ContentHandler):
if self.count % self.increment == 0:
self.callback(float(self.count)/float(self.entries))
self.count = self.count + 1
if self.is_import:
self.family = self.db.findFamily(attrs["id"],self.fmap)
else:
self.family = self.db.findFamilyNoMap(attrs["id"])
self.family = self.db.findFamilyNoMap(attrs["id"])
if attrs.has_key("type"):
self.family.setRelationship(attrs["type"])
@ -298,10 +266,7 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def start_childof(self,attrs):
if self.is_import:
family = self.db.findFamily(attrs["ref"],self.fmap)
else:
family = self.db.findFamilyNoMap(attrs["ref"])
family = self.db.findFamilyNoMap(attrs["ref"])
if attrs.has_key("type"):
type = attrs["type"]
self.person.addAltFamily(family,type)
@ -314,10 +279,7 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def start_parentin(self,attrs):
if self.is_import:
family = self.db.findFamily(attrs["ref"],self.fmap)
else:
family = self.db.findFamilyNoMap(attrs["ref"])
family = self.db.findFamilyNoMap(attrs["ref"])
self.person.addFamily(family)
#---------------------------------------------------------------------
@ -327,7 +289,6 @@ class GrampsParser(handler.ContentHandler):
#---------------------------------------------------------------------
def start_name(self,attrs):
self.name = Name()
self.in_name = 1
#---------------------------------------------------------------------
#
@ -337,26 +298,6 @@ class GrampsParser(handler.ContentHandler):
def start_note(self,attrs):
self.in_note = 1
#---------------------------------------------------------------------
#
#
#
#---------------------------------------------------------------------
def start_families(self,attrs):
self.in_family = 1
self.in_people = 0
self.in_source = 0
#---------------------------------------------------------------------
#
#
#
#---------------------------------------------------------------------
def start_sources(self,attrs):
self.in_family = 0
self.in_people = 0
self.in_source = 1
#---------------------------------------------------------------------
#
#
@ -364,19 +305,15 @@ class GrampsParser(handler.ContentHandler):
#---------------------------------------------------------------------
def start_sourceref(self,attrs):
self.source_ref = SourceRef()
self.in_source_ref = 1
if self.is_import:
self.source = self.db.findSource(attrs["ref"],self.smap)
else:
self.source = self.db.findSourceNoMap(attrs["ref"])
self.source = self.db.findSourceNoMap(attrs["ref"])
self.source_ref.setBase(self.source)
if self.in_address:
if self.address:
self.address.setSourceRef(self.source_ref)
elif self.in_name:
elif self.name:
self.name.setSourceRef(self.source_ref)
elif self.in_event:
elif self.event:
self.event.setSourceRef(self.source_ref)
elif self.in_attribute:
elif self.attribute:
self.attribute.setSourceRef(self.source_ref)
else:
print "Sorry, I'm lost"
@ -387,10 +324,7 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def start_source(self,attrs):
if self.is_import:
self.source = self.db.findSource(attrs["id"],self.smap)
else:
self.source = self.db.findSourceNoMap(attrs["id"])
self.source = self.db.findSourceNoMap(attrs["id"])
#---------------------------------------------------------------------
#
@ -408,9 +342,9 @@ class GrampsParser(handler.ContentHandler):
else:
photo.setPath(src)
photo.setPrivate(0)
if self.in_family == 1:
if self.family:
self.family.addPhoto(photo)
if self.in_source == 1:
if self.source:
self.source.addPhoto(photo)
else:
self.person.addPhoto(photo)
@ -430,10 +364,10 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def stop_attribute(self,tag):
self.in_attribute = 0
if self.in_old_attr:
self.attribute.setValue(tag)
self.in_old_attr = 0
self.attribute = None
#---------------------------------------------------------------------
#
@ -457,7 +391,7 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def stop_address(self,tag):
self.in_address = 0
self.address = None
#---------------------------------------------------------------------
#
@ -465,7 +399,6 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def stop_event(self,tag):
self.in_event = 0
self.event.setName(self.event_type)
if self.event_type == "Birth":
@ -476,10 +409,11 @@ class GrampsParser(handler.ContentHandler):
self.family.setMarriage(self.event)
elif self.event_type == "Divorce":
self.family.setDivorce(self.event)
elif self.in_people == 1:
elif self.person:
self.person.addEvent(self.event)
else:
self.family.addEvent(self.event)
self.event = None
#---------------------------------------------------------------------
#
@ -488,7 +422,7 @@ class GrampsParser(handler.ContentHandler):
#---------------------------------------------------------------------
def stop_name(self,tag):
self.person.setPrimaryName(self.name)
self.in_name = 0
self.name = None
#---------------------------------------------------------------------
#
@ -513,7 +447,7 @@ class GrampsParser(handler.ContentHandler):
#---------------------------------------------------------------------
def stop_date(self,tag):
if tag:
if self.in_address:
if self.address:
self.address.setDate(tag)
else:
self.event.getDateObj().quick_set(tag)
@ -526,6 +460,22 @@ class GrampsParser(handler.ContentHandler):
def stop_first(self,tag):
self.name.setFirstName(tag)
#---------------------------------------------------------------------
#
#
#
#---------------------------------------------------------------------
def stop_family(self,tag):
self.family = None
#---------------------------------------------------------------------
#
#
#
#---------------------------------------------------------------------
def stop_person(self,tag):
self.person = None
#---------------------------------------------------------------------
#
#
@ -559,7 +509,15 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def stop_sourceref(self,tag):
self.in_source_ref = 0
self.source_ref = None
#---------------------------------------------------------------------
#
#
#
#---------------------------------------------------------------------
def stop_source(self,tag):
self.source = None
#---------------------------------------------------------------------
#
@ -688,19 +646,19 @@ class GrampsParser(handler.ContentHandler):
note = fix_spaces(self.note_list)
else:
note = tag
if self.in_address == 1:
if self.address:
self.address.setNote(note)
elif self.in_attribute == 1:
elif self.attribute:
self.attribute.setNote(note)
elif self.in_name == 1:
elif self.name:
self.name.setNote(note)
elif self.in_source == 1:
elif self.source:
self.source.setNote(note)
elif self.in_event == 1:
elif self.event:
self.event.setNote(note)
elif self.in_people == 1:
elif self.person:
self.person.setNote(note)
elif self.in_family == 1:
elif self.family:
self.family.setNote(note)
self.note_list = []
@ -817,7 +775,7 @@ class GrampsParser(handler.ContentHandler):
"date" : (None, stop_date),
"description": (None, stop_description),
"event" : (start_event, stop_event),
"families" : (start_families, None),
"families" : (None, None),
"family" : (start_family, None),
"father" : (start_father, None),
"first" : (None, stop_first),
@ -831,7 +789,7 @@ class GrampsParser(handler.ContentHandler):
"p" : (None, stop_ptag),
"parentin" : (start_parentin,None),
"people" : (start_people, None),
"person" : (start_person, None),
"person" : (start_person, stop_person),
"img" : (start_photo, None),
"place" : (None, stop_place),
"postal" : (None, stop_postal),
@ -848,9 +806,9 @@ class GrampsParser(handler.ContentHandler):
"scallno" : (None, stop_scallno),
"scomments" : (None, stop_scomments),
"sdate" : (None,stop_sdate),
"source" : (start_source, None),
"source" : (start_source, stop_source),
"sourceref" : (start_sourceref, stop_sourceref),
"sources" : (start_sources, None),
"sources" : (None, None),
"spage" : (None, stop_spage),
"spubinfo" : (None, stop_spubinfo),
"state" : (None, stop_state),
@ -905,3 +863,112 @@ class GrampsParser(handler.ContentHandler):
self.data = self.data + data
#-------------------------------------------------------------------------
#
# Gramps database parsing class. Derived from SAX XML parser
#
#-------------------------------------------------------------------------
class GrampsImportParser(handler.ContentHandler):
#---------------------------------------------------------------------
#
#
#
#---------------------------------------------------------------------
def start_bmark(self,attrs):
person = self.db.findPerson("x%s" % attrs["ref"],self.pmap)
self.db.bookmarks.append(person)
#---------------------------------------------------------------------
#
#
#
#---------------------------------------------------------------------
def start_person(self,attrs):
if self.count % self.increment == 0:
self.callback(float(self.count)/float(self.entries))
self.count = self.count + 1
self.person = self.db.findPerson("x%s" % attrs["id"],self.pmap)
#---------------------------------------------------------------------
#
#
#
#---------------------------------------------------------------------
def start_father(self,attrs):
father = self.db.findPerson("x%s" % attrs["ref"],self.pmap)
self.family.setFather(father)
#---------------------------------------------------------------------
#
#
#
#---------------------------------------------------------------------
def start_mother(self,attrs):
mother = self.db.findPerson("x%s" % attrs["ref"],self.pmap)
self.family.setMother(mother)
#---------------------------------------------------------------------
#
#
#
#---------------------------------------------------------------------
def start_child(self,attrs):
child = self.db.findPerson("x%s" % attrs["ref"],self.pmap)
self.family.addChild(child)
#---------------------------------------------------------------------
#
#
#
#---------------------------------------------------------------------
def start_family(self,attrs):
if self.count % self.increment == 0:
self.callback(float(self.count)/float(self.entries))
self.count = self.count + 1
self.family = self.db.findFamily(attrs["id"],self.fmap)
if attrs.has_key("type"):
self.family.setRelationship(attrs["type"])
#---------------------------------------------------------------------
#
#
#
#---------------------------------------------------------------------
def start_childof(self,attrs):
family = self.db.findFamily(attrs["ref"],self.fmap)
if attrs.has_key("type"):
type = attrs["type"]
self.person.addAltFamily(family,type)
else:
self.person.setMainFamily(family)
#---------------------------------------------------------------------
#
#
#
#---------------------------------------------------------------------
def start_sourceref(self,attrs):
self.source_ref = SourceRef()
self.source = self.db.findSource(attrs["ref"],self.smap)
self.source_ref.setBase(self.source)
if self.address:
self.address.setSourceRef(self.source_ref)
elif self.name:
self.name.setSourceRef(self.source_ref)
elif self.event:
self.event.setSourceRef(self.source_ref)
elif self.attribute:
self.attribute.setSourceRef(self.source_ref)
else:
print "Sorry, I'm lost"
#---------------------------------------------------------------------
#
#
#
#---------------------------------------------------------------------
def start_source(self,attrs):
self.source = self.db.findSource(attrs["id"],self.smap)