Beispiel #1
0
    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
Beispiel #2
0
    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
Beispiel #3
0
 def _parse_family(self, line_number, row, col):
     "Parse the content of a family line"
     family_ref = rd(line_number, row, col, "family")
     if family_ref is None:
         LOG.warn("no family reference found for family on line %d" %
                  line_number)
         return  # required
     child = rd(line_number, row, col, "child")
     source = rd(line_number, row, col, "source")
     note = rd(line_number, row, col, "note")
     gender = rd(line_number, row, col, "gender")
     child = self.lookup("person", child)
     family = self.lookup("family", family_ref)
     if family is None:
         LOG.warn("no matching family reference found for family "
                  "on line %d" % line_number)
         return
     if child is None:
         LOG.warn("no matching child reference found for family "
                  "on line %d" % line_number)
         return
     # is this child already in this family? If so, don't add
     LOG.debug("children: %s",
               [ref.ref for ref in family.get_child_ref_list()])
     LOG.debug("looking for: %s", child.get_handle())
     if child.get_handle() not in [
             ref.ref for ref in family.get_child_ref_list()
     ]:
         # add child to family
         LOG.debug("   adding child [%s] to family [%s]",
                   child.get_gramps_id(), family.get_gramps_id())
         childref = ChildRef()
         childref.set_reference_handle(child.get_handle())
         family.add_child_ref(childref)
         self.db.commit_family(family, self.trans)
         child.add_parent_family_handle(family.get_handle())
     if gender:
         # replace
         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
         child.set_gender(gender)
     if source:
         # add, if new
         dummy_new, source = self.get_or_create_source(source)
         self.find_and_set_citation(child, source)
     # put note on child
     if note:
         # append notes, if previous notes
         previous_notes_list = child.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)
             child.add_note(new_note.handle)
     self.db.commit_person(child, self.trans)
Beispiel #4
0
 def _parse_family(self, line_number, row, col):
     "Parse the content of a family line"
     family_ref   = rd(line_number, row, col, "family")
     if family_ref is None:
         LOG.warn("no family reference found for family on line %d" %
                  line_number)
         return # required
     child   = rd(line_number, row, col, "child")
     source  = rd(line_number, row, col, "source")
     note  = rd(line_number, row, col, "note")
     gender  = rd(line_number, row, col, "gender")
     child = self.lookup("person", child)
     family = self.lookup("family", family_ref)
     if family is None:
         LOG.warn("no matching family reference found for family "
                  "on line %d" % line_number)
         return
     if child is None:
         LOG.warn("no matching child reference found for family "
                  "on line %d" % line_number)
         return
     # is this child already in this family? If so, don't add
     LOG.debug("children: %s", [ref.ref for ref in
                                family.get_child_ref_list()])
     LOG.debug("looking for: %s", child.get_handle())
     if child.get_handle() not in [ref.ref for ref in
                                   family.get_child_ref_list()]:
         # add child to family
         LOG.debug("   adding child [%s] to family [%s]",
                   child.get_gramps_id(), family.get_gramps_id())
         childref = ChildRef()
         childref.set_reference_handle(child.get_handle())
         family.add_child_ref( childref)
         self.db.commit_family(family, self.trans)
         child.add_parent_family_handle(family.get_handle())
     if gender:
         # replace
         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
         child.set_gender(gender)
     if source:
         # add, if new
         dummy_new, source = self.get_or_create_source(source)
         self.find_and_set_citation(child, source)
     # put note on child
     if note:
         # append notes, if previous notes
         previous_notes_list = child.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)
             child.add_note(new_note.handle)
     self.db.commit_person(child, self.trans)