def set_person_attribute(self, person, record_id): attr_name = 'Ancestry APID H:{}'.format(self._dbid) existing_attrs = [a for a in person.get_attribute_list() if(str(a.get_type()) == attr_name)] if existing_attrs: existing_attrs[0].set_value(str(record_id)) for extra_attr in existing_attrs[1:]: person.remove_attribute(extra_attr) else: attr = Attribute() attr.set_type(attr_name) attr.set_value(str(record_id)) person.add_attribute(attr) with DbTxn(_("Setting Ancestry Record ID"), self.dbstate.db) as trans: self.dbstate.db.commit_person(person, trans)
def generate_md5(self, button): """ Generate md5 hashes for media files and attach them as attributes to media objects. """ self.clear_models() progress = ProgressMeter(self.window_name, can_cancel=True, parent=self.window) length = self.db.get_number_of_media_objects() progress.set_pass(_('Generating media hashes'), length) with DbTxn(_("Set media hashes"), self.db, batch=True) as trans: for handle in self.db.get_media_object_handles(): media = self.db.get_object_from_handle(handle) full_path = media_path_full(self.db, media.get_path()) try: with io.open(full_path, 'rb') as media_file: md5sum = hashlib.md5(media_file.read()).hexdigest() except IOError as err: error_msg = '%s: %s' % (err.strerror, full_path) self.models[5].append((error_msg, None)) progress.step() continue for attr in media.get_attribute_list(): if str(attr.get_type()) == 'md5': media.remove_attribute(attr) break attr = Attribute() attr.set_type(AttributeType('md5')) attr.set_value(md5sum) media.add_attribute(attr) self.db.commit_media_object(media, trans) progress.step() if progress.get_cancelled(): break self.show_tabs() progress.close()
def add_button_clicked(self, obj): pname = '' attr = Attribute() try: self.get_editor()(self.dbstate, self.uistate, self.track, attr, pname, self.get_user_values(), self.add_callback) except WindowActiveError: pass
def save(self): """ Save the census headings to the database. """ new_list = [] for attr in self.event.get_attribute_list(): if attr.get_type() not in self.heading_list: new_list.append(attr) for row in self.model: if row[1]: attr = Attribute() attr.set_type(row[0]) attr.set_value(row[1]) new_list.append(attr) self.event.set_attribute_list(new_list)
def set_attribute(event_ref, attrs, name, value): """ Set a named attribute to a given value. Create the attribute if it does not already exist. Delete it if the value is None or ''. """ attr = get_attribute(attrs, name) if attr is None: if value: # Add attr = Attribute() attr.set_type(name) attr.set_value(value) if name == ORDER_ATTR: attr.set_privacy(True) event_ref.add_attribute(attr) else: if not value: # Remove event_ref.remove_attribute(attr) elif attr.get_value() != value: # Update attr.set_value(value)
def save(self): """ Save the form headings to the database. """ new_list = [] for attr in self.event.get_attribute_list(): if attr.get_type() not in self.heading_list: new_list.append(attr) for row in self.model: if row[1]: attr = Attribute() attr.set_type(row[0]) attr.set_value(row[1]) attr.add_citation(self.citation.handle) new_list.append(attr) self.event.set_attribute_list(new_list)
def set_attribute(citation, event_ref, name, value): """ Set a named attribute to a given value. Create the attribute if it does not already exist. Delete it if the value is None or ''. """ attrs = event_ref.get_attribute_list() attr = get_attribute(attrs, name) if attr is None: if value: # Add attr = Attribute() attr.set_type(name) attr.set_value(value) attr.add_citation(citation.handle) if name == ORDER_ATTR: attr.set_privacy(True) event_ref.add_attribute(attr) else: if not value: # Remove event_ref.remove_attribute(attr) elif attr.get_value() != value: # Update attr.set_value(value)
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)