def parse_marriage(self, fields, idx): mariageDataRe = re.compile("^[+#-0-9].*$") mar_date = None mar_place = None mar_source = None sep_date = None div_date = None married = 1 engaged = 0 # skip to marriage date in case person contained unmatches tokens #Alex: this failed when fields[idx] was an empty line. Fixed. #while idx < len(fields) and not fields[idx][0] == "+": while idx < len(fields) and not (fields[idx] and fields[idx][0] == "+"): if fields[idx]: LOG.warning( ("parse_marriage(): Unknown field: " + "'%s' in line %d!") % (fields[idx], self.lineno)) idx += 1 while idx < len(fields) and mariageDataRe.match(fields[idx]): field = fields[idx] idx += 1 if field.startswith("+"): field = field[1:] mar_date = self.parse_date(self.decode(field)) LOG.debug(" Married at: %s" % field) elif field.startswith("-"): field = field[1:] div_date = self.parse_date(self.decode(field)) LOG.debug(" Div at: %s" % field) elif field == "#mp" and idx < len(fields): mar_place = self.get_or_create_place(self.decode(fields[idx])) LOG.debug(" Marriage place: %s" % fields[idx]) idx += 1 elif field == "#ms" and idx < len(fields): mar_source = self.get_or_create_source(self.decode( fields[idx])) LOG.debug(" Marriage source: %s" % fields[idx]) idx += 1 elif field == "#sep" and idx < len(fields): sep_date = self.parse_date(self.decode(fields[idx])) LOG.debug(" Seperated since: %s" % fields[idx]) idx += 1 elif field == "#nm": LOG.debug(" Are not married.") married = 0 elif field == "#noment": LOG.debug(" Not mentioned.") elif field == "#eng": LOG.debug(" Are engaged.") engaged = 1 else: LOG.warning( ("parse_marriage(): Unknown field " + "'%s'for mariage in line %d!") % (field, self.lineno)) if mar_date or mar_place or mar_source: mar = self.create_event(EventType.MARRIAGE, None, mar_date, mar_place, mar_source) mar_ref = EventRef() mar_ref.set_reference_handle(mar.get_handle()) mar_ref.set_role(EventRoleType.FAMILY) self.current_family.add_event_ref(mar_ref) self.current_family.set_relationship( FamilyRelType(FamilyRelType.MARRIED)) if div_date: div = self.create_event(EventType.DIVORCE, None, div_date, None, None) div_ref = EventRef() div_ref.set_reference_handle(div.get_handle()) div_ref.set_role(EventRoleType.FAMILY) self.current_family.add_event_ref(div_ref) if sep_date or engaged: sep = self.create_event(EventType.ENGAGEMENT, None, sep_date, None, None) sep_ref = EventRef() sep_ref.set_reference_handle(sep.get_handle()) sep_ref.set_role(EventRoleType.FAMILY) self.current_family.add_event_ref(sep_ref) if not married: self.current_family.set_relationship( FamilyRelType(FamilyRelType.UNMARRIED)) self.db.commit_family(self.current_family, self.trans) return idx
def column_type(self, data): return str(FamilyRelType(data[5]))