Example #1
0
    def __init__(self, dbstate, uistate, clicked):
        self.clicked_func = clicked
        self.filter_id = widgets.BasicEntry()
        self.filter_title = widgets.BasicEntry()
        self.filter_address = widgets.BasicEntry()
        self.filter_url = widgets.BasicEntry()

        self.repo = Repository()
        self.repo.set_type((RepositoryType.CUSTOM, ''))
        self.rtype = Gtk.ComboBox(has_entry=True)
        self.event_menu = widgets.MonitoredDataType(
            self.rtype,
            self.repo.set_type,
            self.repo.get_type,
            False,  # read-only?
            dbstate.db.get_repository_types())

        self.filter_note = widgets.BasicEntry()

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

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

        SidebarFilter.__init__(self, dbstate, uistate, "Repository")
Example #2
0
 def add_button_clicked(self, obj):
     from .. import EditRepoRef
     ref = RepoRef()
     repo = Repository()
     try:
         EditRepoRef(self.dbstate, self.uistate, self.track, repo, ref,
                     self.add_callback)
     except WindowActiveError:
         pass
Example #3
0
    def _add_repository(self):
        # Add a Repository

        with DbTxn("Add Repository", self._db) as tran:
            repos = Repository()
            self._db.add_repository(repos, tran)
            self._db.commit_repository(repos, tran)

        return repos
    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
Example #5
0
 def post(self, path):
     if "/" in path:
         handle, action = path.split("/")
     else:
         handle, action = path, "view"
     if handle == "add":
         repository = Repository()
         repository.handle = handle = create_id()
     else:
         repository = self.database.get_repository_from_handle(handle)
     form = RepositoryForm(self.database, _, instance=repository)
     form.save(handler=self)
     self.redirect("/repository/%(handle)s" % {"handle": handle})
Example #6
0
 def addRepository(repositoryName, reftag):
     ridno = db.find_next_repository_gramps_id()
     repository = Repository()
     repositoryType = RepositoryType()
     repositoryType.set(RepositoryType.ARCHIVE)
     repository.set_type(repositoryType)
     repository.set_gramps_id(ridno)
     repository.set_name(repositoryName)
     repository.set_url_list(())
     repository.set_change_time(chgtime)
     if reftag != None:
         repository.add_tag(reftag.get_handle())
     with DbTxn(_("Add Repository"), db) as trans:
         rhandle = db.add_repository(repository, trans)
     return repository
Example #7
0
    def buildRepository(self, ridno, rname, tag, rtype, rhandle=None):
        if rhandle == None:
            rhandle = id.create_id()  # 26-merkkinen tunniste
        repositoryType = RepositoryType()
        repositoryType.set(rtype)

        repository = Repository()
        repository.set_type(repositoryType)
        repository.set_handle(rhandle)
        repository.set_gramps_id(ridno)
        repository.set_name(rname)
        repository.set_change_time(self.chgtime)
        #       repository.set_color("#000000")
        repository.add_tag(tag.get_handle())
        #        print ("Repository ") ; print(repository.to_struct())
        return ([repository, rhandle])
Example #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":
             repository = Repository()
             action = "edit"
         else:
             repository = self.database.get_repository_from_handle(handle)
         if repository:
             self.render(
                 "repository.html",
                 **self.get_template_dict(tview=_("repository detail"),
                                          action=action,
                                          page=page,
                                          search=search,
                                          form=RepositoryForm(
                                              self.database,
                                              _,
                                              instance=repository),
                                          logform=None))
             return
         else:
             self.clear()
             self.set_status(404)
             self.finish("<html><body>No such repository</body></html>")
             return
     self.render(
         "page_view.html",
         **self.get_template_dict(
             tview=_("repository view"),
             page=page,
             search=search,
             form=RepositoryForm(self.database, _, table="Repository"),
         ))
Example #9
0
 def addRepository(repositoryName, repositoryUrl, reftag):
     ridno = db.find_next_repository_gramps_id()
     repository = Repository()
     repositoryType = RepositoryType()
     repositoryType.set(RepositoryType.ARCHIVE)
     repository.set_type(repositoryType)
     repository.set_gramps_id(ridno)
     repository.set_name(repositoryName)
     urlList = []
     #        for urlPath in repositoryUrls:
     url = Url()
     url.set_path(repositoryUrl)
     url.set_description('Sshy')
     url.set_type(UrlType.WEB_HOME)
     urlList.append(url)
     repository.set_url_list(urlList)
     repository.set_change_time(chgtime)
     if reftag != None:
         repository.add_tag(reftag.get_handle())
     with DbTxn(_("Add Repository"), db) as trans:
         rhandle = db.add_repository(repository, trans)
     return repository
Example #10
0
 def empty_object(self):
     return Repository()
Example #11
0
 def add(self, *obj):
     EditRepository(self.dbstate, self.uistate, [], Repository())
Example #12
0
def importSourceHierarchies(db, filename, user):
    def findNextRidno(ridstrt):
        with DbTxn(_("Find next ridno"), db):
            prefix_save = db.get_repository_prefix()
            db.set_repository_id_prefix(ridstrt + '%05d')
            next_ridno = db.find_next_repository_gramps_id()
            LOG.debug('Next ridno = ' + next_ridno)
            db.set_repository_id_prefix(prefix_save)
        return next_ridno

    def findNextSidno(ridno):
        with DbTxn(_("Find next sidno"), db):
            prefix_save = db.get_source_prefix()
            db.set_source_id_prefix(ridno + '%05d')
            next_sidno = db.find_next_source_gramps_id()
            LOG.debug('Next sidno = ' + next_sidno)
            db.set_source_id_prefix(prefix_save)
        return next_sidno

    def checkTagExistence(otext):
        with DbTxn(_("Read Tag"), db):
            tag = db.get_tag_from_name(otext)
        if tag != None:
            LOG.debug('Tag found by name, no duplicates: ' + otext + ' ' +
                      tag.get_name())
        else:
            tag = Tag()
            tag.set_name(otext)
            tag.set_color("#EF2929")
            with DbTxn(_("Add Tag"), db) as trans:
                thandle = db.add_tag(tag, trans)
                LOG.debug('Tag added: ' + tag.get_name() + ' ' + thandle)
        return tag

    fdir = os.path.dirname(filename)

    fh = logging.FileHandler(fdir + '\\sourceimport.log')
    formatter = logging.Formatter(
        '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    fh.setLevel(logging.DEBUG)
    fh.setFormatter(formatter)
    LOG.addHandler(fh)

    LOG.info("   fdir = " + fdir)
    cout = fdir + "\\sresult.csv"
    LOG.debug('ini file handling')

    config = configman.register_manager("importsources")
    '''
    config.register("options.repositoryidrng", "1000")    
    config.register("options.repositoryincr", "1") 
    config.register("options.sourceidrng", "1000")    
    config.register("options.sourceidincr", "1") 
    '''
    config.register("options.refstring", "r")

    config.load()
    config.save()
    '''     
    repository_idrange = int(config.get('options.repositoryidrng'))
    repository_incr = int(config.get('options.repositoryincr'))
    source_idrange = int(config.get('options.sourceidrng'))
    source_idincr = int(config.get('options.sourceidincr'))
    '''
    refstr = config.get('options.refstring')
    '''
    repository_idno  = 0
    source_idno = 0
    '''

    t_count = 0
    r_count = 0
    s_count = 0
    c_count = 0
    u_count = 0

    ridno = None
    sidno = None

    reftext = 'Referenssi'
    reftag = checkTagExistence(reftext)

    chgtime = int(time.time())
    LOG.info("   chgtime = " + str(chgtime))

    try:
        with open(cout, 'w', newline='\n', encoding="utf-8-sig") as csv_out:
            #            csv_out.write(u'\uFEFF')        #   utf-8-bom
            r_writer = csv.writer(csv_out, delimiter=';')

            with open(filename, 'r', encoding="utf-8-sig") as t_in:
                rhandle = None
                t_dialect = csv.Sniffer().sniff(t_in.read(1024))
                t_in.seek(0)
                t_reader = csv.reader(t_in, t_dialect)
                LOG.info('CSV input file delimiter is ' + t_dialect.delimiter)
                for row in t_reader:

                    rectype = row[
                        0]  # Record type = Gramps object id prefix character
                    #                    LOG.debug('Row type: -' + row[0] + '-')

                    if rectype == '#':
                        LOG.debug('Comment row: ' + row[0])
                        c_count += 1
                        r_writer.writerow([
                            row[0], row[1], row[2], row[3], row[4], row[5],
                            row[6], row[7]
                        ])

                    else:
                        idno = row[
                            2]  # Possibly previously assigned Gramps object id
                        handle = row[3].strip(
                            '"'
                        )  # Possibly previously assigned Gramps object handle
                        otext = row[4].strip()
                        LOG.debug('Handle = ' + handle)
                        '''                    
                        if rectype == 'T':
                            LOG.debug('Tag row: ' + row[0])
                            thandle = ''
                            t_count += 1
                            recobj  = row[1]     # Tag related to repositories or sources
                            tag = None
                            with DbTxn(_("Read Tag"), db):
                                tag = db.get_tag_from_name(otext)
                            if tag != None: 
                                LOG.info('Tag found by name, no duplicates: ' + otext + ' ' + tag.get_name())       
                                thandle = tag.get_handle()
                            else:       
                                tag = Tag()                  
                                tag.set_name(otext)
                                tag.set_change_time(chgtime)
                                tag.set_color("#EF2929")
                                with DbTxn(_("Add Tag"), db) as trans:
                                    thandle = db.add_tag(tag, trans)
                                    LOG.info('Tag added: ' + tag.get_name() + ' ' + thandle)
                            tags[recobj] = tag
                            try: 
                                r_writer.writerow([rectype, recobj, '', '"' + thandle + '"', otext, '', '', '', ''])
                            except IOError:    
                                LOG.error('Error writing T-csv '  + IOError.strerror) 
                        '''

                        if rectype == 'R':
                            LOG.debug('Repository row: ' + row[0])
                            rhandle = ''
                            #                            source_idno = 0
                            r_count += 1
                            repotype = row[1]  # repository type number
                            if idno == '':
                                if refstr == 'r':
                                    # repository type based numbering should be applied but not supplied by Gramps
                                    ridno = findNextRidno(rectype + refstr +
                                                          '9')
#                                   repository_idno = repository_idno + repository_incr
#                                   ridno = rectype + refstr + str(int(repotype) * repository_idrange + repository_idno)
                                else:
                                    ridno = db.find_next_repository_gramps_id()

                            else:
                                ridno = idno
                            LOG.debug('Ridno = ' + str(ridno))
                            repository = Repository()
                            if handle != '':
                                with DbTxn(_("Read Repository"), db) as trans:
                                    repository = db.get_repository_from_handle(
                                        handle)
                                    if repository == None:
                                        LOG.error(
                                            'Repository NOT found by handle: '
                                            + handle + ' ' + otext)
                                        raise GrampsImportError(
                                            'Repository NOT found by handle: ',
                                            handle + '/' + otext)
                            repositoryType = RepositoryType()
                            repositoryType.set(int(repotype))
                            repository.set_type(repositoryType)
                            repository.set_gramps_id(ridno)
                            repository.set_name(otext)
                            repository.set_change_time(chgtime)
                            if reftag != None:
                                repository.add_tag(reftag.get_handle())
                            if handle == '':
                                with DbTxn(_("Add Repository"), db) as trans:
                                    rhandle = db.add_repository(
                                        repository, trans)
                            else:
                                with DbTxn(_("Update Repository"),
                                           db) as trans:
                                    db.commit_repository(repository, trans)
                                    rhandle = handle
                            try:
                                r_writer.writerow([
                                    rectype, repotype, ridno,
                                    '"' + rhandle + '"', otext, '', '', '', ''
                                ])
                            except IOError:
                                LOG.error('Error writing R-csv ' +
                                          IOError.strerror)

                        elif rectype == 'S':
                            LOG.debug('Source row: ' + row[0])
                            shandle = ''
                            sidno = ''
                            s_count += 1
                            attribs = (row[5], row[6], row[7])

                            if idno == '':
                                LOG.debug('Ridno for sidno = ' + str(ridno))
                                if refstr == 'r':
                                    # repository type based numbering should be applied but not supplied by Gramps
                                    sidno = findNextSidno(rectype + refstr +
                                                          '9')
#                                   source_idno = source_idno + source_idincr
#                                   sidno = rectype + refstr + str((int(repotype) * repository_idrange + repository_idno) * source_idrange + source_idno)
                                else:
                                    sidno = db.find_next_source_gramps_id()
                            else:
                                sidno = idno
                            LOG.debug('Sidno = ' + str(sidno))
                            source = Source()
                            if handle != '':
                                with DbTxn(_("Read Source"), db) as trans:
                                    source = db.get_source_from_handle(handle)
                                    if source == None:
                                        LOG.error(
                                            'Source NOT found by handle: ' +
                                            handle + ' ' + otext)
                                        raise GrampsImportError(
                                            'Source NOT found by handle: ',
                                            handle + '/' + otext)
                            source.set_gramps_id(sidno)
                            source.set_title(otext)
                            source.set_author(attribs[0])
                            source.set_publication_info(attribs[1])
                            source.set_abbreviation(attribs[2])
                            if reftag != None:
                                source.add_tag(reftag.get_handle())
                            repoRef = RepoRef()
                            repoRef.set_reference_handle(rhandle)
                            source.add_repo_reference(repoRef)
                            source.set_change_time(chgtime)
                            if handle == '':
                                with DbTxn(_("Add Source"), db) as trans:
                                    shandle = db.add_source(source, trans)
                            else:
                                with DbTxn(_("Update Source"), db) as trans:
                                    db.commit_source(source, trans)
                                    shandle = handle
                            try:
                                r_writer.writerow([
                                    rectype, '', sidno, '"' + shandle + '"',
                                    otext, attribs[0], attribs[1], attribs[2],
                                    ''
                                ])
                            except IOError:
                                LOG.error('Error writing S-csv ' +
                                          IOError.strerror)

                        else:
                            u_count += 1
                            LOG.debug('Unknown rectype: ' + rectype)
                            raise GrampsImportError('Unknown record type ' +
                                                    rectype)

    except:
        exc = sys.exc_info()[0]
        LOG.error('*** Something went really wrong! ', exc)

        return ImportInfo({_('Results'): _('Something went really wrong  ')})

    results = {
        _('Results'):
        _('Input file handled.'),
        _('    Repositories   '):
        str(r_count),
        _('    Sources        '):
        str(s_count),
        _('    Comments       '):
        str(c_count),
        _('    Unknown types  '):
        str(u_count),
        _('  Total            '):
        str(t_count + r_count + s_count + c_count + u_count)
    }

    LOG.info('Input file handled.')
    LOG.info('    Repositories   ' + str(r_count))
    LOG.info('    Sources        ' + str(s_count))
    LOG.info('    Comments       ' + str(c_count))
    LOG.info('    Unknown types  ' + str(u_count))
    LOG.info('  Total            ' +
             str(t_count + r_count + s_count + c_count + u_count))

    db.enable_signals()
    db.request_rebuild()

    return ImportInfo(results)
Example #13
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)