def get_or_create_source(self, source_text): source_list = self.db.get_source_handles() for source_handle in source_list: source = self.db.get_source_from_handle(source_handle) if source.get_title() == source_text: return source source = Source() source.set_title(source_text) self.db.add_source(source, self.trans) return source
def call_editor(self, obj=None): if obj is None: source = Source() func = self.obj_added else: source = obj func = self.after_edit try: EditSource(self.dbstate, self.uistate, self.track, source, func) except WindowActiveError: pass
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
def post(self, path): if "/" in path: handle, action = path.split("/") else: handle, action = path, "view" if handle == "add": source = Source() source.handle = handle = create_id() else: source = self.database.get_source_from_handle(handle) form = SourceForm(self.database, _, instance=source) form.save(handler=self) self.redirect("/source/%(handle)s" % {"handle": handle})
def on_ok_clicked(self): """ Method that is run when you click the OK button. The numbers of sources and citations are retrieved from the entry box and used to govern the amount of data generated """ num_sources_text = self.sources_entry.get_text() try: num_sources = int(num_sources_text) except: return num_citations_text = self.citations_entry.get_text() num_citations = int(num_citations_text) self.progress = ProgressMeter( 'Generating data', '') self.progress.set_pass('Generating data', num_sources*num_citations) LOG.debug("sources %04d citations %04d" % (num_sources, num_citations)) source = Source() citation = Citation() self.db.disable_signals() with DbTxn('Populate sources and citations', self.db) as trans: for i in range(num_sources): source.gramps_id = None source.handle = None source.title = "Source %04d" % (i + 1) source_handle = self.db.add_source(source, trans) for j in range(num_citations): citation.gramps_id = None citation.handle = None citation.source_handle = source_handle citation.page = "Page %04d" % (j + 1) self.db.add_citation(citation, trans) self.progress.step() LOG.debug("sources and citations added") self.db.enable_signals() self.db.request_rebuild() self.progress.close() self.options.handler.options_dict['sources'] = num_sources self.options.handler.options_dict['citations'] = num_citations # Save options self.options.handler.save_options()
def add_button_clicked(self, obj): """ Create a new Citation instance and call the EditCitation editor with the new citation. 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. """ try: from .. import EditCitation EditCitation(self.dbstate, self.uistate, self.track, Citation(), Source(), self.add_callback, self.callertitle) except WindowActiveError: pass
def get_or_create_source(self, source_name): source = None if source_name in self.skeys: source = self.db.get_source_from_handle(self.skeys[source_name]) else: source = Source() source.set_title(source_name) self.db.add_source(source, self.trans) self.db.commit_source(source, self.trans) self.skeys[source_name] = source.get_handle() citation = Citation() citation.set_reference_handle(source.get_handle()) self.db.add_citation(citation, self.trans) self.db.commit_citation(citation, self.trans) return citation
def get_or_create_source(self, source_text): "Return the requested source object tuple-packed with a new indicator." source_list = self.db.get_source_handles(sort_handles=False) LOG.debug("get_or_create_source: list: %s", source_list) LOG.debug("get_or_create_source: looking for: %s", source_text) for source_handle in source_list: source = self.db.get_source_from_handle(source_handle) if source.get_title() == source_text: LOG.debug(" returning existing source") return (0, source) LOG.debug(" creating source") source = Source() source.set_title(source_text) self.db.add_source(source, self.trans) return (1, source)
def _add_source(self, repos=None): # Add a Source with DbTxn("Add Source and Citation", self._db) as tran: source = Source() if repos is not None: repo_ref = RepoRef() repo_ref.set_reference_handle(repos.get_handle()) source.add_repo_reference(repo_ref) self._db.add_source(source, tran) self._db.commit_source(source, tran) citation = Citation() citation.set_reference_handle(source.get_handle()) self._db.add_citation(citation, tran) self._db.commit_citation(citation, tran) return citation
def buildSource(self, sidno, stitle, tag, repository, shandle, attribs): if shandle == None: shandle = id.create_id() # 26-merkkinen tunniste # repositoryType = RepositoryType() source = Source() source.set_handle(shandle) source.set_gramps_id(sidno) source.set_title(stitle) source.set_author(attribs[0]) source.set_publication_info(attribs[1]) source.set_abbreviation(attribs[2]) source.add_tag(tag.get_handle()) repoRef = RepoRef() repoRef.set_reference_handle(repository.get_handle()) source.add_repo_reference(repoRef) source.set_change_time(self.chgtime) # source.set_color("#000000") # print ("Source ") ; print(source.to_struct()) return ([source, shandle])
def addSource(sourceName, attribs, reftag, repository): snote = addNote(attribs[3], NoteType.SOURCE) sidno = db.find_next_source_gramps_id() source = Source() source.set_gramps_id(sidno) source.set_title(sourceName) source.set_author(attribs[0]) source.set_publication_info(attribs[1]) source.set_abbreviation(attribs[2]) source.add_note(snote.get_handle()) if reftag != None: source.add_tag(reftag.get_handle()) repoRef = RepoRef() repoRef.set_reference_handle(repository.get_handle()) source.add_repo_reference(repoRef) source.set_change_time(chgtime) with DbTxn(_("Add Source"), db) as trans: shandle = db.add_source(source, trans) return source
def add_source(self, obj): """ add_source: Add a new source (this is also available from the source view) Create a new Source instance and call the EditSource editor with the new source. Called when the Add_source button is clicked. If the window already exists (WindowActiveError), we ignore it. This prevents the dialog from coming up twice on the same object. However, since the window is identified by the Source object, and we have just created a new one, it seems to be impossible for the window to already exist, so this is just an extra safety measure. """ try: EditSource(self.dbstate, self.uistate, [], Source()) except WindowActiveError: pass
def add(self, *obj): """ add: Add a new citation and a new source (this can also be done by source view add a source, then citation view add a new citation to an existing source) Create a new Source instance and Citation instance and call the EditCitation editor with the new source and new citation. 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. However, since the window is identified by the Source object, and we have just created a new one, it seems to be impossible for the window to already exist, so this is just an extra safety measure. """ try: EditCitation(self.dbstate, self.uistate, [], Citation(), Source()) except WindowActiveError: pass
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": source = Source() action = "edit" else: source = self.database.get_source_from_handle(handle) if source: self.render("source.html", **self.get_template_dict(tview=_("source detail"), action=action, page=page, search=search, form=SourceForm(self.database, _, instance=source), logform=None)) return else: self.clear() self.set_status(404) self.finish("<html><body>No such source</body></html>") return self.render("page_view.html", **self.get_template_dict(tview=_("source view"), page=page, search=search, form=SourceForm(self.database, _, table="Source"), ) )
def add(self, obj): EditSource(self.dbstate, self.uistate, [], Source())
def empty_object(self): return Source()
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)
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)