当前位置: 首页>>代码示例>>Python>>正文


Python Name.set_first_name方法代码示例

本文整理汇总了Python中gramps.gen.lib.Name.set_first_name方法的典型用法代码示例。如果您正苦于以下问题:Python Name.set_first_name方法的具体用法?Python Name.set_first_name怎么用?Python Name.set_first_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gramps.gen.lib.Name的用法示例。


在下文中一共展示了Name.set_first_name方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run_tool

# 需要导入模块: from gramps.gen.lib import Name [as 别名]
# 或者: from gramps.gen.lib.Name import set_first_name [as 别名]

#.........这里部分代码省略.........
        #        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()
开发者ID:nblock,项目名称:gramps,代码行数:104,代码来源:dateparserdisplaytest.py

示例2: parse_person

# 需要导入模块: from gramps.gen.lib import Name [as 别名]
# 或者: from gramps.gen.lib.Name import set_first_name [as 别名]
    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()
#.........这里部分代码省略.........
开发者ID:ewongbb,项目名称:gramps,代码行数:103,代码来源:importgeneweb.py

示例3: _parse_person

# 需要导入模块: from gramps.gen.lib import Name [as 别名]
# 或者: from gramps.gen.lib.Name import set_first_name [as 别名]
 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
#.........这里部分代码省略.........
开发者ID:tecknicaltom,项目名称:gramps,代码行数:103,代码来源:importcsv.py


注:本文中的gramps.gen.lib.Name.set_first_name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。