def read_witness_line(self, line, fields): LOG.debug("Witness:") if fields[1] == "m:": (idx, wit_p) = self.parse_person(fields, 2, Person.MALE, None) elif fields[1] == "f:": (idx, wit_p) = self.parse_person(fields, 2, Person.FEMALE, None) else: (idx, wit_p) = self.parse_person(fields, 1, None, None) if wit_p: mev = None # search marriage event for evr in self.current_family.get_event_ref_list(): ev = self.db.get_event_from_handle(evr.get_reference_handle()) if ev.get_type() == EventType.MARRIAGE: mev = ev # found. if not mev: # No marriage event found create a new one mev = self.create_event(EventType.MARRIAGE, None, None, None, None) mar_ref = EventRef() mar_ref.set_reference_handle(mev.get_handle()) self.current_family.add_event_ref(mar_ref) wit_ref = EventRef() wit_ref.set_role(EventRoleType(EventRoleType.WITNESS)) wit_ref.set_reference_handle(mev.get_handle()) wit_p.add_event_ref(wit_ref) self.db.commit_person(wit_p, self.trans) return None
def new_gwplus_pevent(self, line): source = place = note = type = None date = self.parse_date(self.decode(line[6:])) idx = 0 LOG.info((self.person, line, pevents_map.get(line[0:5]))) type = pevents_map.get(line[0:5]) data = line.split() date = self.parse_date(self.decode(line[6:])) for part in data: idx += 1 if part == "#p": place = self.get_or_create_place(self.decode(data[idx])) if part == "#s": source = self.get_or_create_source(self.decode(data[idx])) self.current_event = self.create_event(type, None, None, None, None) print('new event', self.current_event.handle) if date: print(date) self.current_event.set_date_object(date) if place: print('place', place.handle) self.current_event.set_place_handle(place.get_handle()) if source: print('source', source.handle) self.current_event.add_citation(source.get_handle()) self.db.commit_event(self.current_event, self.trans) nev_ref = EventRef() nev_ref.set_reference_handle(self.current_event.get_handle()) self.current_person.add_event_ref(nev_ref) self.db.commit_person(self.current_person, self.trans) return self.current_event
def save(self, trans): """ Save the census details to the database. """ # Update people on the census all_people = [] for order, row in enumerate(self.model): all_people.append(row[0]) person = self.db.get_person_from_handle(row[0]) event_ref = self.get_census_event_ref(person) if event_ref is None: # Add new link to census event_ref = EventRef() event_ref.ref = self.event.get_handle() event_ref.set_role(EventRoleType.PRIMARY) person.add_event_ref(event_ref) # Write attributes attrs = event_ref.get_attribute_list() set_attribute(event_ref, attrs, ORDER_ATTR, str(order + 1)) for offset, name in enumerate(self.columns): value = row[offset + 1] if name == _('Name'): if value != name_displayer.display(person): set_attribute(event_ref, attrs, name, value) else: set_attribute(event_ref, attrs, name, value) self.db.commit_person(person, trans) # Remove links to people no longer on census for handle in (set(self.initial_people) - set(all_people)): person = self.db.get_person_from_handle(handle) ref_list = [event_ref for event_ref in person.get_event_ref_list() if event_ref.ref != self.event.handle] person.set_event_ref_list(ref_list) self.db.commit_person(person, trans)
def read_children_lines(self): father_surname = "Dummy" if not self.current_husband_handle: LOG.warning("Unknown father for child in line %d!" % self.lineno) return None husb = self.db.get_person_from_handle(self.current_husband_handle) father_surname = husb.get_primary_name().get_surname() if not self.current_family: LOG.warning("Unknown family of child in line %d!" % self.lineno) return None while 1: line = self.get_next_line() if line is None: break if line == "": continue fields = line.split(" ") if fields[0] == "-": LOG.debug("Child:") child = None if fields[1] == "h": (idx, child) = self.parse_person(fields, 2, Person.MALE, father_surname) elif fields[1] == "f": (idx, child) = self.parse_person(fields, 2, Person.FEMALE, father_surname) else: (idx, child) = self.parse_person(fields, 1, Person.UNKNOWN, father_surname) if child: childref = ChildRef() childref.set_reference_handle(child.get_handle()) self.current_family.add_child_ref(childref) self.db.commit_family(self.current_family, self.trans) child.add_parent_family_handle( self.current_family.get_handle()) if self.current_child_birthplace_handle: birth = None birth_ref = child.get_birth_ref() if birth_ref: birth = self.db.get_event_from_handle( birth_ref.ref) if not birth: birth = self.create_event(EventType.BIRTH) birth_ref = EventRef() birth_ref.set_reference_handle(birth.get_handle()) child.set_birth_ref(birth_ref) birth.set_place_handle( self.current_child_birthplace_handle) self.db.commit_event(birth, self.trans) if self.current_child_source_handle: child.add_citation(self.current_child_source_handle) self.db.commit_person(child, self.trans) else: break self.current_mode = None return None
def handle_extra_type(self, objtype, obj): try: ref = EventRef() event = self.dbstate.db.get_event_from_handle(obj) ref.set_role(self.default_role()) self.get_ref_editor()(self.dbstate, self.uistate, self.track, event, ref, self.object_added) except WindowActiveError: pass
def handle_extra_type(self, objtype, obj): try: ref = EventRef() event = self.dbstate.db.get_event_from_handle(obj) ref.set_role(self.default_role()) self.get_ref_editor()( self.dbstate, self.uistate, self.track, event, ref, self.object_added) except WindowActiveError: pass
def add_button_clicked(self, obj): try: ref = EventRef() event = Event() ref.set_role(self.default_role()) event.set_type(self.default_type()) self.get_ref_editor()(self.dbstate, self.uistate, self.track, event, ref, self.object_added) except WindowActiveError: pass
def add_participant(self, *obj): person = Person() ref = EventRef() ref.ref = self.handle person.add_event_ref(ref) try: EditPerson(self.dbstate, self.uistate, [], person) except WindowActiveError: pass
def column_death_place(self, data): index = data[COLUMN_DEATH] if index != -1: try: local = data[COLUMN_EVENT][index] dr = EventRef() dr.unserialize(local) event = self.db.get_event_from_handle(dr.ref) if event: place_title = place_displayer.display_event(self.db, event) if place_title: return escape(place_title) except: return '' for event_ref in data[COLUMN_EVENT]: er = EventRef() er.unserialize(event_ref) event = self.db.get_event_from_handle(er.ref) etype = event.get_type() if (etype in [ EventType.BURIAL, EventType.CREMATION, EventType.CAUSE_DEATH ] and er.get_role() == EventRoleType.PRIMARY): place_title = place_displayer.display_event(self.db, event) if place_title: return "<i>%s</i>" % escape(place_title) return ""
def column_birth_place(self, data): index = data[COLUMN_BIRTH] if index != -1: try: local = data[COLUMN_EVENT][index] br = EventRef() br.unserialize(local) event = self.db.get_event_from_handle(br.ref) if event: place_title = place_displayer.display_event(self.db, event) if place_title: return escape(place_title) except: return '' for event_ref in data[COLUMN_EVENT]: er = EventRef() er.unserialize(event_ref) event = self.db.get_event_from_handle(er.ref) etype = event.get_type() if (etype in [EventType.BAPTISM, EventType.CHRISTEN] and er.get_role() == EventRoleType.PRIMARY): place_title = place_displayer.display_event(self.db, event) if place_title: return "<i>%s</i>" % escape(place_title) return ""
def add_button_clicked(self, obj): try: ref = EventRef() event = Event() ref.set_role(self.default_role()) event.set_type(self.default_type()) self.get_ref_editor()( self.dbstate, self.uistate, self.track, event, ref, self.object_added) except WindowActiveError: pass
def read_children_lines(self): father_surname = "Dummy" if not self.current_husband_handle: LOG.warning("Unknown father for child in line %d!" % self.lineno) return None husb = self.db.get_person_from_handle(self.current_husband_handle) father_surname = husb.get_primary_name().get_surname() if not self.current_family: LOG.warning("Unknown family of child in line %d!" % self.lineno) return None while 1: line = self.get_next_line() if line is None: break if line == "": continue fields = line.split(" ") if fields[0] == "-": LOG.debug("Child:") child = None if fields[1] == "h": (idx,child) = self.parse_person(fields,2,Person.MALE,father_surname) elif fields[1] == "f": (idx,child) = self.parse_person(fields,2,Person.FEMALE,father_surname) else: (idx,child) = self.parse_person(fields,1,Person.UNKNOWN,father_surname) if child: childref = ChildRef() childref.set_reference_handle(child.get_handle()) self.current_family.add_child_ref( childref) self.db.commit_family(self.current_family,self.trans) child.add_parent_family_handle( self.current_family.get_handle()) if self.current_child_birthplace_handle: birth = None birth_ref = child.get_birth_ref() if birth_ref: birth = self.db.get_event_from_handle(birth_ref.ref) if not birth: birth = self.create_event(EventType.BIRTH) birth_ref = EventRef() birth_ref.set_reference_handle(birth.get_handle()) child.set_birth_ref(birth_ref) birth.set_place_handle(self.current_child_birthplace_handle) self.db.commit_event(birth,self.trans) if self.current_child_source_handle: child.add_citation(self.current_child_source_handle) self.db.commit_person(child,self.trans) else: break self.current_mode = None return None
def add_occupation(self, fields, data): """Read the ROLE property of a VCard.""" occupation = data.strip() if occupation: event = Event() event.set_type(EventType(EventType.OCCUPATION)) event.set_description(self.unesc(occupation)) self.database.add_event(event, self.trans) event_ref = EventRef() event_ref.set_reference_handle(event.get_handle()) self.person.add_event_ref(event_ref)
def read_witness_line(self,line,fields): LOG.debug("Witness:") if fields[1] == "m:": (idx,wit_p) = self.parse_person(fields,2,Person.MALE,None) elif fields[1] == "f:": (idx,wit_p) = self.parse_person(fields,2,Person.FEMALE,None) else: (idx,wit_p) = self.parse_person(fields,1,None,None) if wit_p: mev = None # search marriage event for evr in self.current_family.get_event_ref_list(): ev = self.db.get_event_from_handle(evr.get_reference_handle()) if ev.get_type() == EventType.MARRIAGE: mev = ev # found. if not mev: # No marriage event found create a new one mev = self.create_event(EventType.MARRIAGE, None, None, None, None) mar_ref = EventRef() mar_ref.set_reference_handle(mev.get_handle()) self.current_family.add_event_ref(mar_ref) wit_ref = EventRef() wit_ref.set_role(EventRoleType(EventRoleType.WITNESS)) wit_ref.set_reference_handle(mev.get_handle()) wit_p.add_event_ref(wit_ref) self.db.commit_person(wit_p,self.trans) return None
def share_button_clicked(self, obj): SelectEvent = SelectorFactory('Event') sel = SelectEvent(self.dbstate, self.uistate, self.track) event = sel.run() if event: try: ref = EventRef() ref.set_role(self.default_role()) self.get_ref_editor()(self.dbstate, self.uistate, self.track, event, ref, self.object_added) except WindowActiveError: from ...dialog import WarningDialog WarningDialog(_("Cannot share this reference"), self.__blocked_text())
def select_participant(self, *obj): SelectPerson = SelectorFactory('Person') dialog = SelectPerson(self.dbstate, self.uistate) person = dialog.run() if person is None: return ref = EventRef() ref.ref = self.handle person.add_event_ref(ref) try: EditPerson(self.dbstate, self.uistate, [], person) except WindowActiveError: pass
def get_event_ref(event, obj, role): """ Return the event reference for a given person or family that points to the event being edited. """ for event_ref in obj.get_event_ref_list(): if (event_ref.ref == event.get_handle() and event_ref.get_role() == role): return event_ref # Add new event reference event_ref = EventRef() event_ref.ref = event.get_handle() event_ref.set_role(role) obj.add_event_ref(event_ref) return event_ref
def share_button_clicked(self, obj): SelectEvent = SelectorFactory('Event') sel = SelectEvent(self.dbstate, self.uistate, self.track) event = sel.run() if event: try: ref = EventRef() ref.set_role(self.default_role()) self.get_ref_editor()( self.dbstate, self.uistate, self.track, event, ref, self.object_added) except WindowActiveError: from ...dialog import WarningDialog WarningDialog(_("Cannot share this reference"), self.__blocked_text())
def column_death_place(self, data): index = data[COLUMN_DEATH] if index != -1: try: local = data[COLUMN_EVENT][index] dr = EventRef() dr.unserialize(local) event = self.db.get_event_from_handle(dr.ref) if event: place_title = place_displayer.display_event(self.db, event) if place_title: return escape(place_title) except: return '' for event_ref in data[COLUMN_EVENT]: er = EventRef() er.unserialize(event_ref) event = self.db.get_event_from_handle(er.ref) etype = event.get_type() if (etype in [EventType.BURIAL, EventType.CREMATION, EventType.CAUSE_DEATH] and er.get_role() == EventRoleType.PRIMARY): place_title = place_displayer.display_event(self.db, event) if place_title: return "<i>%s</i>" % escape(place_title) return ""
def __add_resi_event(self, person, placename, date_object): pn = PlaceName() pn.set_value(placename) place = Place() place.set_name(pn) placehandle = self.dbstate.db.add_place(place, self.trans) e = Event() e.set_type(EventType.RESIDENCE) e.set_date_object(date_object) e.set_place_handle(placehandle) e.set_description("marriage") eventhandle = self.dbstate.db.add_event(e, self.trans) eref = EventRef() eref.ref = eventhandle person.add_event_ref(eref) self.dbstate.db.commit_person(person, self.trans)
def add_birthday(self, fields, data): """Read the BDAY property of a VCard.""" date_str = data.strip() date_match = VCardParser.DATE_RE.match(date_str) date = Date() if date_match: if date_match.group(2): date_str = "%s-%s-%s" % (date_match.group(2), date_match.group(3), date_match.group(4)) else: date_str = date_match.group(1) y, m, d = [int(x, 10) for x in date_str.split('-')] try: date.set(value=(d, m, y, False)) except DateError: # TRANSLATORS: leave the {vcard_snippet} untranslated # in the format string, but you may re-order it if needed. self.__add_msg( _("Invalid date in BDAY {vcard_snippet}, " "preserving date as text.").format(vcard_snippet=data), self.line_num - 1) date.set(modifier=Date.MOD_TEXTONLY, text=data) else: if date_str: # TRANSLATORS: leave the {vcard_snippet} untranslated. self.__add_msg( _("Date {vcard_snippet} not in appropriate format " "yyyy-mm-dd, preserving date as text.").format( vcard_snippet=date_str), self.line_num - 1) date.set(modifier=Date.MOD_TEXTONLY, text=date_str) else: # silently ignore an empty BDAY record return event = Event() event.set_type(EventType(EventType.BIRTH)) event.set_date_object(date) self.database.add_event(event, self.trans) event_ref = EventRef() event_ref.set_reference_handle(event.get_handle()) self.person.set_birth_ref(event_ref)
def add_birthday(self, fields, data): """Read the BDAY property of a VCard.""" date_str = data.strip() date_match = VCardParser.DATE_RE.match(date_str) date = Date() if date_match: if date_match.group(2): date_str = "%s-%s-%s" % (date_match.group(2), date_match.group(3), date_match.group(4)) else: date_str = date_match.group(1) y, m, d = [int(x, 10) for x in date_str.split('-')] try: date.set(value=(d, m, y, False)) except DateError: # TRANSLATORS: leave the {vcard_snippet} untranslated # in the format string, but you may re-order it if needed. self.__add_msg(_( "Invalid date in BDAY {vcard_snippet}, " "preserving date as text." ).format(vcard_snippet=data), self.line_num - 1) date.set(modifier=Date.MOD_TEXTONLY, text=data) else: if date_str: # TRANSLATORS: leave the {vcard_snippet} untranslated. self.__add_msg(_( "Date {vcard_snippet} not in appropriate format " "yyyy-mm-dd, preserving date as text." ).format(vcard_snippet=date_str), self.line_num - 1) date.set(modifier=Date.MOD_TEXTONLY, text=date_str) else: # silently ignore an empty BDAY record return event = Event() event.set_type(EventType(EventType.BIRTH)) event.set_date_object(date) self.database.add_event(event, self.trans) event_ref = EventRef() event_ref.set_reference_handle(event.get_handle()) self.person.set_birth_ref(event_ref)
def column_death_place(self, data): handle = data[0] cached, value = self.get_cached_value(handle, "DEATH_PLACE") if cached: return value else: index = data[COLUMN_DEATH] if index != -1: try: local = data[COLUMN_EVENT][index] dr = EventRef() dr.unserialize(local) event = self.db.get_event_from_handle(dr.ref) if event: place_title = place_displayer.display_event( self.db, event) if place_title: value = escape(place_title) self.set_cached_value(handle, "DEATH_PLACE", value) return value except: value = '' self.set_cached_value(handle, "DEATH_PLACE", value) return value for event_ref in data[COLUMN_EVENT]: er = EventRef() er.unserialize(event_ref) event = self.db.get_event_from_handle(er.ref) etype = event.get_type() if (etype in [ EventType.BURIAL, EventType.CREMATION, EventType.CAUSE_DEATH ] and er.get_role() == EventRoleType.PRIMARY): place_title = place_displayer.display_event(self.db, event) if place_title: value = "<i>%s</i>" % escape(place_title) self.set_cached_value(handle, "DEATH_PLACE", value) return value value = "" self.set_cached_value(handle, "DEATH_PLACE", value) return value
def _get_death_data(self, data, sort_mode): index = data[COLUMN_DEATH] if index != -1: try: local = data[COLUMN_EVENT][index] ref = EventRef() ref.unserialize(local) event = self.db.get_event_from_handle(ref.ref) if sort_mode: retval = "%09d" % event.get_date_object().get_sort_value() else: date_str = get_date(event) if date_str != "": retval = escape(date_str) if not get_date_valid(event): return invalid_date_format % retval else: return retval except: return '' for event_ref in data[COLUMN_EVENT]: er = EventRef() er.unserialize(event_ref) event = self.db.get_event_from_handle(er.ref) etype = event.get_type() date_str = get_date(event) if (etype in [EventType.BURIAL, EventType.CREMATION, EventType.CAUSE_DEATH] and er.get_role() == EventRoleType.PRIMARY and date_str): if sort_mode: retval = "%09d" % event.get_date_object().get_sort_value() else: retval = "<i>%s</i>" % escape(date_str) if not get_date_valid(event): return invalid_date_format % retval else: return retval return ""
def _get_birth_data(self, data, sort_mode): index = data[COLUMN_BIRTH] if index != -1: try: local = data[COLUMN_EVENT][index] b = EventRef() b.unserialize(local) birth = self.db.get_event_from_handle(b.ref) if sort_mode: retval = "%09d" % birth.get_date_object().get_sort_value() else: date_str = get_date(birth) if date_str != "": retval = escape(date_str) if not get_date_valid(birth): return invalid_date_format % retval else: return retval except: return '' for event_ref in data[COLUMN_EVENT]: er = EventRef() er.unserialize(event_ref) event = self.db.get_event_from_handle(er.ref) etype = event.get_type() date_str = get_date(event) if (etype in [EventType.BAPTISM, EventType.CHRISTEN] and er.get_role() == EventRoleType.PRIMARY and date_str != ""): if sort_mode: retval = "%09d" % event.get_date_object().get_sort_value() else: retval = "<i>%s</i>" % escape(date_str) if not get_date_valid(event): return invalid_date_format % retval else: return retval return ""
def column_birth_place(self, data): handle = data[0] cached, value = self.get_cached_value(handle, "BIRTH_PLACE") if cached: return value else: index = data[COLUMN_BIRTH] if index != -1: try: local = data[COLUMN_EVENT][index] br = EventRef() br.unserialize(local) event = self.db.get_event_from_handle(br.ref) if event: place_title = place_displayer.display_event( self.db, event) if place_title: value = escape(place_title) self.set_cached_value(handle, "BIRTH_PLACE", value) return value except: value = '' self.set_cached_value(handle, "BIRTH_PLACE", value) return value for event_ref in data[COLUMN_EVENT]: er = EventRef() er.unserialize(event_ref) event = self.db.get_event_from_handle(er.ref) etype = event.get_type() if (etype.is_birth_fallback() and er.get_role() == EventRoleType.PRIMARY): place_title = place_displayer.display_event(self.db, event) if place_title: value = "<i>%s</i>" % escape(place_title) self.set_cached_value(handle, "BIRTH_PLACE", value) return value value = "" self.set_cached_value(handle, "BIRTH_PLACE", value) return value
def clone_button_clicked(self, obj): 'Function called with the Clone button is clicked.' source_ref = self.get_selected() if source_ref and \ source_ref[1] is not None \ and source_ref[0] == self._WORKGROUP: source_event = self.dbstate.db.get_event_from_handle( source_ref[1].ref) try: ref = EventRef(source=source_ref[1]) event = Event(source=source_event) event.set_gramps_id( self.dbstate.db.find_next_event_gramps_id()) event.set_handle(None) self.get_ref_editor()(self.dbstate, self.uistate, self.track, event, ref, self.object_added) except WindowActiveError: pass
def column_death_place(self, data): handle = data[0] cached, value = self.get_cached_value(handle, "DEATH_PLACE") if cached: return value else: index = data[COLUMN_DEATH] if index != -1: try: local = data[COLUMN_EVENT][index] dr = EventRef() dr.unserialize(local) event = self.db.get_event_from_handle(dr.ref) if event: place_title = place_displayer.display_event(self.db, event) if place_title: value = escape(place_title) self.set_cached_value(handle, "DEATH_PLACE", value) return value except: value = "" self.set_cached_value(handle, "DEATH_PLACE", value) return value for event_ref in data[COLUMN_EVENT]: er = EventRef() er.unserialize(event_ref) event = self.db.get_event_from_handle(er.ref) etype = event.get_type() if ( etype in [EventType.BURIAL, EventType.CREMATION, EventType.CAUSE_DEATH] and er.get_role() == EventRoleType.PRIMARY ): place_title = place_displayer.display_event(self.db, event) if place_title: value = "<i>%s</i>" % escape(place_title) self.set_cached_value(handle, "DEATH_PLACE", value) return value value = "" self.set_cached_value(handle, "DEATH_PLACE", value) return value
def _get_birth_data(self, data, sort_mode): index = data[COLUMN_BIRTH] if index != -1: try: local = data[COLUMN_EVENT][index] b = EventRef() b.unserialize(local) birth = self.db.get_event_from_handle(b.ref) if sort_mode: retval = "%09d" % birth.get_date_object().get_sort_value() else: date_str = get_date(birth) if date_str != "": retval = escape(date_str) if not get_date_valid(birth): return invalid_date_format % retval else: return retval except: return "" for event_ref in data[COLUMN_EVENT]: er = EventRef() er.unserialize(event_ref) event = self.db.get_event_from_handle(er.ref) etype = event.get_type() date_str = get_date(event) if ( etype in [EventType.BAPTISM, EventType.CHRISTEN] and er.get_role() == EventRoleType.PRIMARY and date_str != "" ): if sort_mode: retval = "%09d" % event.get_date_object().get_sort_value() else: retval = "<i>%s</i>" % escape(date_str) if not get_date_valid(event): return invalid_date_format % retval else: return retval return ""
def column_birth_place(self, data): handle = data[0] cached, value = self.get_cached_value(handle, "BIRTH_PLACE") if cached: return value else: index = data[COLUMN_BIRTH] if index != -1: try: local = data[COLUMN_EVENT][index] br = EventRef() br.unserialize(local) event = self.db.get_event_from_handle(br.ref) if event: place_title = place_displayer.display_event(self.db, event) if place_title: value = escape(place_title) self.set_cached_value(handle, "BIRTH_PLACE", value) return value except: value = "" self.set_cached_value(handle, "BIRTH_PLACE", value) return value for event_ref in data[COLUMN_EVENT]: er = EventRef() er.unserialize(event_ref) event = self.db.get_event_from_handle(er.ref) etype = event.get_type() if etype in [EventType.BAPTISM, EventType.CHRISTEN] and er.get_role() == EventRoleType.PRIMARY: place_title = place_displayer.display_event(self.db, event) if place_title: value = "<i>%s</i>" % escape(place_title) self.set_cached_value(handle, "BIRTH_PLACE", value) return value value = "" self.set_cached_value(handle, "BIRTH_PLACE", value) return value
def apply_selection(self, *args, **kwargs): # Do not add birth or death event if one exists, no matter what if self.table.treeview.get_model() is None: return with DbTxn("", self.db, batch=True) as self.trans: self.pre_run() source_text = self.options.handler.options_dict['source_text'] select_col = self.table.model_index_of_column[_("Select")] source = self.get_or_create_source(source_text) self.db.disable_signals() self.results_write(_("Selecting... ")) self.progress.set_pass((_("Adding events '%s'...") % source_text), len(self.table.treeview.get_model())) count = 0 for row in self.table.treeview.get_model(): self.progress.step() select = row[select_col] # live select value if not select: continue pupdate = False index = row[0] # order put in row_data = self.table.get_raw_data(index) person = row_data[1] # check, person, action, date1, date2 date1 = row_data[3] # date date2 = row_data[4] # date evidence = row_data[5] # evidence other = row_data[6] # other person add_birth_event, add_death_event = self.action[person.handle] birth_ref = person.get_birth_ref() death_ref = person.get_death_ref() if not birth_ref and add_birth_event: other_name = self.sdb.name(other) if other_name: explanation = _("Added birth event based on %(evidence)s, from %(name)s") % { 'evidence' : evidence, 'name' : other_name } else: explanation = _("Added birth event based on %s") % evidence modifier = self.get_modifier("birth") birth = self.create_event(_("Estimated birth date"), EventType.BIRTH, date1, source, explanation, modifier) event_ref = EventRef() event_ref.set_reference_handle(birth.get_handle()) person.set_birth_ref(event_ref) pupdate = True count += 1 if not death_ref and add_death_event: other_name = self.sdb.name(other) if other_name: explanation = _("Added death event based on %(evidence)s, from %(person)s") % { 'evidence' : evidence, 'person' : other_name } else: explanation = _("Added death event based on %s") % evidence modifier = self.get_modifier("death") death = self.create_event(_("Estimated death date"), EventType.DEATH, date2, source, explanation, modifier) event_ref = EventRef() event_ref.set_reference_handle(death.get_handle()) person.set_death_ref(event_ref) pupdate = True count += 1 if pupdate: self.db.commit_person(person, self.trans) self.results_write(_(" Done! Committing...")) self.results_write("\n") self.db.enable_signals() self.db.request_rebuild() self.results_write(_("Added %d events.") % count) self.results_write("\n\n") self.progress.close()
def _parse_marriage(self, line_number, row, col): "Parse the content of a Marriage,Husband,Wife line." marriage_ref = rd(line_number, row, col, "marriage") husband = rd(line_number, row, col, "husband") wife = rd(line_number, row, col, "wife") marriagedate = rd(line_number, row, col, "date") marriageplace = rd(line_number, row, col, "place") marriageplace_id = rd(line_number, row, col, "place_id") marriagesource = rd(line_number, row, col, "source") note = rd(line_number, row, col, "note") wife = self.lookup("person", wife) husband = self.lookup("person", husband) if husband is None and wife is None: # might have children, so go ahead and add LOG.warn("no parents on line %d; adding family anyway" % line_number) family = self.get_or_create_family(marriage_ref, husband, wife) # adjust gender, if not already provided if husband: # this is just a guess, if unknown if husband.get_gender() == Person.UNKNOWN: husband.set_gender(Person.MALE) self.db.commit_person(husband, self.trans) if wife: # this is just a guess, if unknown if wife.get_gender() == Person.UNKNOWN: wife.set_gender(Person.FEMALE) self.db.commit_person(wife, self.trans) if marriage_ref: self.storeup("family", marriage_ref.lower(), family) if marriagesource: # add, if new new, marriagesource = self.get_or_create_source(marriagesource) if marriageplace and marriageplace_id: raise Error("Error in marriage: can't have a place and place_id") if marriageplace: # add, if new new, marriageplace = self.get_or_create_place(marriageplace) elif marriageplace_id: # better exist already, locally or in database: marriageplace = self.lookup("place", marriageplace_id) if marriagedate: marriagedate = _dp.parse(marriagedate) if marriagedate or marriageplace or marriagesource or note: # add, if new; replace, if different new, marriage = self.get_or_create_event(family, EventType.MARRIAGE, marriagedate, marriageplace, marriagesource) if new: mar_ref = EventRef() mar_ref.set_reference_handle(marriage.get_handle()) family.add_event_ref(mar_ref) self.db.commit_family(family, self.trans) # only add note to event: # append notes, if previous notes if note: previous_notes_list = marriage.get_note_list() updated_note = False for note_handle in previous_notes_list: previous_note = self.db.get_note_from_handle( note_handle) if previous_note.type == NoteType.EVENT: previous_text = previous_note.get() if note not in previous_text: note = previous_text + "\n" + note previous_note.set(note) self.db.commit_note(previous_note, self.trans) updated_note = True break if not updated_note: # add new note here new_note = Note() new_note.handle = create_id() new_note.type.set(NoteType.EVENT) new_note.set(note) if self.default_tag: new_note.add_tag(self.default_tag.handle) self.db.add_note(new_note, self.trans) marriage.add_note(new_note.handle) self.db.commit_event(marriage, self.trans)
def parse_person(self,fields,idx,gender,father_surname): if not father_surname: if not idx < len(fields): LOG.warning("Missing surname of person in line %d!" % self.lineno) surname ="" else: surname = self.decode(fields[idx]) idx += 1 else: surname = father_surname if not idx < len(fields): LOG.warning("Missing firstname of person in line %d!" % self.lineno) firstname = "" else: firstname = self.decode(fields[idx]) idx += 1 if idx < len(fields) and father_surname: noSurnameRe = re.compile("^[({\[~><?0-9#].*$") if not noSurnameRe.match(fields[idx]): surname = self.decode(fields[idx]) idx += 1 LOG.debug("Person: %s %s" % (firstname, surname)) person = self.get_or_create_person(firstname,surname) name = Name() name.set_type( NameType(NameType.BIRTH)) name.set_first_name(firstname) surname_obj = name.get_primary_surname() surname_obj.set_surname(surname) person.set_primary_name(name) if person.get_gender() == Person.UNKNOWN and gender is not None: person.set_gender(gender) self.db.commit_person(person,self.trans) personDataRe = re.compile("^[kmes0-9<>~#\[({!].*$") dateRe = re.compile("^[kmes0-9~<>?]+.*$") source = None birth_parsed = False birth_date = None birth_place = None birth_source = None bapt_date = None bapt_place = None bapt_source = None death_date = None death_place = None death_source = None death_cause = None crem_date = None bur_date = None bur_place = None bur_source = None public_name = None firstname_aliases = [] nick_names = [] name_aliases = [] surname_aliases = [] while idx < len(fields) and personDataRe.match(fields[idx]): field = fields[idx] idx += 1 if field.startswith('('): LOG.debug("Public Name: %s" % field) public_name = self.decode(field[1:-1]) elif field.startswith('{'): LOG.debug("Firstsname Alias: %s" % field) firstname_aliases.append(self.decode(field[1:-1])) elif field.startswith('['): LOG.debug("Title: %s" % field) titleparts = self.decode(field[1:-1]).split(":") tname = ttitle = tplace = tstart = tend = tnth = None try: tname = titleparts[0] ttitle = titleparts[1] if titleparts[2]: tplace = self.get_or_create_place(titleparts[2]) tstart = self.parse_date(titleparts[3]) tend = self.parse_date(titleparts[4]) tnth = titleparts[5] except IndexError: # not all parts are written all the time pass if tnth: # Append title numer to title ttitle += ", " + tnth title = self.create_event( EventType.NOB_TITLE, ttitle, tstart, tplace) # TODO: Geneweb has a start date and an end date, and therefore # supports stuff like: FROM about 1955 TO between 1998 and 1999 # gramps only supports one single date or range. if tname and tname != "*": n = Note() n.set(tname) self.db.add_note(n,self.trans) title.add_note( n.handle) title_ref = EventRef() title_ref.set_reference_handle(title.get_handle()) person.add_event_ref(title_ref) elif field == '#nick' and idx < len(fields): LOG.debug("Nick Name: %s" % fields[idx]) nick_names.append(self.decode(fields[idx])) idx += 1 elif field == '#occu' and idx < len(fields): LOG.debug("Occupation: %s" % fields[idx]) occu = self.create_event( EventType.OCCUPATION, self.decode(fields[idx])) occu_ref = EventRef() occu_ref.set_reference_handle(occu.get_handle()) person.add_event_ref(occu_ref) idx += 1 elif field == '#alias' and idx < len(fields): LOG.debug("Name Alias: %s" % fields[idx]) name_aliases.append(self.decode(fields[idx])) idx += 1 elif field == '#salias' and idx < len(fields): LOG.debug("Surname Alias: %s" % fields[idx]) surname_aliases.append(self.decode(fields[idx])) idx += 1 elif field == '#image' and idx < len(fields): LOG.debug("Image: %s" % fields[idx]) idx += 1 elif field == '#src' and idx < len(fields): LOG.debug("Source: %s" % fields[idx]) source = self.get_or_create_source(self.decode(fields[idx])) idx += 1 elif field == '#bs' and idx < len(fields): LOG.debug("Birth Source: %s" % fields[idx]) birth_source = self.get_or_create_source(self.decode(fields[idx])) idx += 1 elif field[0] == '!': LOG.debug("Baptize at: %s" % field[1:]) bapt_date = self.parse_date(self.decode(field[1:])) elif field == '#bp' and idx < len(fields): LOG.debug("Birth Place: %s" % fields[idx]) birth_place = self.get_or_create_place(self.decode(fields[idx])) idx += 1 elif field == '#pp' and idx < len(fields): LOG.debug("Baptize Place: %s" % fields[idx]) bapt_place = self.get_or_create_place(self.decode(fields[idx])) idx += 1 elif field == '#ps' and idx < len(fields): LOG.debug("Baptize Source: %s" % fields[idx]) bapt_source = self.get_or_create_source(self.decode(fields[idx])) idx += 1 elif field == '#dp' and idx < len(fields): LOG.debug("Death Place: %s" % fields[idx]) death_place = self.get_or_create_place(self.decode(fields[idx])) idx += 1 elif field == '#ds' and idx < len(fields): LOG.debug("Death Source: %s" % fields[idx]) death_source = self.get_or_create_source(self.decode(fields[idx])) idx += 1 elif field == '#buri' and idx < len(fields): if fields[idx][0]!='#': # bug in GeneWeb: empty #buri fields LOG.debug("Burial Date: %s" % fields[idx]) bur_date = self.parse_date(self.decode(fields[idx])) idx += 1 elif field == '#crem' and idx < len(fields): LOG.debug("Cremention Date: %s" % fields[idx]) crem_date = self.parse_date(self.decode(fields[idx])) idx += 1 elif field == '#rp' and idx < len(fields): LOG.debug("Burial Place: %s" % fields[idx]) bur_place = self.get_or_create_place(self.decode(fields[idx])) idx += 1 elif field == '#rs' and idx < len(fields): LOG.debug("Burial Source: %s" % fields[idx]) bur_source = self.get_or_create_source(self.decode(fields[idx])) idx += 1 elif field == '#apubl': LOG.debug("This is a public record") elif field == '#apriv': LOG.debug("This is a private record") person.set_privacy(True) elif field == '#h': LOG.debug("This is a restricted record") #TODO: Gramps does currently not feature this level person.set_privacy(True) elif dateRe.match(field): if not birth_parsed: LOG.debug("Birth Date: %s" % field) birth_date = self.parse_date(self.decode(field)) birth_parsed = True else: LOG.debug("Death Date: %s" % field) death_date = self.parse_date(self.decode(field)) if field == "mj": death_cause = "Died joung" elif field.startswith("k"): death_cause = "Killed" elif field.startswith("m"): death_cause = "Murdered" elif field.startswith("e"): death_cause = "Executed" elif field.startswith("d"): death_cause = "Disappeared" #TODO: Set special death types more properly else: LOG.warning(("parse_person(): Unknown field " + "'%s' for person in line %d!") % (field, self.lineno)) if public_name: name = person.get_primary_name() name.set_type(NameType(NameType.BIRTH)) person.add_alternate_name(name) name = Name() name.set_type(NameType(NameType.AKA)) name.set_first_name(public_name) surname_obj = name.get_primary_surname() surname_obj.set_surname(surname) person.set_primary_name(name) for aka in nick_names: name = Attribute() name.set_type(AttributeType(AttributeType.NICKNAME)) name.set_value(aka) person.add_attribute(name) for aka in firstname_aliases: name = Name() name.set_type(NameType(NameType.AKA)) name.set_first_name(aka) surname_obj = name.get_primary_surname() surname_obj.set_surname(surname) person.add_alternate_name(name) for aka in name_aliases: name = Name() name.set_type(NameType(NameType.AKA)) name.set_first_name(aka) surname_obj = name.get_primary_surname() surname_obj.set_surname(surname) person.add_alternate_name(name) for aka in surname_aliases: name = Name() name.set_type(NameType(NameType.AKA)) if public_name: name.set_first_name(public_name) else: name.set_first_name(firstname) surname_obj = name.get_primary_surname() surname_obj.set_surname(aka) person.add_alternate_name(name) if source: person.add_citation(source.get_handle()) if birth_date or birth_place or birth_source: birth = self.create_event(EventType.BIRTH, None, birth_date, birth_place, birth_source) birth_ref = EventRef() birth_ref.set_reference_handle( birth.get_handle()) person.set_birth_ref( birth_ref) if bapt_date or bapt_place or bapt_source: babt = self.create_event(EventType.BAPTISM, None, bapt_date, bapt_place, bapt_source) babt_ref = EventRef() babt_ref.set_reference_handle( babt.get_handle()) person.add_event_ref( babt_ref) if death_date or death_place or death_source or death_cause: death = self.create_event(EventType.DEATH, None, death_date, death_place, death_source) if death_cause: death.set_description(death_cause) self.db.commit_event(death,self.trans) death_ref = EventRef() death_ref.set_reference_handle( death.get_handle()) person.set_death_ref( death_ref) if bur_date: bur = self.create_event(EventType.BURIAL, None, bur_date, bur_place, bur_source) bur_ref = EventRef() bur_ref.set_reference_handle( bur.get_handle()) person.add_event_ref( bur_ref) if crem_date: crem = self.create_event(EventType.CREMATION, None, crem_date, bur_place, bur_source) crem_ref = EventRef() crem_ref.set_reference_handle( crem.get_handle()) person.add_event_ref(crem_ref) self.db.commit_person(person,self.trans) return (idx,person)
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 _parse_marriage(self, line_number, row, col): "Parse the content of a Marriage,Husband,Wife line." marriage_ref = rd(line_number, row, col, "marriage") husband = rd(line_number, row, col, "husband") wife = rd(line_number, row, col, "wife") marriagedate = rd(line_number, row, col, "date") marriageplace = rd(line_number, row, col, "place") marriageplace_id = rd(line_number, row, col, "place_id") marriagesource = rd(line_number, row, col, "source") note = rd(line_number, row, col, "note") wife = self.lookup("person", wife) husband = self.lookup("person", husband) if husband is None and wife is None: # might have children, so go ahead and add LOG.warn("no parents on line %d; adding family anyway" % line_number) family = self.get_or_create_family(marriage_ref, husband, wife) # adjust gender, if not already provided if husband: # this is just a guess, if unknown if husband.get_gender() == Person.UNKNOWN: husband.set_gender(Person.MALE) self.db.commit_person(husband, self.trans) if wife: # this is just a guess, if unknown if wife.get_gender() == Person.UNKNOWN: wife.set_gender(Person.FEMALE) self.db.commit_person(wife, self.trans) if marriage_ref: self.storeup("family", marriage_ref.lower(), family) if marriagesource: # add, if new new, marriagesource = self.get_or_create_source(marriagesource) if marriageplace and marriageplace_id: raise Error("Error in marriage: can't have a place and place_id") if marriageplace: # add, if new new, marriageplace = self.get_or_create_place(marriageplace) elif marriageplace_id: # better exist already, locally or in database: marriageplace = self.lookup("place", marriageplace_id) if marriagedate: marriagedate = _dp.parse(marriagedate) if marriagedate or marriageplace or marriagesource or note: # add, if new; replace, if different new, marriage = self.get_or_create_event(family, EventType.MARRIAGE, marriagedate, marriageplace, marriagesource) if new: mar_ref = EventRef() mar_ref.set_reference_handle(marriage.get_handle()) family.add_event_ref(mar_ref) self.db.commit_family(family, self.trans) # only add note to event: # append notes, if previous notes if note: previous_notes_list = marriage.get_note_list() updated_note = False for note_handle in previous_notes_list: previous_note = self.db.get_note_from_handle(note_handle) if previous_note.type == NoteType.EVENT: previous_text = previous_note.get() if note not in previous_text: note = previous_text + "\n" + note previous_note.set(note) self.db.commit_note(previous_note, self.trans) updated_note = True break if not updated_note: # add new note here new_note = Note() new_note.handle = create_id() new_note.type.set(NoteType.EVENT) new_note.set(note) if self.default_tag: new_note.add_tag(self.default_tag.handle) self.db.add_note(new_note, self.trans) marriage.add_note(new_note.handle) self.db.commit_event(marriage, self.trans)
def _parse_person(self, line_number, row, col): "Parse the content of a Person line." surname = rd(line_number, row, col, "surname") firstname = rd(line_number, row, col, "firstname", "") callname = rd(line_number, row, col, "callname") title = rd(line_number, row, col, "title") prefix = rd(line_number, row, col, "prefix") suffix = rd(line_number, row, col, "suffix") gender = rd(line_number, row, col, "gender") source = rd(line_number, row, col, "source") note = rd(line_number, row, col, "note") birthplace = rd(line_number, row, col, "birthplace") birthplace_id = rd(line_number, row, col, "birthplace_id") birthdate = rd(line_number, row, col, "birthdate") birthsource = rd(line_number, row, col, "birthsource") baptismplace = rd(line_number, row, col, "baptismplace") baptismplace_id = rd(line_number, row, col, "baptismplace_id") baptismdate = rd(line_number, row, col, "baptismdate") baptismsource = rd(line_number, row, col, "baptismsource") burialplace = rd(line_number, row, col, "burialplace") burialplace_id = rd(line_number, row, col, "burialplace_id") burialdate = rd(line_number, row, col, "burialdate") burialsource = rd(line_number, row, col, "burialsource") deathplace = rd(line_number, row, col, "deathplace") deathplace_id = rd(line_number, row, col, "deathplace_id") deathdate = rd(line_number, row, col, "deathdate") deathsource = rd(line_number, row, col, "deathsource") deathcause = rd(line_number, row, col, "deathcause") grampsid = rd(line_number, row, col, "grampsid") person_ref = rd(line_number, row, col, "person") ######################################################### # if this person already exists, don't create them person = self.lookup("person", person_ref) if person is None: if surname is None: LOG.warn("empty surname for new person on line %d" % line_number) surname = "" # new person person = self.create_person() name = Name() name.set_type(NameType(NameType.BIRTH)) name.set_first_name(firstname) surname_obj = Surname() surname_obj.set_surname(surname) name.add_surname(surname_obj) person.set_primary_name(name) else: name = person.get_primary_name() ######################################################### if person_ref is not None: self.storeup("person", person_ref, person) # replace if surname is not None: name.get_primary_surname().set_surname(surname) if firstname is not None: name.set_first_name(firstname) if callname is not None: name.set_call_name(callname) if title is not None: name.set_title(title) if prefix is not None: name.get_primary_surname().set_prefix(prefix) name.group_as = '' # HELP? what should I do here? if suffix is not None: name.set_suffix(suffix) if note is not None: # append notes, if previous notes previous_notes_list = person.get_note_list() updated_note = False for note_handle in previous_notes_list: previous_note = self.db.get_note_from_handle(note_handle) if previous_note.type == NoteType.PERSON: previous_text = previous_note.get() if note not in previous_text: note = previous_text + "\n" + note previous_note.set(note) self.db.commit_note(previous_note, self.trans) updated_note = True break if not updated_note: # add new note here new_note = Note() new_note.handle = create_id() new_note.type.set(NoteType.PERSON) new_note.set(note) if self.default_tag: new_note.add_tag(self.default_tag.handle) self.db.add_note(new_note, self.trans) person.add_note(new_note.handle) if grampsid is not None: person.gramps_id = grampsid elif person_ref is not None: if person_ref.startswith("[") and person_ref.endswith("]"): person.gramps_id = self.db.id2user_format(person_ref[1:-1]) if (person.get_gender() == Person.UNKNOWN and gender is not None): gender = gender.lower() if gender == gender_map[Person.MALE].lower(): gender = Person.MALE elif gender == gender_map[Person.FEMALE].lower(): gender = Person.FEMALE else: gender = Person.UNKNOWN person.set_gender(gender) ######################################################### # add if new, replace if different # Birth: if birthdate is not None: birthdate = _dp.parse(birthdate) if birthplace and birthplace_id: raise Error( "Error in person: can't have a birthplace and birthplace_id") if birthplace is not None: new, birthplace = self.get_or_create_place(birthplace) elif birthplace_id: # better exist already, locally or in database: birthplace = self.lookup("place", birthplace_id) if birthsource is not None: new, birthsource = self.get_or_create_source(birthsource) if birthdate or birthplace or birthsource: new, birth = self.get_or_create_event(person, EventType.BIRTH, birthdate, birthplace, birthsource) birth_ref = person.get_birth_ref() if birth_ref is None: # new birth_ref = EventRef() birth_ref.set_reference_handle(birth.get_handle()) person.set_birth_ref(birth_ref) # Baptism: if baptismdate is not None: baptismdate = _dp.parse(baptismdate) if baptismplace and baptismplace_id: raise Error( "Error in person: can't have a baptismplace and baptismplace_id" ) if baptismplace is not None: new, baptismplace = self.get_or_create_place(baptismplace) elif baptismplace_id: # better exist already, locally or in database: baptismplace = self.lookup("place", baptismplace_id) if baptismsource is not None: new, baptismsource = self.get_or_create_source(baptismsource) if baptismdate or baptismplace or baptismsource: new, baptism = self.get_or_create_event(person, EventType.BAPTISM, baptismdate, baptismplace, baptismsource) baptism_ref = get_primary_event_ref_from_type( self.db, person, "Baptism") if baptism_ref is None: # new baptism_ref = EventRef() baptism_ref.set_reference_handle(baptism.get_handle()) person.add_event_ref(baptism_ref) # Death: if deathdate is not None: deathdate = _dp.parse(deathdate) if deathplace and deathplace_id: raise Error( "Error in person: can't have a deathplace and deathplace_id") if deathplace is not None: new, deathplace = self.get_or_create_place(deathplace) elif deathplace_id: # better exist already, locally or in database: deathplace = self.lookup("place", deathplace_id) if deathsource is not None: new, deathsource = self.get_or_create_source(deathsource) if deathdate or deathplace or deathsource or deathcause: new, death = self.get_or_create_event(person, EventType.DEATH, deathdate, deathplace, deathsource) if deathcause: death.set_description(deathcause) self.db.commit_event(death, self.trans) death_ref = person.get_death_ref() if death_ref is None: # new death_ref = EventRef() death_ref.set_reference_handle(death.get_handle()) person.set_death_ref(death_ref) # Burial: if burialdate is not None: burialdate = _dp.parse(burialdate) if burialplace and burialplace_id: raise Error( "Error in person: can't have a burialplace and burialplace_id") if burialplace is not None: new, burialplace = self.get_or_create_place(burialplace) elif burialplace_id: # better exist already, locally or in database: burialplace = self.lookup("place", burialplace_id) if burialsource is not None: new, burialsource = self.get_or_create_source(burialsource) if burialdate or burialplace or burialsource: new, burial = self.get_or_create_event(person, EventType.BURIAL, burialdate, burialplace, burialsource) burial_ref = get_primary_event_ref_from_type( self.db, person, "Burial") if burial_ref is None: # new burial_ref = EventRef() burial_ref.set_reference_handle(burial.get_handle()) person.add_event_ref(burial_ref) if source: # add, if new new, source = self.get_or_create_source(source) self.find_and_set_citation(person, source) self.db.commit_person(person, self.trans)
def run_tool(self): self.progress = ProgressMeter(_('Running Date Test'), '', parent=self.parent_window) self.progress.set_pass(_('Generating dates'), 4) dates = [] # first some valid dates calendar = Date.CAL_GREGORIAN for quality in (Date.QUAL_NONE, Date.QUAL_ESTIMATED, Date.QUAL_CALCULATED): for modifier in (Date.MOD_NONE, Date.MOD_BEFORE, Date.MOD_AFTER, Date.MOD_ABOUT): for slash1 in (False, True): for month in range(0, 13): for day in (0, 5, 27): if not month and day: continue d = Date() d.set(quality, modifier, calendar, (day, month, 1789, slash1), "Text comment") dates.append(d) for modifier in (Date.MOD_RANGE, Date.MOD_SPAN): for slash1 in (False, True): for slash2 in (False, True): for month in range(0, 13): for day in (0, 5, 27): if not month and day: continue d = Date() d.set(quality, modifier, calendar, (day, month, 1789, slash1, day, month, 1876, slash2), "Text comment") dates.append(d) if not month: continue d = Date() d.set(quality, modifier, calendar, (day, month, 1789, slash1, day, 13 - month, 1876, slash2), "Text comment") dates.append(d) if not day: continue d = Date() d.set(quality, modifier, calendar, (day, month, 1789, slash1, 32 - day, month, 1876, slash2), "Text comment") dates.append(d) d = Date() d.set(quality, modifier, calendar, (day, month, 1789, slash1, 32 - day, 13 - month, 1876, slash2), "Text comment") dates.append(d) modifier = Date.MOD_TEXTONLY d = Date() d.set(quality, modifier, calendar, Date.EMPTY, "This is a textual date") dates.append(d) self.progress.step() # test invalid dates #dateval = (4,7,1789,False,5,8,1876,False) #for l in range(1,len(dateval)): # d = Date() # try: # d.set(Date.QUAL_NONE,Date.MOD_NONE, # Date.CAL_GREGORIAN,dateval[:l],"Text comment") # dates.append( d) # except DateError, e: # d.set_as_text("Date identified value correctly as invalid.\n%s" % e) # dates.append( d) # except: # d = Date() # d.set_as_text("Date.set Exception %s" % ("".join(traceback.format_exception(*sys.exc_info())),)) # dates.append( d) #for l in range(1,len(dateval)): # d = Date() # try: # d.set(Date.QUAL_NONE,Date.MOD_SPAN,Date.CAL_GREGORIAN,dateval[:l],"Text comment") # dates.append( d) # except DateError, e: # d.set_as_text("Date identified value correctly as invalid.\n%s" % e) # dates.append( d) # except: # d = Date() # d.set_as_text("Date.set Exception %s" % ("".join(traceback.format_exception(*sys.exc_info())),)) # dates.append( d) #self.progress.step() #d = Date() #d.set(Date.QUAL_NONE,Date.MOD_NONE, # Date.CAL_GREGORIAN,(44,7,1789,False),"Text comment") #dates.append( d) #d = Date() #d.set(Date.QUAL_NONE,Date.MOD_NONE, # Date.CAL_GREGORIAN,(4,77,1789,False),"Text comment") #dates.append( d) #d = Date() #d.set(Date.QUAL_NONE,Date.MOD_SPAN, # Date.CAL_GREGORIAN, # (4,7,1789,False,55,8,1876,False),"Text comment") #dates.append( d) #d = Date() #d.set(Date.QUAL_NONE,Date.MOD_SPAN, # Date.CAL_GREGORIAN, # (4,7,1789,False,5,88,1876,False),"Text comment") #dates.append( d) with DbTxn(_("Date Test Plugin"), self.db, batch=True) as self.trans: self.db.disable_signals() self.progress.set_pass(_('Generating dates'), len(dates)) # create pass and fail tags pass_handle = self.create_tag(_('Pass'), '#0000FFFF0000') fail_handle = self.create_tag(_('Fail'), '#FFFF00000000') # now add them as birth to new persons i = 1 for dateval in dates: person = Person() surname = Surname() surname.set_surname("DateTest") name = Name() name.add_surname(surname) name.set_first_name("Test %d" % i) person.set_primary_name(name) self.db.add_person(person, self.trans) bevent = Event() bevent.set_type(EventType.BIRTH) bevent.set_date_object(dateval) bevent.set_description("Date Test %d (source)" % i) bevent_h = self.db.add_event(bevent, self.trans) bevent_ref = EventRef() bevent_ref.set_reference_handle(bevent_h) # for the death event display the date as text and parse it back to a new date ndate = None try: datestr = _dd.display(dateval) try: ndate = _dp.parse(datestr) if not ndate: ndate = Date() ndate.set_as_text("DateParser None") person.add_tag(fail_handle) else: person.add_tag(pass_handle) except: ndate = Date() ndate.set_as_text("DateParser Exception %s" % ("".join( traceback.format_exception(*sys.exc_info())), )) person.add_tag(fail_handle) else: person.add_tag(pass_handle) except: ndate = Date() ndate.set_as_text("DateDisplay Exception: %s" % ("".join( traceback.format_exception(*sys.exc_info())), )) person.add_tag(fail_handle) if dateval.get_modifier() != Date.MOD_TEXTONLY \ and ndate.get_modifier() == Date.MOD_TEXTONLY: # parser was unable to correctly parse the string ndate.set_as_text("TEXTONLY: " + ndate.get_text()) person.add_tag(fail_handle) if dateval.get_modifier() == Date.MOD_TEXTONLY \ and dateval.get_text().count("Traceback") \ and pass_handle in person.get_tag_list(): person.add_tag(fail_handle) devent = Event() devent.set_type(EventType.DEATH) devent.set_date_object(ndate) devent.set_description("Date Test %d (result)" % i) devent_h = self.db.add_event(devent, self.trans) devent_ref = EventRef() devent_ref.set_reference_handle(devent_h) person.set_birth_ref(bevent_ref) person.set_death_ref(devent_ref) self.db.commit_person(person, self.trans) i = i + 1 self.progress.step() self.db.enable_signals() self.db.request_rebuild() self.progress.close()
def run_tool(self): self.progress = ProgressMeter(_('Running Date Test'),'', parent=self.parent_window) self.progress.set_pass(_('Generating dates'), 4) dates = [] # first some valid dates calendar = Date.CAL_GREGORIAN for quality in (Date.QUAL_NONE, Date.QUAL_ESTIMATED, Date.QUAL_CALCULATED): for modifier in (Date.MOD_NONE, Date.MOD_BEFORE, Date.MOD_AFTER, Date.MOD_ABOUT): for slash1 in (False,True): for month in range(0,13): for day in (0,5,27): if not month and day: continue d = Date() d.set(quality,modifier,calendar,(day,month,1789,slash1),"Text comment") dates.append( d) for modifier in (Date.MOD_RANGE, Date.MOD_SPAN): for slash1 in (False,True): for slash2 in (False,True): for month in range(0,13): for day in (0,5,27): if not month and day: continue d = Date() d.set(quality,modifier,calendar,(day,month,1789,slash1,day,month,1876,slash2),"Text comment") dates.append( d) if not month: continue d = Date() d.set(quality,modifier,calendar,(day,month,1789,slash1,day,13-month,1876,slash2),"Text comment") dates.append( d) if not day: continue d = Date() d.set(quality,modifier,calendar,(day,month,1789,slash1,32-day,month,1876,slash2),"Text comment") dates.append( d) d = Date() d.set(quality,modifier,calendar,(day,month,1789,slash1,32-day,13-month,1876,slash2),"Text comment") dates.append( d) modifier = Date.MOD_TEXTONLY d = Date() d.set(quality,modifier,calendar,Date.EMPTY, "This is a textual date") dates.append( d) self.progress.step() # test invalid dates #dateval = (4,7,1789,False,5,8,1876,False) #for l in range(1,len(dateval)): # d = Date() # try: # d.set(Date.QUAL_NONE,Date.MOD_NONE, # Date.CAL_GREGORIAN,dateval[:l],"Text comment") # dates.append( d) # except DateError, e: # d.set_as_text("Date identified value correctly as invalid.\n%s" % e) # dates.append( d) # except: # d = Date() # d.set_as_text("Date.set Exception %s" % ("".join(traceback.format_exception(*sys.exc_info())),)) # dates.append( d) #for l in range(1,len(dateval)): # d = Date() # try: # d.set(Date.QUAL_NONE,Date.MOD_SPAN,Date.CAL_GREGORIAN,dateval[:l],"Text comment") # dates.append( d) # except DateError, e: # d.set_as_text("Date identified value correctly as invalid.\n%s" % e) # dates.append( d) # except: # d = Date() # d.set_as_text("Date.set Exception %s" % ("".join(traceback.format_exception(*sys.exc_info())),)) # dates.append( d) #self.progress.step() #d = Date() #d.set(Date.QUAL_NONE,Date.MOD_NONE, # Date.CAL_GREGORIAN,(44,7,1789,False),"Text comment") #dates.append( d) #d = Date() #d.set(Date.QUAL_NONE,Date.MOD_NONE, # Date.CAL_GREGORIAN,(4,77,1789,False),"Text comment") #dates.append( d) #d = Date() #d.set(Date.QUAL_NONE,Date.MOD_SPAN, # Date.CAL_GREGORIAN, # (4,7,1789,False,55,8,1876,False),"Text comment") #dates.append( d) #d = Date() #d.set(Date.QUAL_NONE,Date.MOD_SPAN, # Date.CAL_GREGORIAN, # (4,7,1789,False,5,88,1876,False),"Text comment") #dates.append( d) with DbTxn(_("Date Test Plugin"), self.db, batch=True) as self.trans: self.db.disable_signals() self.progress.set_pass(_('Generating dates'), len(dates)) # create pass and fail tags pass_handle = self.create_tag(_('Pass'), '#0000FFFF0000') fail_handle = self.create_tag(_('Fail'), '#FFFF00000000') # now add them as birth to new persons i = 1 for dateval in dates: person = Person() surname = Surname() surname.set_surname("DateTest") name = Name() name.add_surname(surname) name.set_first_name("Test %d" % i) person.set_primary_name(name) self.db.add_person(person, self.trans) bevent = Event() bevent.set_type(EventType.BIRTH) bevent.set_date_object(dateval) bevent.set_description("Date Test %d (source)" % i) bevent_h = self.db.add_event(bevent, self.trans) bevent_ref = EventRef() bevent_ref.set_reference_handle(bevent_h) # for the death event display the date as text and parse it back to a new date ndate = None try: datestr = _dd.display( dateval) try: ndate = _dp.parse( datestr) if not ndate: ndate = Date() ndate.set_as_text("DateParser None") person.add_tag(fail_handle) else: person.add_tag(pass_handle) except: ndate = Date() ndate.set_as_text("DateParser Exception %s" % ("".join(traceback.format_exception(*sys.exc_info())),)) person.add_tag(fail_handle) else: person.add_tag(pass_handle) except: ndate = Date() ndate.set_as_text("DateDisplay Exception: %s" % ("".join(traceback.format_exception(*sys.exc_info())),)) person.add_tag(fail_handle) if dateval.get_modifier() != Date.MOD_TEXTONLY \ and ndate.get_modifier() == Date.MOD_TEXTONLY: # parser was unable to correctly parse the string ndate.set_as_text( "TEXTONLY: "+ndate.get_text()) person.add_tag(fail_handle) if dateval.get_modifier() == Date.MOD_TEXTONLY \ and dateval.get_text().count("Traceback") \ and pass_handle in person.get_tag_list(): person.add_tag(fail_handle) devent = Event() devent.set_type(EventType.DEATH) devent.set_date_object(ndate) devent.set_description("Date Test %d (result)" % i) devent_h = self.db.add_event(devent, self.trans) devent_ref = EventRef() devent_ref.set_reference_handle(devent_h) person.set_birth_ref(bevent_ref) person.set_death_ref(devent_ref) self.db.commit_person(person, self.trans) i = i + 1 self.progress.step() self.db.enable_signals() self.db.request_rebuild() self.progress.close()
def parse_person(self, fields, idx, gender, father_surname): if not father_surname: if not idx < len(fields): LOG.warning("Missing surname of person in line %d!" % self.lineno) surname = "" else: surname = self.decode(fields[idx]) idx += 1 else: surname = father_surname if not idx < len(fields): LOG.warning("Missing firstname of person in line %d!" % self.lineno) firstname = "" else: firstname = self.decode(fields[idx]) idx += 1 if idx < len(fields) and father_surname: noSurnameRe = re.compile("^[({\[~><?0-9#].*$") if not noSurnameRe.match(fields[idx]): surname = self.decode(fields[idx]) idx += 1 LOG.debug("Person: %s %s" % (firstname, surname)) person = self.get_or_create_person(firstname, surname) name = Name() name.set_type(NameType(NameType.BIRTH)) name.set_first_name(firstname) surname_obj = name.get_primary_surname() surname_obj.set_surname(surname) person.set_primary_name(name) if person.get_gender() == Person.UNKNOWN and gender is not None: person.set_gender(gender) self.db.commit_person(person, self.trans) personDataRe = re.compile("^[kmes0-9<>~#\[({!].*$") dateRe = re.compile("^[kmes0-9~<>?]+.*$") source = None birth_parsed = False birth_date = None birth_place = None birth_source = None bapt_date = None bapt_place = None bapt_source = None death_date = None death_place = None death_source = None death_cause = None crem_date = None bur_date = None bur_place = None bur_source = None public_name = None firstname_aliases = [] nick_names = [] name_aliases = [] surname_aliases = [] while idx < len(fields) and personDataRe.match(fields[idx]): field = fields[idx] idx += 1 if field.startswith('('): LOG.debug("Public Name: %s" % field) public_name = self.decode(field[1:-1]) elif field.startswith('{'): LOG.debug("Firstsname Alias: %s" % field) firstname_aliases.append(self.decode(field[1:-1])) elif field.startswith('['): LOG.debug("Title: %s" % field) titleparts = self.decode(field[1:-1]).split(":") tname = ttitle = tplace = tstart = tend = tnth = None try: tname = titleparts[0] ttitle = titleparts[1] if titleparts[2]: tplace = self.get_or_create_place(titleparts[2]) tstart = self.parse_date(titleparts[3]) tend = self.parse_date(titleparts[4]) tnth = titleparts[5] except IndexError: # not all parts are written all the time pass if tnth: # Append title numer to title ttitle += ", " + tnth title = self.create_event(EventType.NOB_TITLE, ttitle, tstart, tplace) # TODO: Geneweb has a start date and an end date, and therefore # supports stuff like: FROM about 1955 TO between 1998 and 1999 # gramps only supports one single date or range. if tname and tname != "*": n = Note() n.set(tname) self.db.add_note(n, self.trans) title.add_note(n.handle) title_ref = EventRef() title_ref.set_reference_handle(title.get_handle()) person.add_event_ref(title_ref) elif field == '#nick' and idx < len(fields): LOG.debug("Nick Name: %s" % fields[idx]) nick_names.append(self.decode(fields[idx])) idx += 1 elif field == '#occu' and idx < len(fields): LOG.debug("Occupation: %s" % fields[idx]) occu = self.create_event(EventType.OCCUPATION, self.decode(fields[idx])) occu_ref = EventRef() occu_ref.set_reference_handle(occu.get_handle()) person.add_event_ref(occu_ref) idx += 1 elif field == '#alias' and idx < len(fields): LOG.debug("Name Alias: %s" % fields[idx]) name_aliases.append(self.decode(fields[idx])) idx += 1 elif field == '#salias' and idx < len(fields): LOG.debug("Surname Alias: %s" % fields[idx]) surname_aliases.append(self.decode(fields[idx])) idx += 1 elif field == '#image' and idx < len(fields): LOG.debug("Image: %s" % fields[idx]) idx += 1 elif field == '#src' and idx < len(fields): LOG.debug("Source: %s" % fields[idx]) source = self.get_or_create_source(self.decode(fields[idx])) idx += 1 elif field == '#bs' and idx < len(fields): LOG.debug("Birth Source: %s" % fields[idx]) birth_source = self.get_or_create_source( self.decode(fields[idx])) idx += 1 elif field[0] == '!': LOG.debug("Baptize at: %s" % field[1:]) bapt_date = self.parse_date(self.decode(field[1:])) elif field == '#bp' and idx < len(fields): LOG.debug("Birth Place: %s" % fields[idx]) birth_place = self.get_or_create_place(self.decode( fields[idx])) idx += 1 elif field == '#pp' and idx < len(fields): LOG.debug("Baptize Place: %s" % fields[idx]) bapt_place = self.get_or_create_place(self.decode(fields[idx])) idx += 1 elif field == '#ps' and idx < len(fields): LOG.debug("Baptize Source: %s" % fields[idx]) bapt_source = self.get_or_create_source( self.decode(fields[idx])) idx += 1 elif field == '#dp' and idx < len(fields): LOG.debug("Death Place: %s" % fields[idx]) death_place = self.get_or_create_place(self.decode( fields[idx])) idx += 1 elif field == '#ds' and idx < len(fields): LOG.debug("Death Source: %s" % fields[idx]) death_source = self.get_or_create_source( self.decode(fields[idx])) idx += 1 elif field == '#buri' and idx < len(fields): if fields[idx][0] != '#': # bug in GeneWeb: empty #buri fields LOG.debug("Burial Date: %s" % fields[idx]) bur_date = self.parse_date(self.decode(fields[idx])) idx += 1 elif field == '#crem' and idx < len(fields): LOG.debug("Cremention Date: %s" % fields[idx]) crem_date = self.parse_date(self.decode(fields[idx])) idx += 1 elif field == '#rp' and idx < len(fields): LOG.debug("Burial Place: %s" % fields[idx]) bur_place = self.get_or_create_place(self.decode(fields[idx])) idx += 1 elif field == '#rs' and idx < len(fields): LOG.debug("Burial Source: %s" % fields[idx]) bur_source = self.get_or_create_source(self.decode( fields[idx])) idx += 1 elif field == '#apubl': LOG.debug("This is a public record") elif field == '#apriv': LOG.debug("This is a private record") person.set_privacy(True) elif field == '#h': LOG.debug("This is a restricted record") #TODO: Gramps does currently not feature this level person.set_privacy(True) elif dateRe.match(field): if not birth_parsed: LOG.debug("Birth Date: %s" % field) birth_date = self.parse_date(self.decode(field)) birth_parsed = True else: LOG.debug("Death Date: %s" % field) death_date = self.parse_date(self.decode(field)) if field == "mj": death_cause = "Died joung" elif field.startswith("k"): death_cause = "Killed" elif field.startswith("m"): death_cause = "Murdered" elif field.startswith("e"): death_cause = "Executed" elif field.startswith("d"): death_cause = "Disappeared" #TODO: Set special death types more properly else: LOG.warning( ("parse_person(): Unknown field " + "'%s' for person in line %d!") % (field, self.lineno)) if public_name: name = person.get_primary_name() name.set_type(NameType(NameType.BIRTH)) person.add_alternate_name(name) name = Name() name.set_type(NameType(NameType.AKA)) name.set_first_name(public_name) surname_obj = name.get_primary_surname() surname_obj.set_surname(surname) person.set_primary_name(name) for aka in nick_names: name = Attribute() name.set_type(AttributeType(AttributeType.NICKNAME)) name.set_value(aka) person.add_attribute(name) for aka in firstname_aliases: name = Name() name.set_type(NameType(NameType.AKA)) name.set_first_name(aka) surname_obj = name.get_primary_surname() surname_obj.set_surname(surname) person.add_alternate_name(name) for aka in name_aliases: name = Name() name.set_type(NameType(NameType.AKA)) name.set_first_name(aka) surname_obj = name.get_primary_surname() surname_obj.set_surname(surname) person.add_alternate_name(name) for aka in surname_aliases: name = Name() name.set_type(NameType(NameType.AKA)) if public_name: name.set_first_name(public_name) else: name.set_first_name(firstname) surname_obj = name.get_primary_surname() surname_obj.set_surname(aka) person.add_alternate_name(name) if source: person.add_citation(source.get_handle()) if birth_date or birth_place or birth_source: birth = self.create_event(EventType.BIRTH, None, birth_date, birth_place, birth_source) birth_ref = EventRef() birth_ref.set_reference_handle(birth.get_handle()) person.set_birth_ref(birth_ref) if bapt_date or bapt_place or bapt_source: babt = self.create_event(EventType.BAPTISM, None, bapt_date, bapt_place, bapt_source) babt_ref = EventRef() babt_ref.set_reference_handle(babt.get_handle()) person.add_event_ref(babt_ref) if death_date or death_place or death_source or death_cause: death = self.create_event(EventType.DEATH, None, death_date, death_place, death_source) if death_cause: death.set_description(death_cause) self.db.commit_event(death, self.trans) death_ref = EventRef() death_ref.set_reference_handle(death.get_handle()) person.set_death_ref(death_ref) if bur_date: bur = self.create_event(EventType.BURIAL, None, bur_date, bur_place, bur_source) bur_ref = EventRef() bur_ref.set_reference_handle(bur.get_handle()) person.add_event_ref(bur_ref) if crem_date: crem = self.create_event(EventType.CREMATION, None, crem_date, bur_place, bur_source) crem_ref = EventRef() crem_ref.set_reference_handle(crem.get_handle()) person.add_event_ref(crem_ref) self.db.commit_person(person, self.trans) return (idx, person)
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 apply_selection(self, *args, **kwargs): # Do not add birth or death event if one exists, no matter what if self.table.treeview.get_model() is None: return with DbTxn("", self.db, batch=True) as self.trans: self.pre_run() source_text = self.options.handler.options_dict['source_text'] select_col = self.table.model_index_of_column[_("Select")] source = self.get_or_create_source(source_text) self.db.disable_signals() self.results_write(_("Selecting... ")) self.progress.set_pass((_("Adding events '%s'...") % source_text), len(self.table.treeview.get_model())) count = 0 for row in self.table.treeview.get_model(): self.progress.step() select = row[select_col] # live select value if not select: continue pupdate = False index = row[0] # order put in row_data = self.table.get_raw_data(index) person = row_data[1] # check, person, action, date1, date2 date1 = row_data[3] # date date2 = row_data[4] # date evidence = row_data[5] # evidence other = row_data[6] # other person if other: other_name = self.sdb.name(other) else: other_name = None add_birth_event, add_death_event = self.action[person.handle] birth_ref = person.get_birth_ref() death_ref = person.get_death_ref() if not birth_ref and add_birth_event: if other_name: explanation = _("Added birth event based on %(evidence)s, from %(name)s") % { 'evidence' : evidence, 'name' : other_name } else: explanation = _("Added birth event based on %s") % evidence modifier = self.get_modifier("birth") birth = self.create_event(_("Estimated birth date"), EventType.BIRTH, date1, source, explanation, modifier) event_ref = EventRef() event_ref.set_reference_handle(birth.get_handle()) person.set_birth_ref(event_ref) pupdate = True count += 1 if not death_ref and add_death_event: if other_name: explanation = _("Added death event based on %(evidence)s, from %(person)s") % { 'evidence' : evidence, 'person' : other_name } else: explanation = _("Added death event based on %s") % evidence modifier = self.get_modifier("death") death = self.create_event(_("Estimated death date"), EventType.DEATH, date2, source, explanation, modifier) event_ref = EventRef() event_ref.set_reference_handle(death.get_handle()) person.set_death_ref(event_ref) pupdate = True count += 1 if pupdate: self.db.commit_person(person, self.trans) self.results_write(_(" Done! Committing...")) self.results_write("\n") self.db.enable_signals() self.db.request_rebuild() self.results_write(_("Added %d events.") % count) self.results_write("\n\n") self.progress.close()
def _parse_person(self, line_number, row, col): "Parse the content of a Person line." surname = rd(line_number, row, col, "surname") firstname = rd(line_number, row, col, "firstname", "") callname = rd(line_number, row, col, "callname") title = rd(line_number, row, col, "title") prefix = rd(line_number, row, col, "prefix") suffix = rd(line_number, row, col, "suffix") gender = rd(line_number, row, col, "gender") source = rd(line_number, row, col, "source") note = rd(line_number, row, col, "note") birthplace = rd(line_number, row, col, "birthplace") birthplace_id = rd(line_number, row, col, "birthplace_id") birthdate = rd(line_number, row, col, "birthdate") birthsource = rd(line_number, row, col, "birthsource") baptismplace = rd(line_number, row, col, "baptismplace") baptismplace_id = rd(line_number, row, col, "baptismplace_id") baptismdate = rd(line_number, row, col, "baptismdate") baptismsource = rd(line_number, row, col, "baptismsource") burialplace = rd(line_number, row, col, "burialplace") burialplace_id = rd(line_number, row, col, "burialplace_id") burialdate = rd(line_number, row, col, "burialdate") burialsource = rd(line_number, row, col, "burialsource") deathplace = rd(line_number, row, col, "deathplace") deathplace_id = rd(line_number, row, col, "deathplace_id") deathdate = rd(line_number, row, col, "deathdate") deathsource = rd(line_number, row, col, "deathsource") deathcause = rd(line_number, row, col, "deathcause") grampsid = rd(line_number, row, col, "grampsid") person_ref = rd(line_number, row, col, "person") ######################################################### # if this person already exists, don't create them person = self.lookup("person", person_ref) if person is None: if surname is None: LOG.warn("empty surname for new person on line %d" % line_number) surname = "" # new person person = self.create_person() name = Name() name.set_type(NameType(NameType.BIRTH)) name.set_first_name(firstname) surname_obj = Surname() surname_obj.set_surname(surname) name.add_surname(surname_obj) person.set_primary_name(name) else: name = person.get_primary_name() ######################################################### if person_ref is not None: self.storeup("person", person_ref, person) # replace if surname is not None: name.get_primary_surname().set_surname(surname) if firstname is not None: name.set_first_name(firstname) if callname is not None: name.set_call_name(callname) if title is not None: name.set_title(title) if prefix is not None: name.get_primary_surname().set_prefix(prefix) name.group_as = '' # HELP? what should I do here? if suffix is not None: name.set_suffix(suffix) if note is not None: # append notes, if previous notes previous_notes_list = person.get_note_list() updated_note = False for note_handle in previous_notes_list: previous_note = self.db.get_note_from_handle(note_handle) if previous_note.type == NoteType.PERSON: previous_text = previous_note.get() if note not in previous_text: note = previous_text + "\n" + note previous_note.set(note) self.db.commit_note(previous_note, self.trans) updated_note = True break if not updated_note: # add new note here new_note = Note() new_note.handle = create_id() new_note.type.set(NoteType.PERSON) new_note.set(note) if self.default_tag: new_note.add_tag(self.default_tag.handle) self.db.add_note(new_note, self.trans) person.add_note(new_note.handle) if grampsid is not None: person.gramps_id = grampsid elif person_ref is not None: if person_ref.startswith("[") and person_ref.endswith("]"): person.gramps_id = self.db.id2user_format(person_ref[1:-1]) if (person.get_gender() == Person.UNKNOWN and gender is not None): gender = gender.lower() if gender == gender_map[Person.MALE].lower(): gender = Person.MALE elif gender == gender_map[Person.FEMALE].lower(): gender = Person.FEMALE else: gender = Person.UNKNOWN person.set_gender(gender) ######################################################### # add if new, replace if different # Birth: if birthdate is not None: birthdate = _dp.parse(birthdate) if birthplace and birthplace_id: raise Error("Error in person: can't have a birthplace and birthplace_id") if birthplace is not None: new, birthplace = self.get_or_create_place(birthplace) elif birthplace_id: # better exist already, locally or in database: birthplace = self.lookup("place", birthplace_id) if birthsource is not None: new, birthsource = self.get_or_create_source(birthsource) if birthdate or birthplace or birthsource: new, birth = self.get_or_create_event(person, EventType.BIRTH, birthdate, birthplace, birthsource) birth_ref = person.get_birth_ref() if birth_ref is None: # new birth_ref = EventRef() birth_ref.set_reference_handle( birth.get_handle()) person.set_birth_ref( birth_ref) # Baptism: if baptismdate is not None: baptismdate = _dp.parse(baptismdate) if baptismplace and baptismplace_id: raise Error("Error in person: can't have a baptismplace and baptismplace_id") if baptismplace is not None: new, baptismplace = self.get_or_create_place(baptismplace) elif baptismplace_id: # better exist already, locally or in database: baptismplace = self.lookup("place", baptismplace_id) if baptismsource is not None: new, baptismsource = self.get_or_create_source(baptismsource) if baptismdate or baptismplace or baptismsource: new, baptism = self.get_or_create_event(person, EventType.BAPTISM, baptismdate, baptismplace, baptismsource) baptism_ref = get_primary_event_ref_from_type(self.db, person, "Baptism") if baptism_ref is None: # new baptism_ref = EventRef() baptism_ref.set_reference_handle( baptism.get_handle()) person.add_event_ref( baptism_ref) # Death: if deathdate is not None: deathdate = _dp.parse(deathdate) if deathplace and deathplace_id: raise Error("Error in person: can't have a deathplace and deathplace_id") if deathplace is not None: new, deathplace = self.get_or_create_place(deathplace) elif deathplace_id: # better exist already, locally or in database: deathplace = self.lookup("place", deathplace_id) if deathsource is not None: new, deathsource = self.get_or_create_source(deathsource) if deathdate or deathplace or deathsource or deathcause: new, death = self.get_or_create_event(person, EventType.DEATH, deathdate, deathplace, deathsource) if deathcause: death.set_description(deathcause) self.db.commit_event(death, self.trans) death_ref = person.get_death_ref() if death_ref is None: # new death_ref = EventRef() death_ref.set_reference_handle(death.get_handle()) person.set_death_ref(death_ref) # Burial: if burialdate is not None: burialdate = _dp.parse(burialdate) if burialplace and burialplace_id: raise Error("Error in person: can't have a burialplace and burialplace_id") if burialplace is not None: new, burialplace = self.get_or_create_place(burialplace) elif burialplace_id: # better exist already, locally or in database: burialplace = self.lookup("place", burialplace_id) if burialsource is not None: new, burialsource = self.get_or_create_source(burialsource) if burialdate or burialplace or burialsource: new, burial = self.get_or_create_event(person, EventType.BURIAL, burialdate, burialplace, burialsource) burial_ref = get_primary_event_ref_from_type(self.db, person, "Burial") if burial_ref is None: # new burial_ref = EventRef() burial_ref.set_reference_handle( burial.get_handle()) person.add_event_ref( burial_ref) if source: # add, if new new, source = self.get_or_create_source(source) self.find_and_set_citation(person, source) self.db.commit_person(person, self.trans)