Fixed GEDCOM inline note import bug, sped up XML parsing
svn: r31
This commit is contained in:
parent
b02015a4b2
commit
946774ebd9
@ -40,9 +40,9 @@ class AbiWordDoc(TextDoc):
|
|||||||
else:
|
else:
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
|
|
||||||
self.f = open(filename,"w")
|
self.f = open(self.filename,"w")
|
||||||
self.f.write('<?xml version="1.0" encoding="ISO-8859-1"?>\n')
|
self.f.write('<?xml version="1.0" encoding="ISO-8859-1"?>\n')
|
||||||
self.f.write('<abiword version="0.7.13" fileformat="1.0">\n')
|
self.f.write('<abiword version="0.7.14" fileformat="1.0">\n')
|
||||||
self.f.write('<pagesize ')
|
self.f.write('<pagesize ')
|
||||||
self.f.write('pagetype="%s" ' % self.paper.get_name())
|
self.f.write('pagetype="%s" ' % self.paper.get_name())
|
||||||
if self.orientation == PAPER_PORTRAIT:
|
if self.orientation == PAPER_PORTRAIT:
|
||||||
@ -67,13 +67,13 @@ class AbiWordDoc(TextDoc):
|
|||||||
file = file_tuple[0]
|
file = file_tuple[0]
|
||||||
width = file_tuple[1]
|
width = file_tuple[1]
|
||||||
height = file_tuple[2]
|
height = file_tuple[2]
|
||||||
base = os.path.basename(file)
|
base = "/tmp/%s.png" % os.path.basename(file)
|
||||||
tag = string.replace(base,'.','_')
|
tag = string.replace(base,'.','_')
|
||||||
cmd = "%s -size %dx%d %s %s" % (const.convert,width,height,file,base)
|
cmd = "%s -size %dx%d %s %s" % (const.convert,width,height,file,base)
|
||||||
os.system(cmd)
|
os.system(cmd)
|
||||||
self.f.write('<d name="')
|
self.f.write('<d name="')
|
||||||
self.f.write(tag)
|
self.f.write(tag)
|
||||||
self.f.write('" mime=type="image/png" base64="yes">\n')
|
self.f.write('" mime-type="image/png" base64="yes">\n')
|
||||||
f = open(base,"rb")
|
f = open(base,"rb")
|
||||||
base64.encode(f,self.f)
|
base64.encode(f,self.f)
|
||||||
f.close()
|
f.close()
|
||||||
@ -94,13 +94,13 @@ class AbiWordDoc(TextDoc):
|
|||||||
|
|
||||||
self.photo_list.append((name,act_width,act_height))
|
self.photo_list.append((name,act_width,act_height))
|
||||||
|
|
||||||
base = os.path.basename(name)
|
base = "/tmp/%s.png" % os.path.basename(name)
|
||||||
tag = string.replace(base,'.','_')
|
tag = string.replace(base,'.','_')
|
||||||
|
|
||||||
self.f.write('<image data="')
|
self.f.write('<image dataid="')
|
||||||
self.f.write(tag)
|
self.f.write(tag)
|
||||||
self.f.write('" props="width:%.3fin; ' % ((float(act_width)/72.0)/2.54))
|
self.f.write('" props="width:%.3fin; ' % ((float(act_width)/72.0)/2.54))
|
||||||
self.f.write('height:%.3fin"/>\n' % ((float(act_height)/72.0)/2.54))
|
self.f.write('height:%.3fin"/>' % ((float(act_height)/72.0)/2.54))
|
||||||
|
|
||||||
def start_paragraph(self,style_name):
|
def start_paragraph(self,style_name):
|
||||||
style = self.style_list[style_name]
|
style = self.style_list[style_name]
|
||||||
@ -155,31 +155,14 @@ if __name__ == "__main__":
|
|||||||
foo.set_size(24)
|
foo.set_size(24)
|
||||||
|
|
||||||
para = ParagraphStyle()
|
para = ParagraphStyle()
|
||||||
para.set_font(foo)
|
|
||||||
para.set_alignment(PARA_ALIGN_RIGHT)
|
|
||||||
doc.add_style("MyTitle",para)
|
|
||||||
|
|
||||||
para = ParagraphStyle()
|
|
||||||
para.set_left_margin(1)
|
|
||||||
para.set_right_margin(1)
|
|
||||||
para.set_alignment(PARA_ALIGN_JUSTIFY)
|
|
||||||
doc.add_style("Normal",para)
|
doc.add_style("Normal",para)
|
||||||
|
|
||||||
doc.open("/home/dona/oo_test.abw")
|
doc.open("test")
|
||||||
doc.start_paragraph("MyTitle")
|
|
||||||
doc.write_text("This is my Title")
|
|
||||||
doc.end_paragraph()
|
|
||||||
|
|
||||||
doc.start_paragraph("Normal")
|
doc.start_paragraph("Normal")
|
||||||
doc.add_photo("/home/dona/dad.jpg",200,200)
|
doc.add_photo("image.jpg",200,200)
|
||||||
doc.end_paragraph()
|
doc.end_paragraph()
|
||||||
|
|
||||||
doc.start_paragraph("Normal")
|
|
||||||
doc.write_text("This is a test of the emergency broadcast system. ")
|
|
||||||
doc.write_text("This is a only a test. Repeat. This is only a test. ")
|
|
||||||
doc.write_text("Had this been an actual emergency, we would not be here ")
|
|
||||||
doc.write_text("to give you this message.")
|
|
||||||
doc.end_paragraph()
|
|
||||||
doc.close()
|
doc.close()
|
||||||
|
|
||||||
|
|
||||||
|
@ -57,65 +57,6 @@ def fix_spaces(text_list):
|
|||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
class GrampsParser(handler.ContentHandler):
|
class GrampsParser(handler.ContentHandler):
|
||||||
|
|
||||||
researchTag = "researcher"
|
|
||||||
resnameTag = "resname"
|
|
||||||
resaddrTag = "resaddr"
|
|
||||||
rescityTag = "rescity"
|
|
||||||
resstateTag = "resstate"
|
|
||||||
resconTag = "rescountry"
|
|
||||||
resposTag = "respostal"
|
|
||||||
resphoneTag = "resphone"
|
|
||||||
resemailTag = "resemail"
|
|
||||||
attrTag = "attribute"
|
|
||||||
addressTag = "address"
|
|
||||||
startTag = "date_start"
|
|
||||||
stopTag = "date_stop"
|
|
||||||
cityTag = "city"
|
|
||||||
stateTag = "state"
|
|
||||||
streetTag = "street"
|
|
||||||
countryTag = "country"
|
|
||||||
postalTag = "postal"
|
|
||||||
noteTag = "note"
|
|
||||||
uidTag = "uid"
|
|
||||||
urlTag = "url"
|
|
||||||
pTag = "p"
|
|
||||||
personTag = "person"
|
|
||||||
peopleTag = "people"
|
|
||||||
sourcesTag = "sources"
|
|
||||||
sourcerefTag= "sourceref"
|
|
||||||
photoTag = "img"
|
|
||||||
nameTag = "name"
|
|
||||||
akaTag = "aka"
|
|
||||||
firstTag = "first"
|
|
||||||
lastTag = "last"
|
|
||||||
nickTag = "nick"
|
|
||||||
genderTag = "gender"
|
|
||||||
titleTag = "title"
|
|
||||||
suffixTag = "suffix"
|
|
||||||
placeTag = "place"
|
|
||||||
descriptionTag = "description"
|
|
||||||
dateTag = "date"
|
|
||||||
familyTag = "family"
|
|
||||||
fatherTag = "father"
|
|
||||||
childTag = "child"
|
|
||||||
createdTag = "created"
|
|
||||||
childofTag = "childof"
|
|
||||||
parentinTag = "parentin"
|
|
||||||
motherTag = "mother"
|
|
||||||
familiesTag = "families"
|
|
||||||
eventTag = "event"
|
|
||||||
sourceTag = "source"
|
|
||||||
sdateTag = "sdate"
|
|
||||||
spageTag = "spage"
|
|
||||||
stitleTag = "stitle"
|
|
||||||
sauthorTag = "sauthor"
|
|
||||||
spubinfoTag = "spubinfo"
|
|
||||||
scallnoTag = "scallno"
|
|
||||||
stextTag = "stext"
|
|
||||||
bmarksTag = "bookmarks"
|
|
||||||
bmarkTag = "bookmark"
|
|
||||||
scommentsTag= "scomments"
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------
|
#---------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
@ -132,7 +73,7 @@ class GrampsParser(handler.ContentHandler):
|
|||||||
self.in_stext = 0
|
self.in_stext = 0
|
||||||
self.in_scomments = 0
|
self.in_scomments = 0
|
||||||
self.in_people = 0
|
self.in_people = 0
|
||||||
self.database = database
|
self.db = database
|
||||||
self.base = base
|
self.base = base
|
||||||
self.in_family = 0
|
self.in_family = 0
|
||||||
self.in_sources = 0
|
self.in_sources = 0
|
||||||
@ -142,6 +83,15 @@ class GrampsParser(handler.ContentHandler):
|
|||||||
self.sourceRef = None
|
self.sourceRef = None
|
||||||
self.is_import = is_import
|
self.is_import = is_import
|
||||||
|
|
||||||
|
self.resname = ""
|
||||||
|
self.resaddr = ""
|
||||||
|
self.rescity = ""
|
||||||
|
self.resstate = ""
|
||||||
|
self.rescon = ""
|
||||||
|
self.respos = ""
|
||||||
|
self.resphone = ""
|
||||||
|
self.resemail = ""
|
||||||
|
|
||||||
self.pmap = {}
|
self.pmap = {}
|
||||||
self.fmap = {}
|
self.fmap = {}
|
||||||
self.smap = {}
|
self.smap = {}
|
||||||
@ -154,8 +104,11 @@ class GrampsParser(handler.ContentHandler):
|
|||||||
self.name = None
|
self.name = None
|
||||||
self.tempDefault = None
|
self.tempDefault = None
|
||||||
self.owner = Researcher()
|
self.owner = Researcher()
|
||||||
self.active = ""
|
self.data = ""
|
||||||
self.data = {}
|
self.func_list = [None]*50
|
||||||
|
self.func_index = 0
|
||||||
|
self.func = None
|
||||||
|
|
||||||
handler.ContentHandler.__init__(self)
|
handler.ContentHandler.__init__(self)
|
||||||
|
|
||||||
#---------------------------------------------------------------------
|
#---------------------------------------------------------------------
|
||||||
@ -172,12 +125,12 @@ class GrampsParser(handler.ContentHandler):
|
|||||||
#
|
#
|
||||||
#---------------------------------------------------------------------
|
#---------------------------------------------------------------------
|
||||||
def endDocument(self):
|
def endDocument(self):
|
||||||
self.database.setResearcher(self.owner)
|
self.db.setResearcher(self.owner)
|
||||||
if self.tempDefault != None:
|
if self.tempDefault != None:
|
||||||
id = self.tempDefault
|
id = self.tempDefault
|
||||||
if self.database.personMap.has_key(id):
|
if self.db.personMap.has_key(id):
|
||||||
person = self.database.personMap[id]
|
person = self.db.personMap[id]
|
||||||
self.database.setDefaultPerson(person)
|
self.db.setDefaultPerson(person)
|
||||||
|
|
||||||
#---------------------------------------------------------------------
|
#---------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -214,10 +167,10 @@ class GrampsParser(handler.ContentHandler):
|
|||||||
#---------------------------------------------------------------------
|
#---------------------------------------------------------------------
|
||||||
def start_bmark(self,attrs):
|
def start_bmark(self,attrs):
|
||||||
if self.is_import:
|
if self.is_import:
|
||||||
person = self.database.findPerson("x%s" % attrs["ref"],self.pmap)
|
person = self.db.findPerson("x%s" % attrs["ref"],self.pmap)
|
||||||
else:
|
else:
|
||||||
person = self.database.findPersonNoMap(attrs["ref"])
|
person = self.db.findPersonNoMap(attrs["ref"])
|
||||||
self.database.bookmarks.append(person)
|
self.db.bookmarks.append(person)
|
||||||
|
|
||||||
#---------------------------------------------------------------------
|
#---------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -229,9 +182,9 @@ class GrampsParser(handler.ContentHandler):
|
|||||||
self.callback(float(self.count)/float(self.entries))
|
self.callback(float(self.count)/float(self.entries))
|
||||||
self.count = self.count + 1
|
self.count = self.count + 1
|
||||||
if self.is_import:
|
if self.is_import:
|
||||||
self.person = self.database.findPerson("x%s" % attrs["id"],self.pmap)
|
self.person = self.db.findPerson("x%s" % attrs["id"],self.pmap)
|
||||||
else:
|
else:
|
||||||
self.person = self.database.findPersonNoMap(attrs["id"])
|
self.person = self.db.findPersonNoMap(attrs["id"])
|
||||||
|
|
||||||
#---------------------------------------------------------------------
|
#---------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -252,9 +205,9 @@ class GrampsParser(handler.ContentHandler):
|
|||||||
#---------------------------------------------------------------------
|
#---------------------------------------------------------------------
|
||||||
def start_father(self,attrs):
|
def start_father(self,attrs):
|
||||||
if self.is_import:
|
if self.is_import:
|
||||||
father = self.database.findPerson("x%s" % attrs["ref"],self.pmap)
|
father = self.db.findPerson("x%s" % attrs["ref"],self.pmap)
|
||||||
else:
|
else:
|
||||||
father = self.database.findPersonNoMap(attrs["ref"])
|
father = self.db.findPersonNoMap(attrs["ref"])
|
||||||
self.family.setFather(father)
|
self.family.setFather(father)
|
||||||
|
|
||||||
#---------------------------------------------------------------------
|
#---------------------------------------------------------------------
|
||||||
@ -264,9 +217,9 @@ class GrampsParser(handler.ContentHandler):
|
|||||||
#---------------------------------------------------------------------
|
#---------------------------------------------------------------------
|
||||||
def start_mother(self,attrs):
|
def start_mother(self,attrs):
|
||||||
if self.is_import:
|
if self.is_import:
|
||||||
mother = self.database.findPerson("x%s" % attrs["ref"],self.pmap)
|
mother = self.db.findPerson("x%s" % attrs["ref"],self.pmap)
|
||||||
else:
|
else:
|
||||||
mother = self.database.findPersonNoMap(attrs["ref"])
|
mother = self.db.findPersonNoMap(attrs["ref"])
|
||||||
self.family.setMother(mother)
|
self.family.setMother(mother)
|
||||||
|
|
||||||
#---------------------------------------------------------------------
|
#---------------------------------------------------------------------
|
||||||
@ -276,9 +229,9 @@ class GrampsParser(handler.ContentHandler):
|
|||||||
#---------------------------------------------------------------------
|
#---------------------------------------------------------------------
|
||||||
def start_child(self,attrs):
|
def start_child(self,attrs):
|
||||||
if self.is_import:
|
if self.is_import:
|
||||||
child = self.database.findPerson("x%s" % attrs["ref"],self.pmap)
|
child = self.db.findPerson("x%s" % attrs["ref"],self.pmap)
|
||||||
else:
|
else:
|
||||||
child = self.database.findPersonNoMap(attrs["ref"])
|
child = self.db.findPersonNoMap(attrs["ref"])
|
||||||
self.family.addChild(child)
|
self.family.addChild(child)
|
||||||
|
|
||||||
#---------------------------------------------------------------------
|
#---------------------------------------------------------------------
|
||||||
@ -311,9 +264,9 @@ class GrampsParser(handler.ContentHandler):
|
|||||||
self.callback(float(self.count)/float(self.entries))
|
self.callback(float(self.count)/float(self.entries))
|
||||||
self.count = self.count + 1
|
self.count = self.count + 1
|
||||||
if self.is_import:
|
if self.is_import:
|
||||||
self.family = self.database.findFamily(attrs["id"],self.fmap)
|
self.family = self.db.findFamily(attrs["id"],self.fmap)
|
||||||
else:
|
else:
|
||||||
self.family = self.database.findFamilyNoMap(attrs["id"])
|
self.family = self.db.findFamilyNoMap(attrs["id"])
|
||||||
|
|
||||||
#---------------------------------------------------------------------
|
#---------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -322,9 +275,9 @@ class GrampsParser(handler.ContentHandler):
|
|||||||
#---------------------------------------------------------------------
|
#---------------------------------------------------------------------
|
||||||
def start_childof(self,attrs):
|
def start_childof(self,attrs):
|
||||||
if self.is_import:
|
if self.is_import:
|
||||||
family = self.database.findFamily(attrs["ref"],self.fmap)
|
family = self.db.findFamily(attrs["ref"],self.fmap)
|
||||||
else:
|
else:
|
||||||
family = self.database.findFamilyNoMap(attrs["ref"])
|
family = self.db.findFamilyNoMap(attrs["ref"])
|
||||||
if attrs.has_key("type"):
|
if attrs.has_key("type"):
|
||||||
type = attrs["type"]
|
type = attrs["type"]
|
||||||
self.person.addAltFamily(family,type)
|
self.person.addAltFamily(family,type)
|
||||||
@ -338,9 +291,9 @@ class GrampsParser(handler.ContentHandler):
|
|||||||
#---------------------------------------------------------------------
|
#---------------------------------------------------------------------
|
||||||
def start_parentin(self,attrs):
|
def start_parentin(self,attrs):
|
||||||
if self.is_import:
|
if self.is_import:
|
||||||
family = self.database.findFamily(attrs["ref"],self.fmap)
|
family = self.db.findFamily(attrs["ref"],self.fmap)
|
||||||
else:
|
else:
|
||||||
family = self.database.findFamilyNoMap(attrs["ref"])
|
family = self.db.findFamilyNoMap(attrs["ref"])
|
||||||
self.person.addFamily(family)
|
self.person.addFamily(family)
|
||||||
|
|
||||||
#---------------------------------------------------------------------
|
#---------------------------------------------------------------------
|
||||||
@ -387,9 +340,9 @@ class GrampsParser(handler.ContentHandler):
|
|||||||
def start_sourceref(self,attrs):
|
def start_sourceref(self,attrs):
|
||||||
self.source = Source()
|
self.source = Source()
|
||||||
if self.is_import:
|
if self.is_import:
|
||||||
self.sourceRef = self.database.findSource(attrs["ref"],self.smap)
|
self.sourceRef = self.db.findSource(attrs["ref"],self.smap)
|
||||||
else:
|
else:
|
||||||
self.sourceRef = self.database.findSourceNoMap(attrs["ref"])
|
self.sourceRef = self.db.findSourceNoMap(attrs["ref"])
|
||||||
self.source.setBase(self.sourceRef)
|
self.source.setBase(self.sourceRef)
|
||||||
self.event.setSource(self.source)
|
self.event.setSource(self.source)
|
||||||
|
|
||||||
@ -400,9 +353,9 @@ class GrampsParser(handler.ContentHandler):
|
|||||||
#---------------------------------------------------------------------
|
#---------------------------------------------------------------------
|
||||||
def start_source(self,attrs):
|
def start_source(self,attrs):
|
||||||
if self.is_import:
|
if self.is_import:
|
||||||
self.sourceRef = self.database.findSource(attrs["id"],self.smap)
|
self.sourceRef = self.db.findSource(attrs["id"],self.smap)
|
||||||
else:
|
else:
|
||||||
self.sourceRef = self.database.findSourceNoMap(attrs["id"])
|
self.sourceRef = self.db.findSourceNoMap(attrs["id"])
|
||||||
|
|
||||||
#---------------------------------------------------------------------
|
#---------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -415,7 +368,7 @@ class GrampsParser(handler.ContentHandler):
|
|||||||
photo.setDescription(attrs["descrip"])
|
photo.setDescription(attrs["descrip"])
|
||||||
src = attrs["src"]
|
src = attrs["src"]
|
||||||
if src[0] != os.sep:
|
if src[0] != os.sep:
|
||||||
photo.setPath(self.base + os.sep + attrs["src"])
|
photo.setPath("%s%s%s" % (self.base,os.sep,src))
|
||||||
photo.setPrivate(1)
|
photo.setPrivate(1)
|
||||||
else:
|
else:
|
||||||
photo.setPath(src)
|
photo.setPath(src)
|
||||||
@ -493,7 +446,7 @@ class GrampsParser(handler.ContentHandler):
|
|||||||
#
|
#
|
||||||
#---------------------------------------------------------------------
|
#---------------------------------------------------------------------
|
||||||
def stop_date(self,tag):
|
def stop_date(self,tag):
|
||||||
if tag != "":
|
if tag:
|
||||||
self.event.getDateObj().quick_set(tag)
|
self.event.getDateObj().quick_set(tag)
|
||||||
|
|
||||||
#---------------------------------------------------------------------
|
#---------------------------------------------------------------------
|
||||||
@ -662,26 +615,73 @@ class GrampsParser(handler.ContentHandler):
|
|||||||
#
|
#
|
||||||
#
|
#
|
||||||
#---------------------------------------------------------------------
|
#---------------------------------------------------------------------
|
||||||
def get_val(self,tag):
|
def stop_research(self,tag):
|
||||||
if self.data.has_key(tag):
|
self.owner.set(self.resname, self.resaddr, self.rescity, self.resstate,
|
||||||
return self.data[tag]
|
self.rescon, self.respos, self.resphone, self.resemail)
|
||||||
else:
|
|
||||||
return ""
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------
|
#---------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#---------------------------------------------------------------------
|
#---------------------------------------------------------------------
|
||||||
def stop_research(self,tag):
|
def stop_resname(self,tag):
|
||||||
self.owner.set(self.get_val(GrampsParser.resnameTag), \
|
self.resname = tag
|
||||||
self.get_val(GrampsParser.resaddrTag), \
|
|
||||||
self.get_val(GrampsParser.rescityTag), \
|
#---------------------------------------------------------------------
|
||||||
self.get_val(GrampsParser.resstateTag), \
|
#
|
||||||
self.get_val(GrampsParser.resconTag), \
|
#
|
||||||
self.get_val(GrampsParser.resposTag),\
|
#
|
||||||
self.get_val(GrampsParser.resphoneTag),\
|
#---------------------------------------------------------------------
|
||||||
self.get_val(GrampsParser.resemailTag))
|
def stop_resaddr(self,tag):
|
||||||
|
self.resaddr = tag
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#---------------------------------------------------------------------
|
||||||
|
def stop_rescity(self,tag):
|
||||||
|
self.rescity = tag
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#---------------------------------------------------------------------
|
||||||
|
def stop_resstate(self,tag):
|
||||||
|
self.resstate = tag
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#---------------------------------------------------------------------
|
||||||
|
def stop_rescountry(self,tag):
|
||||||
|
self.rescon = tag
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#---------------------------------------------------------------------
|
||||||
|
def stop_respostal(self,tag):
|
||||||
|
self.respos = tag
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#---------------------------------------------------------------------
|
||||||
|
def stop_resphone(self,tag):
|
||||||
|
self.resphone = tag
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#---------------------------------------------------------------------
|
||||||
|
def stop_resemail(self,tag):
|
||||||
|
self.resemail = tag
|
||||||
|
|
||||||
#---------------------------------------------------------------------
|
#---------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -704,62 +704,69 @@ class GrampsParser(handler.ContentHandler):
|
|||||||
def stop_aka(self,tag):
|
def stop_aka(self,tag):
|
||||||
self.person.addAlternateName(self.name)
|
self.person.addAlternateName(self.name)
|
||||||
|
|
||||||
stop = { eventTag : stop_event,
|
func_map = {
|
||||||
attrTag : stop_attribute,
|
"address" : (start_address, None),
|
||||||
nameTag : stop_name,
|
"aka" : (start_name, stop_aka),
|
||||||
placeTag : stop_place,
|
"attribute" : (start_attribute, stop_attribute),
|
||||||
dateTag : stop_date,
|
"bookmark" : (start_bmark, None),
|
||||||
firstTag : stop_first,
|
"bookmarks" : (None, None),
|
||||||
lastTag : stop_last,
|
"child" : (start_child,None),
|
||||||
titleTag : stop_title,
|
"childof" : (start_childof,None),
|
||||||
nickTag : stop_nick,
|
"childlist" : (None,None),
|
||||||
suffixTag : stop_suffix,
|
"city" : (None, stop_city),
|
||||||
noteTag : stop_note,
|
"country" : (None, stop_country),
|
||||||
uidTag : stop_uid,
|
"created" : (start_created, None),
|
||||||
stopTag : stop_date_stop,
|
"database" : (None, None),
|
||||||
startTag : stop_date_start,
|
"date" : (None, stop_date),
|
||||||
streetTag : stop_street,
|
"description": (None, stop_description),
|
||||||
cityTag : stop_city,
|
"event" : (start_event, stop_event),
|
||||||
stateTag : stop_state,
|
"families" : (start_families, None),
|
||||||
countryTag : stop_country,
|
"family" : (start_family, None),
|
||||||
postalTag : stop_postal,
|
"father" : (start_father, None),
|
||||||
researchTag : stop_research,
|
"first" : (None, stop_first),
|
||||||
descriptionTag : stop_description,
|
"gender" : (None, stop_gender),
|
||||||
genderTag : stop_gender,
|
"header" : (None, None),
|
||||||
stitleTag : stop_stitle,
|
"last" : (None, stop_last),
|
||||||
sauthorTag : stop_sauthor,
|
"mother" : (start_mother,None),
|
||||||
sdateTag: stop_sdate,
|
"name" : (start_name, stop_name),
|
||||||
spageTag : stop_spage,
|
"nick" : (None, stop_nick),
|
||||||
spubinfoTag : stop_spubinfo,
|
"note" : (start_note, stop_note),
|
||||||
scallnoTag : stop_scallno,
|
"p" : (None, stop_ptag),
|
||||||
stextTag : stop_stext,
|
"parentin" : (start_parentin,None),
|
||||||
pTag : stop_ptag,
|
"people" : (start_people, None),
|
||||||
akaTag : stop_aka,
|
"person" : (start_person, None),
|
||||||
scommentsTag : stop_scomments
|
"img" : (start_photo, None),
|
||||||
}
|
"place" : (None, stop_place),
|
||||||
|
"postal" : (None, stop_postal),
|
||||||
start = { eventTag : start_event ,
|
"researcher" : (None, stop_research),
|
||||||
attrTag : start_attribute,
|
"resname" : (None, stop_resname ),
|
||||||
bmarkTag : start_bmark,
|
"resaddr" : (None, stop_resaddr ),
|
||||||
urlTag : start_url,
|
"rescity" : (None, stop_rescity ),
|
||||||
personTag : start_person,
|
"resstate" : (None, stop_resstate ),
|
||||||
addressTag : start_address,
|
"rescountry" : (None, stop_rescountry),
|
||||||
peopleTag : start_people,
|
"respostal" : (None, stop_respostal),
|
||||||
fatherTag : start_father,
|
"resphone" : (None, stop_resphone),
|
||||||
noteTag : start_note,
|
"resemail" : (None, stop_resemail),
|
||||||
motherTag : start_mother,
|
"sauthor" : (None, stop_sauthor),
|
||||||
childTag : start_child,
|
"scallno" : (None, stop_scallno),
|
||||||
familyTag : start_family,
|
"scomments" : (None, stop_scomments),
|
||||||
childofTag : start_childof,
|
"sdate" : (None,stop_sdate),
|
||||||
parentinTag : start_parentin,\
|
"source" : (start_source, None),
|
||||||
nameTag : start_name,
|
"sourceref" : (start_sourceref, None),
|
||||||
familiesTag : start_families,
|
"sources" : (start_sources, None),
|
||||||
sourcesTag : start_sources,
|
"spage" : (None, stop_spage),
|
||||||
sourcerefTag : start_sourceref,
|
"spubinfo" : (None, stop_spubinfo),
|
||||||
sourceTag : start_source,
|
"date_start" : (None, stop_date_start),
|
||||||
photoTag : start_photo,
|
"state" : (None, stop_state),
|
||||||
akaTag : start_name,
|
"stext" : (None, stop_stext),
|
||||||
createdTag : start_created }
|
"stitle" : (None, stop_stitle),
|
||||||
|
"date_stop" : (None, stop_date_stop),
|
||||||
|
"street" : (None, stop_street),
|
||||||
|
"suffix" : (None, stop_suffix),
|
||||||
|
"title" : (None, stop_title),
|
||||||
|
"uid" : (None, stop_uid),
|
||||||
|
"url" : (None, start_url)
|
||||||
|
}
|
||||||
|
|
||||||
#---------------------------------------------------------------------
|
#---------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -768,34 +775,47 @@ class GrampsParser(handler.ContentHandler):
|
|||||||
#---------------------------------------------------------------------
|
#---------------------------------------------------------------------
|
||||||
def startElement(self,tag,attrs):
|
def startElement(self,tag,attrs):
|
||||||
|
|
||||||
self.active = tag
|
self.func_list[self.func_index] = (self.func,self.data)
|
||||||
self.data[tag] = ""
|
self.func_index = self.func_index + 1
|
||||||
if GrampsParser.start.has_key(tag):
|
self.data = ""
|
||||||
GrampsParser.start[tag](self,attrs)
|
|
||||||
|
try:
|
||||||
|
f,self.func = GrampsParser.func_map[tag]
|
||||||
|
if f:
|
||||||
|
f(self,attrs)
|
||||||
|
except:
|
||||||
|
GrampsParser.func_map[tag] = (None,None)
|
||||||
|
print tag
|
||||||
|
self.func = None
|
||||||
|
|
||||||
#---------------------------------------------------------------------
|
#---------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#---------------------------------------------------------------------
|
#---------------------------------------------------------------------
|
||||||
def endElement(self,tag):
|
|
||||||
|
|
||||||
if GrampsParser.stop.has_key(tag):
|
|
||||||
if sax == 1:
|
|
||||||
data = utf8_to_latin(self.data[tag])
|
|
||||||
else:
|
|
||||||
data = self.data[tag]
|
|
||||||
GrampsParser.stop[tag](self,data)
|
|
||||||
|
|
||||||
if sax == 1:
|
if sax == 1:
|
||||||
def characters(self, data, offset, length):
|
|
||||||
self.data[self.active] = self.data[self.active] + data
|
|
||||||
else:
|
|
||||||
def characters(self, data):
|
|
||||||
self.data[self.active] = self.data[self.active] + data
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------
|
def endElement(self,tag):
|
||||||
#
|
|
||||||
#
|
if self.func:
|
||||||
#
|
self.func(self,utf8_to_latin(self.data))
|
||||||
#---------------------------------------------------------------------
|
self.func_index = self.func_index - 1
|
||||||
|
self.func,self.data = self.func_list[self.func_index]
|
||||||
|
|
||||||
|
def characters(self, data, offset, length):
|
||||||
|
if self.func:
|
||||||
|
self.data = self.data + data
|
||||||
|
else:
|
||||||
|
|
||||||
|
def endElement(self,tag):
|
||||||
|
|
||||||
|
if self.func:
|
||||||
|
self.func(self,self.data)
|
||||||
|
self.func_index = self.func_index - 1
|
||||||
|
self.func,self.data = self.func_list[self.func_index]
|
||||||
|
|
||||||
|
def characters(self, data):
|
||||||
|
if self.func:
|
||||||
|
self.data = self.data + data
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,8 +25,8 @@ import intl
|
|||||||
_ = intl.gettext
|
_ = intl.gettext
|
||||||
|
|
||||||
paper_sizes = [
|
paper_sizes = [
|
||||||
TextDoc.PaperStyle("US Letter",27.94,21.59),
|
TextDoc.PaperStyle("Letter",27.94,21.59),
|
||||||
TextDoc.PaperStyle("US Legal",35.56,21.59),
|
TextDoc.PaperStyle("Legal",35.56,21.59),
|
||||||
TextDoc.PaperStyle("A3",42.0,29.7),
|
TextDoc.PaperStyle("A3",42.0,29.7),
|
||||||
TextDoc.PaperStyle("A4",29.7,21.0),
|
TextDoc.PaperStyle("A4",29.7,21.0),
|
||||||
TextDoc.PaperStyle("A5",21.0,14.8),
|
TextDoc.PaperStyle("A5",21.0,14.8),
|
||||||
|
@ -337,6 +337,7 @@ class TextDoc:
|
|||||||
else:
|
else:
|
||||||
self.width = type.get_height()
|
self.width = type.get_height()
|
||||||
self.height = type.get_width()
|
self.height = type.get_width()
|
||||||
|
self.paper = type
|
||||||
self.tmargin = 2.54
|
self.tmargin = 2.54
|
||||||
self.bmargin = 2.54
|
self.bmargin = 2.54
|
||||||
self.lmargin = 2.54
|
self.lmargin = 2.54
|
||||||
|
@ -103,8 +103,8 @@ def importData(database, filename):
|
|||||||
noteactRegexp= re.compile(r"\s*1\s+NOTE\s+(.+)*")
|
noteactRegexp= re.compile(r"\s*1\s+NOTE\s+(.+)*")
|
||||||
refnRegexp = re.compile(r"\s*1\s+REFN")
|
refnRegexp = re.compile(r"\s*1\s+REFN")
|
||||||
noteRegexp = re.compile(r"\s*0\s+@(.+)@\s+NOTE\s*(.*)?$")
|
noteRegexp = re.compile(r"\s*0\s+@(.+)@\s+NOTE\s*(.*)?$")
|
||||||
concRegexp = re.compile(r"\s*1\s+CONC\s(.*)?$")
|
concRegexp = re.compile(r"\s*\d\s+CONC\s(.*)?$")
|
||||||
contRegexp = re.compile(r"\s*1\s+CONT\s(.*)?$")
|
contRegexp = re.compile(r"\s*\d\s+CONT\s(.*)?$")
|
||||||
deathRegexp = re.compile(r"\s*1\s+DEAT\s*(.*)?$")
|
deathRegexp = re.compile(r"\s*1\s+DEAT\s*(.*)?$")
|
||||||
divorceRegexp= re.compile(r"\s*1\s+DIV\s*(.*)?$")
|
divorceRegexp= re.compile(r"\s*1\s+DIV\s*(.*)?$")
|
||||||
marriedRegexp= re.compile(r"\s*1\s+MAR\s*(.*)?$")
|
marriedRegexp= re.compile(r"\s*1\s+MAR\s*(.*)?$")
|
||||||
@ -405,7 +405,6 @@ def importData(database, filename):
|
|||||||
regex_match = noterefRegexp.match(line)
|
regex_match = noterefRegexp.match(line)
|
||||||
if regex_match :
|
if regex_match :
|
||||||
matches = regex_match.groups()
|
matches = regex_match.groups()
|
||||||
print "found note",matches[0]
|
|
||||||
person2note[person] = matches[0]
|
person2note[person] = matches[0]
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user