2006-06-05 Don Allingham <don@gramps-project.org>

* src/GrampsDb/_ReadGedcom.py: more improvements



svn: r6865
This commit is contained in:
Don Allingham 2006-06-06 04:23:04 +00:00
parent dd9c1a46ad
commit 4e5ff5a16a
3 changed files with 273 additions and 177 deletions

View File

@ -1,3 +1,6 @@
2006-06-05 Don Allingham <don@gramps-project.org>
* src/GrampsDb/_ReadGedcom.py: more improvements
2006-06-05 Alex Roitman <shura@gramps-project.org> 2006-06-05 Alex Roitman <shura@gramps-project.org>
* src/plugins/BookReport.py (BookReportDialog.__init__): Correctly * src/plugins/BookReport.py (BookReportDialog.__init__): Correctly
close managed window. close managed window.

11
NEWS
View File

@ -1,4 +1,10 @@
Verison 2.1.4 Version 2.1.5
* Table of Contents generation added to several reports and formats (Brian)
* Filter Editor enhanced and working for Person filters (Don)
* Report modules restructured (Alex)
* Bug fixes
Version 2.1.4
* Enhanced Verify tool (Alex) * Enhanced Verify tool (Alex)
* Start of index generation for some reports in Open Document files (Brian) * Start of index generation for some reports in Open Document files (Brian)
* Report enhancements (Brian) * Report enhancements (Brian)
@ -6,8 +12,7 @@ Verison 2.1.4
* Shading option to highlight data in Relationship View (Don) * Shading option to highlight data in Relationship View (Don)
* Bug fixes. * Bug fixes.
Version 2.1.3
Verison 2.1.3
* Add user defined custom types to appropriate menus * Add user defined custom types to appropriate menus
* Select Place dialog replaces text entry of places * Select Place dialog replaces text entry of places
* Icon improvements * Icon improvements

View File

@ -128,14 +128,6 @@ _TYPE_BIRTH = RelLib.ChildRefType()
_TYPE_ADOPT = RelLib.ChildRefType(RelLib.ChildRefType.ADOPTED) _TYPE_ADOPT = RelLib.ChildRefType(RelLib.ChildRefType.ADOPTED)
_TYPE_FOSTER = RelLib.ChildRefType(RelLib.ChildRefType.FOSTER) _TYPE_FOSTER = RelLib.ChildRefType(RelLib.ChildRefType.FOSTER)
file_systems = {
'VFAT' : _('Windows 9x file system'),
'FAT' : _('Windows 9x file system'),
"NTFS" : _('Windows NT file system'),
"ISO9660" : _('CD ROM'),
"SMBFS" : _('Networked Windows file system')
}
rel_types = (RelLib.ChildRefType.BIRTH, rel_types = (RelLib.ChildRefType.BIRTH,
RelLib.ChildRefType.UNKNOWN, RelLib.ChildRefType.UNKNOWN,
RelLib.ChildRefType.NONE, RelLib.ChildRefType.NONE,
@ -616,6 +608,39 @@ class GedcomParser(UpdateCallback):
TOKEN__TODO : self.skip_record, TOKEN__TODO : self.skip_record,
} }
self.person_attr = {
TOKEN_TYPE : self.func_person_attr_type,
TOKEN_CAUS : self.func_person_attr_ignore,
TOKEN_DATE : self.func_person_attr_ignore,
TOKEN_TIME : self.func_person_attr_ignore,
TOKEN_ADDR : self.func_person_attr_ignore,
TOKEN_IGNORE: self.func_person_attr_ignore,
TOKEN_STAT : self.func_person_attr_ignore,
TOKEN_TEMP : self.func_person_attr_ignore,
TOKEN_OBJE : self.func_person_attr_ignore,
TOKEN_DATE : self.func_person_attr_ignore,
TOKEN_SOUR : self.func_person_attr_source,
TOKEN_PLAC : self.func_person_attr_place,
TOKEN_NOTE : self.func_person_attr_note,
}
self.family_func = {
TOKEN_HUSB : self.func_family_husb,
TOKEN_WIFE : self.func_family_wife,
TOKEN_SLGS : self.func_family_slgs,
TOKEN_ADDR : self.func_family_addr,
TOKEN_CHIL : self.func_family_chil,
TOKEN_NCHI : self.func_family_nchil,
TOKEN_SOUR : self.func_family_source,
TOKEN_RIN : self.func_family_ignore,
TOKEN_SUBM : self.func_family_ignore,
TOKEN_REFN : self.func_family_ignore,
TOKEN_CHAN : self.func_family_ignore,
TOKEN_OBJE : self.func_family_object,
TOKEN__COMM : self.func_family_comm,
TOKEN_NOTE : self.func_family_note,
}
self.place_names = set() self.place_names = set()
cursor = dbase.get_place_cursor() cursor = dbase.get_place_cursor()
data = cursor.next() data = cursor.next()
@ -864,32 +889,7 @@ class GedcomParser(UpdateCallback):
while True: while True:
matches = self.get_next() matches = self.get_next()
if matches[2] == "FAM": if matches[2] == "FAM":
self.fam_count = self.fam_count + 1 self.parse_FAM(matches)
self.family = self.find_or_create_family(matches[3][1:-1])
self.parse_family()
if self.addr != None:
father_handle = self.family.get_father_handle()
father = self.db.get_person_from_handle(father_handle)
if father:
father.add_address(self.addr)
self.db.commit_person(father, self.trans)
mother_handle = self.family.get_mother_handle()
mother = self.db.get_person_from_handle(mother_handle)
if mother:
mother.add_address(self.addr)
self.db.commit_person(mother, self.trans)
for child_ref in self.family.get_child_ref_list():
child_handle = child_ref.ref
child = self.db.get_person_from_handle(child_handle)
if child:
child.add_address(self.addr)
self.db.commit_person(child, self.trans)
if len(self.family.get_source_references()) == 0:
sref = RelLib.SourceRef()
sref.set_reference_handle(self.def_src.handle)
self.family.add_source_reference(sref)
self.db.commit_family(self.family, self.trans)
del self.family
elif matches[2] == "INDI": elif matches[2] == "INDI":
self.parse_INDI(matches) self.parse_INDI(matches)
elif matches[2] == "REPO": elif matches[2] == "REPO":
@ -1130,35 +1130,81 @@ class GedcomParser(UpdateCallback):
self.barf(level+1) self.barf(level+1)
return None return None
def parse_FAM(self, matches):
# create a family
self.fam_count = self.fam_count + 1
self.family = self.find_or_create_family(matches[3][1:-1])
# parse the family
self.parse_family()
# handle addresses attached to families
if self.addr != None:
father_handle = self.family.get_father_handle()
father = self.db.get_person_from_handle(father_handle)
if father:
father.add_address(self.addr)
self.db.commit_person(father, self.trans)
mother_handle = self.family.get_mother_handle()
mother = self.db.get_person_from_handle(mother_handle)
if mother:
mother.add_address(self.addr)
self.db.commit_person(mother, self.trans)
for child_ref in self.family.get_child_ref_list():
child_handle = child_ref.ref
child = self.db.get_person_from_handle(child_handle)
if child:
child.add_address(self.addr)
self.db.commit_person(child, self.trans)
# add default reference if no reference exists
if len(self.family.get_source_references()) == 0:
sref = RelLib.SourceRef()
sref.set_reference_handle(self.def_src.handle)
self.family.add_source_reference(sref)
# commit family to database
self.db.commit_family(self.family, self.trans)
del self.family
def parse_family(self): def parse_family(self):
self.addr = None self.addr = None
note = "" note = ""
while True: while True:
matches = self.get_next() matches = self.get_next()
if int(matches[0]) < 1: if self.level_is_finished(matches, 1):
self.backup() break
return else:
elif matches[1] == TOKEN_HUSB: func = self.family_func.get(matches[1], self.func_family_event)
func(self.family, matches, 2)
def func_family_husb(self, family, matches, level):
gid = matches[2] gid = matches[2]
handle = self.find_person_handle(self.map_gid(gid[1:-1])) handle = self.find_person_handle(self.map_gid(gid[1:-1]))
self.family.set_father_handle(handle) self.family.set_father_handle(handle)
self.ignore_sub_junk(2) self.ignore_sub_junk(2)
elif matches[1] == TOKEN_WIFE:
def func_family_wife(self, family, matches, level):
gid = matches[2] gid = matches[2]
handle = self.find_person_handle(self.map_gid(gid[1:-1])) handle = self.find_person_handle(self.map_gid(gid[1:-1]))
self.family.set_mother_handle(handle) self.family.set_mother_handle(handle)
self.ignore_sub_junk(2) self.ignore_sub_junk(2)
elif matches[1] == TOKEN_SLGS:
def func_family_slgs(self, family, matches, level):
lds_ord = RelLib.LdsOrd() lds_ord = RelLib.LdsOrd()
lds_ord.set_type(RelLib.LdsOrd.SEAL_TO_SPOUSE) lds_ord.set_type(RelLib.LdsOrd.SEAL_TO_SPOUSE)
self.family.lds_ord_list.append(lds_ord) self.family.lds_ord_list.append(lds_ord)
self.parse_ord(lds_ord,2) self.parse_ord(lds_ord,2)
elif matches[1] == TOKEN_ADDR:
def func_family_addr(self, family, matches, level):
self.addr = RelLib.Address() self.addr = RelLib.Address()
self.addr.set_street(matches[2]) self.addr.set_street(matches[2])
self.parse_address(self.addr,2) self.parse_address(self.addr,2)
elif matches[1] == TOKEN_CHIL:
def func_family_chil(self, family, matches, level):
mrel,frel = self.parse_ftw_relations(2) mrel,frel = self.parse_ftw_relations(2)
gid = matches[2] gid = matches[2]
child = self.find_or_create_person(self.map_gid(gid[1:-1])) child = self.find_or_create_person(self.map_gid(gid[1:-1]))
@ -1168,28 +1214,35 @@ class GedcomParser(UpdateCallback):
ref.set_father_relation(frel) ref.set_father_relation(frel)
ref.set_mother_relation(mrel) ref.set_mother_relation(mrel)
self.family.add_child_ref(ref) self.family.add_child_ref(ref)
elif matches[1] == TOKEN_NCHI:
def func_family_nchil(self, family, matches, level):
a = RelLib.Attribute() a = RelLib.Attribute()
a.set_type(RelLib.AttributeType.NUM_CHILD) a.set_type(RelLib.AttributeType.NUM_CHILD)
a.set_value(matches[2]) a.set_value(matches[2])
self.family.add_attribute(a) self.family.add_attribute(a)
elif matches[1] == TOKEN_SOUR:
def func_family_source(self, family, matches, level):
source_ref = self.handle_source(matches,2) source_ref = self.handle_source(matches,2)
self.family.add_source_reference(source_ref) self.family.add_source_reference(source_ref)
elif matches[1] in (TOKEN_RIN, TOKEN_SUBM, TOKEN_REFN,TOKEN_CHAN):
def func_family_ignore(self, family, matches, level):
self.ignore_sub_junk(2) self.ignore_sub_junk(2)
elif matches[1] == TOKEN_OBJE:
def func_family_object(self, family, matches, level):
if matches[2] and matches[2][0] == '@': if matches[2] and matches[2][0] == '@':
self.barf(2) self.barf(2)
else: else:
self.parse_family_object(2) self.parse_family_object(2)
elif matches[1] == TOKEN__COMM:
def func_family_comm(self, family, matches, level):
note = matches[2] note = matches[2]
self.family.set_note(note) self.family.set_note(note)
self.ignore_sub_junk(2) self.ignore_sub_junk(2)
elif matches[1] == TOKEN_NOTE:
note = self.parse_note(matches,self.family,1,note) def func_family_note(self, family, matches, level):
else: self.parse_note(matches, self.family, 1, '')
def func_family_event(self, family, matches, level):
event = RelLib.Event() event = RelLib.Event()
event.set_gramps_id(self.emapper.find_next()) event.set_gramps_id(self.emapper.find_next())
try: try:
@ -1203,8 +1256,10 @@ class GedcomParser(UpdateCallback):
matches[3])) matches[3]))
else: else:
event.set_type(RelLib.EventType.UNKNOWN) event.set_type(RelLib.EventType.UNKNOWN)
if matches[2] and not event.get_description(): if matches[2] and not event.get_description():
event.set_description(matches[2]) event.set_description(matches[2])
self.parse_family_event(event,2) self.parse_family_event(event,2)
if int(event.get_type()) == RelLib.EventType.MARRIAGE: if int(event.get_type()) == RelLib.EventType.MARRIAGE:
self.family.type.set(RelLib.FamilyRelType.MARRIED) self.family.type.set(RelLib.FamilyRelType.MARRIED)
@ -1255,10 +1310,38 @@ class GedcomParser(UpdateCallback):
""" """
return value[1:-1] return value[1:-1]
#----------------------------------------------------------------------
#
# INDI parsing
#
#----------------------------------------------------------------------
def parse_INDI(self, matches): def parse_INDI(self, matches):
""" """
Handling of the GEDCOM INDI tag. The maintenence stuff is handled here, Handling of the GEDCOM INDI tag.
which that actual parsing is done by self.parse_individual
n @XREF:INDI@ INDI {1:1}
+1 RESN <RESTRICTION_NOTICE> {0:1}
+1 <<PERSONAL_NAME_STRUCTURE>> {0:M}
+1 SEX <SEX_VALUE> {0:1}
+1 <<INDIVIDUAL_EVENT_STRUCTURE>> {0:M}
+1 <<INDIVIDUAL_ATTRIBUTE_STRUCTURE>> {0:M}
+1 <<LDS_INDIVIDUAL_ORDINANCE>> {0:M}
+1 <<CHILD_TO_FAMILY_LINK>> {0:M}
+1 <<SPOUSE_TO_FAMILY_LINK>> {0:M}
+1 SUBM @<XREF:SUBM>@ {0:M}
+1 <<ASSOCIATION_STRUCTURE>> {0:M}
+1 ALIA @<XREF:INDI>@ {0:M}
+1 ANCI @<XREF:SUBM>@ {0:M}
+1 DESI @<XREF:SUBM>@ {0:M}
+1 <<SOURCE_CITATION>> {0:M}
+1 <<MULTIMEDIA_LINK>> {0:M}
+1 <<NOTE_STRUCTURE>> {0:M}
+1 RFN <PERMANENT_RECORD_FILE_NUMBER> {0:1}
+1 AFN <ANCESTRAL_FILE_NUMBER> {0:1}
+1 REFN <USER_REFERENCE_NUMBER> {0:M}
+2 TYPE <USER_REFERENCE_TYPE> {0:1}
+1 RIN <AUTOMATED_RECORD_ID> {0:1}
+1 <<CHANGE_DATE>> {0:1}
""" """
# find the person # find the person
@ -1268,26 +1351,9 @@ class GedcomParser(UpdateCallback):
self.added.add(self.person.handle) self.added.add(self.person.handle)
# do the actual parsing # do the actual parsing
self.parse_individual(self.person)
# Add the default reference if no source has found
if len(self.person.get_source_references()) == 0:
sref = RelLib.SourceRef()
sref.set_reference_handle(self.def_src.handle)
self.person.add_source_reference(sref)
# commit the person to the database
self.db.commit_person(self.person, self.trans)
del self.person
def parse_individual(self,person):
"""
Parse the individual. When we are no longer handling level 1,
then we are finished parsing this level.
"""
state = CurrentState() state = CurrentState()
state.person = person state.person = self.person
state.level = 1 state.level = 1
while True: while True:
@ -1301,6 +1367,17 @@ class GedcomParser(UpdateCallback):
func = self.person_func.get(matches[1], self.func_person_event) func = self.person_func.get(matches[1], self.func_person_event)
func(matches, state) func(matches, state)
# Add the default reference if no source has found
if len(self.person.get_source_references()) == 0:
sref = RelLib.SourceRef()
sref.set_reference_handle(self.def_src.handle)
self.person.add_source_reference(sref)
# commit the person to the database
self.db.commit_person(self.person, self.trans)
del self.person
def parse_optional_note(self,level): def parse_optional_note(self,level):
note = "" note = ""
while True: while True:
@ -1559,7 +1636,8 @@ class GedcomParser(UpdateCallback):
def func_person_event_place(self, matches, event, level): def func_person_event_place(self, matches, event, level):
val = matches[2] val = matches[2]
n = event.get_type() n = event.get_type()
if self.is_ftw and int(n) in [RelLib.EventType.OCCUPATION,RelLib.EventType.DEGREE]: if self.is_ftw and int(n) in [RelLib.EventType.OCCUPATION,
RelLib.EventType.DEGREE]:
event.set_description(val) event.set_description(val)
else: else:
place = self.find_or_create_place(val) place = self.find_or_create_place(val)
@ -1592,14 +1670,33 @@ class GedcomParser(UpdateCallback):
def parse_person_attr(self,attr,level): def parse_person_attr(self,attr,level):
""" """
GRAMPS uses an Attribute to store some information. Technically,
GEDCOM does not make a distinction between Attributes and Events,
so what GRAMPS considers to be an Attribute can have more information
than what we allow.
""" """
note = ""
while True: while True:
matches = self.get_next() matches = self.get_next()
if self.level_is_finished(matches,level): if self.level_is_finished(matches,level):
break break
elif matches[1] == TOKEN_TYPE: else:
func = self.person_attr.get(matches[1],
self.func_person_attr_undef)
func(matches, event, level+1)
def func_person_attr_undef(self, attr, matches, level):
"""
Called when an undefined token is found
"""
self.barf(level)
def func_person_attr_ignore(self, attr, matches, level):
"""
Called when an attribute is found that we know we want to ignore
"""
self.ignore_sub_junk(level)
def func_person_attr_type(self, attr, matches, level):
if attr.get_type() == "": if attr.get_type() == "":
if ged2gramps.has_key(matches[2]): if ged2gramps.has_key(matches[2]):
name = ged2gramps[matches[2]] name = ged2gramps[matches[2]]
@ -1610,28 +1707,19 @@ class GedcomParser(UpdateCallback):
else: else:
name = matches[2] name = matches[2]
attr.set_type(name) attr.set_type(name)
elif matches[1] in (TOKEN_CAUS,TOKEN_DATE,TOKEN_TIME,TOKEN_ADDR,
TOKEN_IGNORE,TOKEN_STAT,TOKEN_TEMP,TOKEN_OBJE): def func_person_attr_source(self, attr, matches, level):
self.ignore_sub_junk(level+1) attr.add_source_reference(self.handle_source(matches,level))
elif matches[1] == TOKEN_SOUR:
attr.add_source_reference(self.handle_source(matches,level+1)) def func_person_attr_place(self, attr, matches, level):
elif matches[1] == TOKEN_PLAC:
val = matches[2] val = matches[2]
if attr.get_value() == "": if attr.get_value() == "":
attr.set_value(val) attr.set_value(val)
self.ignore_sub_junk(level+1) self.ignore_sub_junk(level)
elif matches[1] == TOKEN_DATE:
note = "%s\n\n" % ("Date : %s" % matches[2]) def func_person_attr_note(self, attr, matches, level):
elif matches[1] == TOKEN_NOTE:
info = self.parse_note(matches,attr,level+1,note) info = self.parse_note(matches,attr,level+1,note)
if note == "": attr.set_note(info)
note = info
else:
note = "%s\n\n%s" % (note,info)
else:
self.barf(level+1)
if note != "":
attr.set_note(note)
def parse_family_event(self,event,level): def parse_family_event(self,event,level):
note = "" note = ""