コード例 #1
0
 def post(self, path):
     if "/" in path:
         handle, action = path.split("/")
     else:
         handle, action = path, "view"
     if handle == "add":
         note = Note()
         note.handle = handle = create_id()
     else:
         note = self.database.get_note_from_handle(handle)
     form = NoteForm(self.database, _, instance=note)
     form.save(handler=self)
     self.redirect("/note/%(handle)s" % {"handle": handle})
コード例 #2
0
 def call_editor(self, obj=None):
     if obj is None:
         note = Note()
         note.set_type(self.get_notetype())
         func = self.obj_added
     else:
         note = obj
         func = self.after_edit
     try:
         EditNote(self.dbstate, self.uistate, self.track,
                      note, func)
     except WindowActiveError:
         pass
コード例 #3
0
    def read_pevent_line(self, event, fields):

        name = fields[2] + fields[1]

        try:
            self.person = self.ikeys[name]
        # check key on {ikey}
        except:
            self.person = "(TO_CHECK: %s)" % fields[1:]
            #GrampsImportError()

        lastname = fields[1]
        firstname = fields[2]
        self.current_person = self.get_or_create_person(firstname, lastname)

        #name = Name()
        #name.set_type(NameType(NameType.BIRTH))
        #name.set_first_name(firstname)
        #surname_obj = name.get_primary_surname()
        #surname_obj.set_surname(surname)
        #self.current_person.set_primary_name(name)

        if pevents_map.get(event[0:5]) == None:
            return  #need to fix custom event types not in the map

        self.current_event = None
        # get events for the current person
        for evr in self.current_person.get_event_ref_list():
            ev = self.db.get_event_from_handle(evr.get_reference_handle())
            if ev.get_type() == pevents_map.get(event[0:5]):
                self.current_event = ev  # found. Need to also check EventRef role
            if not self.current_event:  # No event found create a new one
                self.current_event = self.new_gwplus_pevent(event)
        while True:
            line = self.get_next_line()
            if line and line[0:5] in pevents_map:
                self.current_mode = "person_event"
                self.current_event = self.new_gwplus_pevent(line)
            elif line and line[0:4] == "note":
                n = Note()
                n.set(line[5:])
                self.db.add_note(n, self.trans)
                if self.current_event:
                    self.current_event.add_note(n.handle)
                    self.db.commit_event(self.current_event, self.trans)
                else:
                    print('note', n.handle)
            else:
                self.current_mode = None
                #self.db.commit_person(self.current_person,self.trans)
                break
コード例 #4
0
    def find_or_make_source(self):
        """ Find or create a source.
        returns handle to source."""
        for hndl in self.dbstate.db.get_source_handles():
            if self.dbstate.db.get_raw_source_data(hndl)[2] == 'GeoNames':
                return hndl
        # No source found, lets add one with associated repo and note
        repo = Repository()
        repo.set_name("www.geonames.org")
        rtype = RepositoryType(RepositoryType.WEBSITE)
        repo.set_type(rtype)
        url = Url()
        url.set_path('http://www.geonames.org/')
        url.set_description(_('GeoNames web site'))
        url.set_type(UrlType(UrlType.WEB_HOME))
        repo.add_url(url)
        url = Url()
        url.set_path('*****@*****.**')
        url.set_description(_('GeoNames author'))
        url.set_type(UrlType(UrlType.EMAIL))
        repo.add_url(url)

        note_txt = StyledText(_(
            'GeoNames was founded by Marc Wick. You can reach him at '))
        note_txt += StyledText('*****@*****.**' + '\n')
        note_txt += StyledText(_(
            'GeoNames is a project of Unxos GmbH, Weingartenstrasse 8,'
            ' 8708 Männedorf, Switzerland.\nThis work is licensed under a '))
        note_txt += linkst(
            _('Creative Commons Attribution 3.0 License'),
            'https://creativecommons.org/licenses/by/3.0/legalcode')

        new_note = Note()
        new_note.set_styledtext(note_txt)
        new_note.set_type(NoteType.REPO)
        src = Source()
        src.title = 'GeoNames'
        src.author = 'Marc Wick'
        repo_ref = RepoRef()
        mtype = SourceMediaType(SourceMediaType.ELECTRONIC)
        repo_ref.set_media_type(mtype)
        with DbTxn(_("Add Souce/Repo/Note (%s)") % "GeoNames",
                   self.dbstate.db) as trans:

            self.dbstate.db.add_note(new_note, trans)
            repo.add_note(new_note.get_handle())
            self.dbstate.db.add_repository(repo, trans)
            repo_ref.set_reference_handle(repo.handle)
            src.add_repo_reference(repo_ref)
            self.dbstate.db.add_source(src, trans)
        return src.handle
コード例 #5
0
 def main(self):  # return false finishes
     if self._dirty:
         return
     self.active_person_edit.hide()
     self.active_family_edit.hide()
     self.active_family_label.hide()
     self.note_buffer.set_text(StyledText())
     active_person = self.get_active_object("Person")
     self._dirty_person = active_person
     self._dirty_family = None
     if active_person:
         self.active_person_edit.show()
         self.active_family_edit.hide()
         self.active_family_label.hide()
         # Fill in current person edits:
         name = name_displayer.display(active_person)
         self.active_person_widget.set_text("<i>%s</i> " % name)
         self.active_person_widget.set_use_markup(True)
         # Note:
         self.note = None
         note_list = active_person.get_referenced_note_handles()
         for (classname, note_handle) in note_list:
             note_obj = self.dbstate.db.get_note_from_handle(note_handle)
             if note_obj.get_type() == _("Person Note"):
                 self.note = note_obj
                 break
         if self.note is None:
             self.note = Note()
         self.texteditor.set_text(self.note.get_styledtext())
         self.flow_changed(self.note.get_format())
         # Family button:
         family_list = active_person.get_family_handle_list()
         if len(family_list) > 0:
             self._dirty_family = self.dbstate.db.get_family_from_handle(
                 family_list[0])
             self.active_family_edit.show()
             self.active_family_label.show()
         else:
             family_list = active_person.get_parent_family_handle_list()
             if len(family_list) > 0:
                 self._dirty_family = self.dbstate.db.get_family_from_handle(
                     family_list[0])
                 self.active_family_edit.show()
                 self.active_family_label.show()
     else:
         self.clear_data_entry(None)
         self.active_person_edit.hide()
         self.active_family_edit.hide()
         self.active_family_label.hide()
     self._dirty = False
コード例 #6
0
 def addnote(self, place, notetext, trans, trace):
     "Find a note starting with self.tag (Types:) or create a new and add it to the place"
     for notehandle in place.get_note_list():
         note = self.db.get_note_from_handle(notehandle)
         old_notetext = note.get()
         if old_notetext.startswith(self.tag):
             if trace: print("found old note")
             note.set(notetext)
             self.db.commit_note(note, trans)
             return note
     if trace: print("create a new note")
     note = Note()
     note.set(notetext)
     note_handle = self.db.add_note(note, trans)
     place.add_note(note_handle)
     self.db.commit_note(note, trans)
     return note
コード例 #7
0
    def __init__(self, dbstate, uistate, clicked):
        self.clicked_func = clicked
        self.filter_id = widgets.BasicEntry()
        self.filter_text = widgets.BasicEntry()

        self.note = Note()
        self.note.set_type((NoteType.CUSTOM, ''))
        self.ntype = Gtk.ComboBox(has_entry=True)
        self.event_menu = widgets.MonitoredDataType(self.ntype,
                                                    self.note.set_type,
                                                    self.note.get_type)

        self.filter_regex = Gtk.CheckButton(label=_('Use regular expressions'))

        self.tag = Gtk.ComboBox()
        self.generic = Gtk.ComboBox()

        SidebarFilter.__init__(self, dbstate, uistate, "Note")
コード例 #8
0
 def get(self, path=""):
     """
     HANDLE
     HANDLE/edit|delete
     /add
     b2cfa6ca1e174b1f63d/remove/eventref/1
     """
     page = int(self.get_argument("page", 1))
     search = self.get_argument("search", "")
     if "/" in path:
         handle, action = path.split("/", 1)
     else:
         handle, action = path, "view"
     if handle:
         if handle == "add":
             note = Note()
             action = "edit"
         else:
             note = self.database.get_note_from_handle(handle)
         if note:
             self.render(
                 "note.html",
                 **self.get_template_dict(tview=_("note detail"),
                                          action=action,
                                          page=page,
                                          search=search,
                                          form=NoteForm(self.database,
                                                        _,
                                                        instance=note),
                                          logform=None))
             return
         else:
             self.clear()
             self.set_status(404)
             self.finish("<html><body>No such note</body></html>")
             return
     self.render(
         "page_view.html",
         **self.get_template_dict(
             tview=_("note view"),
             page=page,
             search=search,
             form=NoteForm(self.database, _, table="Note"),
         ))
コード例 #9
0
 def new_clicked(self, obj):
     """
     Create a new To Do note.
     """
     nav_type = self.uistate.viewmanager.active_page.navigation_type()
     active_handle = self.get_active(nav_type)
     if active_handle:
         from gramps.gui.editors import EditNote
         note = Note()
         note.set_type(NoteType.TODO)
         try:
             EditNote(self.gui.dbstate, self.gui.uistate, [], note,
                      self.created)
         except WindowActiveError:
             pass
     else:
         WarningDialog(
             _("No active object"),
             _("First select the object to which you want to attach a note")
             + _(":") + _(nav_type),
             parent=self.uistate.window)
コード例 #10
0
    def add_button_clicked(self, obj):
        """
        Create a new Note instance and call the EditNote editor with the new
        note.

        Called when the Add button is clicked.
        If the window already exists (WindowActiveError), we ignore it.
        This prevents the dialog from coming up twice on the same object.
        """
        note = Note()
        if self.notetype:
            note.set_type(self.notetype)
        try:
            from .. import EditNote
            EditNote(self.dbstate,
                     self.uistate,
                     self.track,
                     note,
                     self.add_callback,
                     self.callertitle,
                     extratype=[self.notetype])
        except WindowActiveError:
            pass
コード例 #11
0
    def _read_notes_lines(self, note_tag):
        note_txt = ""
        while True:
            line = self.get_next_line()
            if line is None:
                break

            fields = line.split(" ")
            if fields[0] == "end" and fields[1] == note_tag:
                break
            elif fields[0] == "beg":
                continue
            else:
                if note_txt:
                    note_txt = note_txt + "\n" + line
                else:
                    note_txt = note_txt + line
        if note_txt:
            n = Note()
            n.set(note_txt)
            self.db.add_note(n, self.trans)
            return n.handle
        return None
コード例 #12
0
ファイル: importcsv.py プロジェクト: dmccubbing/gramps
 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)
コード例 #13
0
ファイル: importcsv.py プロジェクト: dmccubbing/gramps
 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)
コード例 #14
0
ファイル: importcsv.py プロジェクト: dmccubbing/gramps
 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)
コード例 #15
0
    def run(self):
        objects = []
        skipped = 0
        total_objects = 0
        total_notes = 0
        matching_notes = 0
        citations_added = 0
        sources_added = 0
        repos_added = 0
        with self.user.progress(_("Generating citations"), '',
                                self.db.get_total()) as step:

            repos = self.get_repos()
            sources = self.get_sources()
            notes_to_remove = {}
            for classname, obj in self.yield_objects(step):
                total_objects += 1
                obj.classname = classname
                obj.notes = []
                obj.citations = []
                current_citations = None
                for note, m, notehandle in self.find_matching_notes(obj):
                    matching_notes += 1

                    # get a list of current citations; this is in the loop to avoid computing the set for all objects
                    if current_citations is None:
                        current_citations = set()
                        for type, h in obj.get_referenced_citation_handles(
                        ):  # type = 'Citation'
                            citation = self.db.get_citation_from_handle(h)
                            page = citation.get_page()
                            current_citations.add(
                                (page, citation.source_handle))

                    source = sources[m.sourcetitle]
                    source.set_title(m.sourcetitle)

                    if (m.citationpage, source.handle) in current_citations:
                        skipped += 1
                        continue  # already has this citation, skip
                    repo = repos[m.reponame]
                    repo.set_name(m.reponame)

                    source.repo = repo

                    citation = Citation()
                    citation.set_page(m.citationpage)
                    citation.source = source
                    citation.note = m.details

                    obj.citations.append(citation)
                    obj.notes.append(notehandle)

                    notelines = note.get().splitlines()
                    if len(notelines) == 1:
                        notes_to_remove[notehandle] = m
                if obj.notes: objects.append(obj)

            with DbTxn(_("Add citations"), self.db) as trans:
                for obj in objects:
                    self.log("Object {}".format(obj))
                    for citation in obj.citations:
                        source = citation.source
                        repo = source.repo

                        citation_handle = self.db.add_citation(citation, trans)
                        source_handle = self.db.add_source(source, trans)
                        repo_handle = self.db.add_repository(repo, trans)

                        self.log("- Adding citation: {}".format(
                            citation.get_page()))

                        if not hasattr(repo, "in_db"):
                            repos_added += 1
                            self.log("- Adding repo: {}".format(
                                repo.get_name()))
                            repo.in_db = True
                        if not hasattr(source, "in_db"):
                            sources_added += 1
                            self.log("- Adding source: {}".format(
                                source.get_title()))
                            source.in_db = True

                        note = Note()
                        note.set(citation.note)
                        note.set_type(NoteType.LINK)
                        note_handle = self.db.add_note(note, trans)
                        citation.add_note(note_handle)
                        citation.newnote = note

                        citation.set_reference_handle(source_handle)
                        if not source.has_repo_reference(repo_handle):
                            reporef = RepoRef()
                            reporef.set_reference_handle(repo_handle)
                            source.add_repo_reference(reporef)
                        obj.add_citation(citation_handle)
                        citations_added += 1

                    for notehandle in obj.notes:
                        if notehandle in notes_to_remove:
                            obj.remove_note(notehandle)

                    commit_func = self.primary_objects[
                        obj.primary_object_class]['commit_func']
                    commit_func(obj.primary_object, trans)
                    for citation in obj.citations:
                        self.db.commit_citation(citation, trans)
                        self.db.commit_source(citation.source, trans)
                        self.db.commit_repository(source.repo, trans)
                        self.db.commit_note(citation.newnote, trans)

                for notehandle, m in notes_to_remove.items():
                    self.log("Removing note: {} {}".format(
                        repr(notehandle), m.line))
                    self.db.remove_note(notehandle, trans)

            log = []
            log.append(
                _("Total objects processed: {total_objects}").format(
                    total_objects=total_objects))
            log.append("- " + _("Total notes: {total_notes}").format(
                total_notes=self.total_notes))
            log.append("- " + _("Matching notes: {matching_notes}").format(
                matching_notes=matching_notes))
            log.append("- " +
                       _("Unique matching notes: {unique_matching_notes}"
                         ).format(unique_matching_notes=len(notes_to_remove)))
            log.append("- " +
                       _("Skipped notes: {skipped}").format(skipped=skipped))
            log.append("- " + _("Citations added: {citations_added}").format(
                citations_added=citations_added))
            log.append("- " + _("Sources added: {sources_added}").format(
                sources_added=sources_added))
            log.append("- " + _("Repositories added: {repos_added}").format(
                repos_added=repos_added))
            msg = "\n".join(log)
            msg += "\n\n" + _("You can undo all changes with Ctrl-Z.")
            self.log(msg)
            OkDialog(_("All events processed"),
                     msg,
                     parent=self.uistate.window)
コード例 #16
0
 def __add_note(self, text, trans):
     note = Note(text=text)
     self.db.add_note(note, trans)
     return note
コード例 #17
0
    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)
コード例 #18
0
 def add(self, obj):
     try:
         EditNote(self.dbstate, self.uistate, [], Note())
     except WindowActiveError:
         pass
コード例 #19
0
    def _process(self, count, total, sql):
        # ---------------------------------
        # Process note
        # ---------------------------------
        notes = sql.query("""select * from note;""")
        for note in notes:
            (handle, gid, text, _format, note_type1, note_type2, change,
             private) = note
            styled_text = [text, []]
            markups = sql.query(
                """select * from link where from_handle = ? """
                """and to_type = 'markup';""", handle)
            for markup_link in markups:
                _from_type, _from_handle, _to_type, to_handle = markup_link
                markup_detail = sql.query(
                    """select * from markup where handle = ?;""", to_handle)
                for markup in markup_detail:
                    (_mhandle, markup0, markup1, value,
                     start_stop_list) = markup
                    ss_list = eval(start_stop_list)
                    styled_text[1] += [((markup0, markup1), value, ss_list)]

            tags = self.get_links(sql, "note", handle, "tag")

            g_note = Note()
            g_note.unserialize(
                (handle, gid, styled_text, _format, (note_type1, note_type2),
                 change, tags, bool(private)))
            self.db.add_note(g_note, self.trans)
            count += 1
            self.callback(100 * count / total)

        # ---------------------------------
        # Process event
        # ---------------------------------
        events = sql.query("""select * from event;""")
        for event in events:
            (handle, gid, the_type0, the_type1, description, change,
             private) = event

            note_list = self.get_note_list(sql, "event", handle)
            citation_list = self.get_citation_list(sql, "event", handle)
            media_list = self.get_media_list(sql, "event", handle)
            attribute_list = self.get_attribute_list(sql, "event", handle)

            date_handle = self.get_link(sql, "event", handle, "date")
            date = self.get_date(sql, date_handle)

            place_handle = self.get_link(sql, "event", handle, "place")
            place = self.get_place_from_handle(sql, place_handle)

            tags = self.get_links(sql, "event", handle, "tag")
            data = (handle, gid, (the_type0, the_type1), date, description,
                    place, citation_list, note_list, media_list,
                    attribute_list, change, tags, bool(private))

            g_event = Event()
            g_event.unserialize(data)
            self.db.add_event(g_event, self.trans)

            count += 1
            self.callback(100 * count / total)

        # ---------------------------------
        # Process person
        # ---------------------------------
        people = sql.query("""select * from person;""")
        for person in people:
            if person is None:
                continue
            (
                handle,  # 0
                gid,  # 1
                gender,  # 2
                death_ref_handle,  # 5
                birth_ref_handle,  # 6
                change,  # 17
                private,  # 19
            ) = person
            primary_name = self.get_names(sql, "person", handle, True)  # one
            alternate_names = self.get_names(sql, "person", handle, False)
            event_ref_list = self.get_event_ref_list(sql, "person", handle)
            family_list = self.get_family_list(sql, "person", handle)
            parent_family_list = self.get_parent_family_list(
                sql, "person", handle)
            media_list = self.get_media_list(sql, "person", handle)
            address_list = self.get_address_list(sql,
                                                 "person",
                                                 handle,
                                                 with_parish=False)
            attribute_list = self.get_attribute_list(sql, "person", handle)
            urls = self.get_url_list(sql, "person", handle)
            lds_ord_list = self.get_lds_list(sql, "person", handle)
            pcitation_list = self.get_citation_list(sql, "person", handle)
            pnote_list = self.get_note_list(sql, "person", handle)
            person_ref_list = self.get_person_ref_list(sql, "person", handle)
            death_ref_index = lookup(death_ref_handle, event_ref_list)
            birth_ref_index = lookup(birth_ref_handle, event_ref_list)
            tags = self.get_links(sql, "person", handle, "tag")

            data = (
                handle,  # 0
                gid,  # 1
                gender,  # 2
                primary_name,  # 3
                alternate_names,  # 4
                death_ref_index,  # 5
                birth_ref_index,  # 6
                event_ref_list,  # 7
                family_list,  # 8
                parent_family_list,  # 9
                media_list,  # 10
                address_list,  # 11
                attribute_list,  # 12
                urls,  # 13
                lds_ord_list,  # 14
                pcitation_list,  # 15
                pnote_list,  # 16
                change,  # 17
                tags,
                bool(private),  # 19
                person_ref_list,
            )  # 20

            g_pers = Person()
            g_pers.unserialize(data)
            self.db.add_person(g_pers, self.trans)
            count += 1
            self.callback(100 * count / total)
        # ---------------------------------
        # Process family
        # ---------------------------------
        families = sql.query("""select * from family;""")
        for family in families:
            (handle, gid, father_handle, mother_handle, the_type0, the_type1,
             change, private) = family

            child_ref_list = self.get_child_ref_list(sql, "family", handle)
            event_ref_list = self.get_event_ref_list(sql, "family", handle)
            media_list = self.get_media_list(sql, "family", handle)
            attribute_list = self.get_attribute_list(sql, "family", handle)
            lds_seal_list = self.get_lds_list(sql, "family", handle)
            citation_list = self.get_citation_list(sql, "family", handle)
            note_list = self.get_note_list(sql, "family", handle)
            tags = self.get_links(sql, "family", handle, "tag")

            data = (handle, gid, father_handle, mother_handle, child_ref_list,
                    (the_type0, the_type1), event_ref_list, media_list,
                    attribute_list, lds_seal_list, citation_list, note_list,
                    change, tags, private)
            g_fam = Family()
            g_fam.unserialize(data)
            self.db.add_family(g_fam, self.trans)

            count += 1
            self.callback(100 * count / total)
        # ---------------------------------
        # Process repository
        # ---------------------------------
        repositories = sql.query("""select * from repository;""")
        for repo in repositories:
            (handle, gid, the_type0, the_type1, name, change, private) = repo

            note_list = self.get_note_list(sql, "repository", handle)
            address_list = self.get_address_list(sql,
                                                 "repository",
                                                 handle,
                                                 with_parish=False)
            urls = self.get_url_list(sql, "repository", handle)
            tags = self.get_links(sql, "repository", handle, "tag")
            data = (handle, gid, (the_type0, the_type1), name, note_list,
                    address_list, urls, change, tags, private)
            g_rep = Repository()
            g_rep.unserialize(data)
            self.db.add_repository(g_rep, self.trans)
            count += 1
            self.callback(100 * count / total)
        # ---------------------------------
        # Process place
        # ---------------------------------
        places = sql.query("""select * from place;""")
        for place in places:
            count += 1
            (handle, gid, title, value, the_type0, the_type1, code, long, lat,
             lang, change, private) = place

            # We could look this up by "place_main", but we have the handle:
            #main_loc = self.get_main_location(sql, handle, with_parish=True)
            alt_loc_list = self.get_location_list(sql,
                                                  "place_alt",
                                                  handle,
                                                  with_parish=True)
            urls = self.get_url_list(sql, "place", handle)
            media_list = self.get_media_list(sql, "place", handle)
            citation_list = self.get_citation_list(sql, "place", handle)
            note_list = self.get_note_list(sql, "place", handle)
            tags = self.get_links(sql, "place", handle, "tag")
            place_type = (the_type0, the_type1)
            alt_place_name_list = self.get_alt_place_name_list(sql, handle)
            place_ref_list = self.get_place_ref_list(sql, handle)
            data = (handle, gid, title, long, lat, place_ref_list,
                    PlaceName(value=value,
                              lang=lang).serialize(), alt_place_name_list,
                    place_type, code, alt_loc_list, urls, media_list,
                    citation_list, note_list, change, tags, private)
            g_plac = Place()
            g_plac.unserialize(data)
            self.db.commit_place(g_plac, self.trans)
            self.callback(100 * count / total)

        # ---------------------------------
        # Process citation
        # ---------------------------------
        citations = sql.query("""select * from citation;""")
        for citation in citations:
            (handle, gid, confidence, page, source_handle, change,
             private) = citation
            date_handle = self.get_link(sql, "citation", handle, "date")
            date = self.get_date(sql, date_handle)
            note_list = self.get_note_list(sql, "citation", handle)
            media_list = self.get_media_list(sql, "citation", handle)
            datamap = self.get_datamap_list(sql, "citation", handle)
            tags = self.get_links(sql, "citation", handle, "tag")
            data = (handle, gid, date, page, confidence, source_handle,
                    note_list, media_list, datamap, change, tags, private)
            g_cit = Citation()
            g_cit.unserialize(data)
            self.db.commit_citation(g_cit, self.trans)
            count += 1
            self.callback(100 * count / total)

        # ---------------------------------
        # Process source
        # ---------------------------------
        sources = sql.query("""select * from source;""")
        for source in sources:
            (handle, gid, title, author, pubinfo, abbrev, change,
             private) = source
            note_list = self.get_note_list(sql, "source", handle)
            media_list = self.get_media_list(sql, "source", handle)
            datamap = self.get_datamap_list(sql, "source", handle)
            reporef_list = self.get_repository_ref_list(sql, "source", handle)
            tags = self.get_links(sql, "source", handle, "tag")

            data = (handle, gid, title, author, pubinfo, note_list, media_list,
                    abbrev, change, datamap, reporef_list, tags, private)
            g_src = Source()
            g_src.unserialize(data)
            self.db.commit_source(g_src, self.trans)
            count += 1
            self.callback(100 * count / total)
        # ---------------------------------
        # Process media
        # ---------------------------------
        media = sql.query("""select * from media;""")
        for med in media:
            (handle, gid, path, mime, desc, checksum, change, private) = med

            attribute_list = self.get_attribute_list(sql, "media", handle)
            citation_list = self.get_citation_list(sql, "media", handle)
            note_list = self.get_note_list(sql, "media", handle)

            date_handle = self.get_link(sql, "media", handle, "date")
            date = self.get_date(sql, date_handle)
            tags = self.get_links(sql, "media", handle, "tag")

            data = (handle, gid, path, mime, desc, checksum, attribute_list,
                    citation_list, note_list, change, date, tags, private)
            g_med = Media()
            g_med.unserialize(data)
            self.db.commit_media(g_med, self.trans)
            count += 1
            self.callback(100 * count / total)
        # ---------------------------------
        # Process tag
        # ---------------------------------
        tags = sql.query("""select * from tag;""")
        for tag in tags:
            (handle, name, color, priority, change) = tag

            data = (handle, name, color, priority, change)
            g_tag = Tag()
            g_tag.unserialize(data)
            self.db.commit_tag(g_tag, self.trans)
            count += 1
            self.callback(100 * count / total)