def from_struct(struct): """ Given a struct with metadata, create a Gramps object. """ from gramps.gen.lib import (Person, Family, Event, Source, Place, Citation, Repository, MediaObject, Note, Tag) if isinstance(struct, dict): if "_class" in struct.keys(): if struct["_class"] == "Person": return Person.create(Person.from_struct(struct)) elif struct["_class"] == "Family": return Family.create(Family.from_struct(struct)) elif struct["_class"] == "Event": return Event.create(Event.from_struct(struct)) elif struct["_class"] == "Source": return Source.create(Source.from_struct(struct)) elif struct["_class"] == "Place": return Place.create(Place.from_struct(struct)) elif struct["_class"] == "Citation": return Citation.create(Citation.from_struct(struct)) elif struct["_class"] == "Repository": return Repository.create(Repository.from_struct(struct)) elif struct["_class"] == "MediaObject": return MediaObject.create(MediaObject.from_struct(struct)) elif struct["_class"] == "Note": return Note.create(Note.from_struct(struct)) elif struct["_class"] == "Tag": return Tag.create(Tag.from_struct(struct)) raise AttributeError("invalid struct: %s" % struct)
def instance_from_struct(cls, struct): """ Given a struct with metadata, create a Gramps object. self is class when called as a classmethod. """ from gramps.gen.lib import (Person, Family, Event, Source, Place, Citation, Repository, Media, Note, Tag, Date) if isinstance(struct, dict): if "_class" in struct.keys(): if struct["_class"] == "Person": return Person.create(Person.from_struct(struct)) elif struct["_class"] == "Family": return Family.create(Family.from_struct(struct)) elif struct["_class"] == "Event": return Event.create(Event.from_struct(struct)) elif struct["_class"] == "Source": return Source.create(Source.from_struct(struct)) elif struct["_class"] == "Place": return Place.create(Place.from_struct(struct)) elif struct["_class"] == "Citation": return Citation.create(Citation.from_struct(struct)) elif struct["_class"] == "Repository": return Repository.create(Repository.from_struct(struct)) elif struct["_class"] == "Media": return Media.create(Media.from_struct(struct)) elif struct["_class"] == "Note": return Note.create(Note.from_struct(struct)) elif struct["_class"] == "Tag": return Tag.create(Tag.from_struct(struct)) elif struct["_class"] == "Date": return Date().unserialize( Date.from_struct(struct, full=True)) raise AttributeError("invalid struct: %s" % struct)
def instance_from_struct(cls, struct): """ Given a struct with metadata, create a Gramps object. self is class when called as a classmethod. """ from gramps.gen.lib import (Person, Family, Event, Source, Place, Citation, Repository, Media, Note, Tag, Date) if isinstance(struct, dict): if "_class" in struct.keys(): if struct["_class"] == "Person": return Person.create(Person.from_struct(struct)) elif struct["_class"] == "Family": return Family.create(Family.from_struct(struct)) elif struct["_class"] == "Event": return Event.create(Event.from_struct(struct)) elif struct["_class"] == "Source": return Source.create(Source.from_struct(struct)) elif struct["_class"] == "Place": return Place.create(Place.from_struct(struct)) elif struct["_class"] == "Citation": return Citation.create(Citation.from_struct(struct)) elif struct["_class"] == "Repository": return Repository.create(Repository.from_struct(struct)) elif struct["_class"] == "Media": return Media.create(Media.from_struct(struct)) elif struct["_class"] == "Note": return Note.create(Note.from_struct(struct)) elif struct["_class"] == "Tag": return Tag.create(Tag.from_struct(struct)) elif struct["_class"] == "Date": return Date().unserialize(Date.from_struct(struct, full=True)) raise AttributeError("invalid struct: %s" % struct)
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")
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")
def importData(db, filename, user): """Function called by Gramps to import data on persons in CSV format.""" db.disable_signals() try: with DbTxn(_("JSON import"), db, batch=True) as trans: with OpenFileOrStdin(filename, encoding="utf-8") as fp: line = fp.readline() while line: data = json.loads(line) if data["_class"] == "Person": obj = Person.create(Person.from_struct(data)) db.add_person(obj, trans) elif data["_class"] == "Family": obj = Family.create(Family.from_struct(data)) db.add_family(obj, trans) elif data["_class"] == "Event": obj = Event.create(Event.from_struct(data)) db.add_event(obj, trans) elif data["_class"] == "Media": obj = Media.create(Media.from_struct(data)) db.add_media(obj, trans) elif data["_class"] == "Repository": obj = Repository.create(Repository.from_struct(data)) db.add_repository(obj, trans) elif data["_class"] == "Tag": obj = Tag.create(Tag.from_struct(data)) db.add_tag(obj, trans) elif data["_class"] == "Source": obj = Source.create(Source.from_struct(data)) db.add_source(obj, trans) elif data["_class"] == "Citation": obj = Citation.create(Citation.from_struct(data)) db.add_citation(obj, trans) elif data["_class"] == "Note": obj = Note.create(Note.from_struct(data)) db.add_note(obj, trans) elif data["_class"] == "Place": obj = Place.create(Place.from_struct(data)) db.add_place(obj, trans) else: LOG.warn("ignored: " + data) line = fp.readline() except EnvironmentError as err: user.notify_error(_("%s could not be opened\n") % filename, str(err)) db.enable_signals() db.request_rebuild()
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 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
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})
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"), ))
class RepoSidebarFilter(SidebarFilter): 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) 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") def create_widget(self): cell = Gtk.CellRendererText() cell.set_property('width', self._FILTER_WIDTH) cell.set_property('ellipsize', self._FILTER_ELLIPSIZE) self.generic.pack_start(cell, True) self.generic.add_attribute(cell, 'text', 0) self.on_filters_changed('Repository') cell = Gtk.CellRendererText() cell.set_property('width', self._FILTER_WIDTH) cell.set_property('ellipsize', self._FILTER_ELLIPSIZE) self.tag.pack_start(cell, True) self.tag.add_attribute(cell, 'text', 0) self.rtype.get_child().set_width_chars(5) self.add_text_entry(_('ID'), self.filter_id) self.add_text_entry(_('Name'), self.filter_title) self.add_entry(_('Type'), self.rtype) self.add_text_entry(_('Address'), self.filter_address) self.add_text_entry(_('URL'), self.filter_url) self.add_text_entry(_('Note'), self.filter_note) self.add_entry(_('Tag'), self.tag) self.add_filter_entry(_('Custom filter'), self.generic) self.add_regex_entry(self.filter_regex) def clear(self, obj): self.filter_id.set_text('') self.filter_title.set_text('') self.filter_address.set_text('') self.filter_url.set_text('') self.rtype.get_child().set_text('') self.filter_note.set_text('') self.tag.set_active(0) self.generic.set_active(0) def get_filter(self): gid = str(self.filter_id.get_text()).strip() title = str(self.filter_title.get_text()).strip() address = str(self.filter_address.get_text()).strip() url = str(self.filter_url.get_text()).strip() rtype = self.repo.get_type().xml_str() note = str(self.filter_note.get_text()).strip() regex = self.filter_regex.get_active() tag = self.tag.get_active() > 0 gen = self.generic.get_active() > 0 empty = not (gid or title or address or url or rtype or note or regex or tag or gen) if empty: generic_filter = None else: generic_filter = GenericRepoFilter() if gid: rule = RegExpIdOf([gid], use_regex=regex) generic_filter.add_rule(rule) rule = HasRepo([title, rtype, address, url], use_regex=regex) generic_filter.add_rule(rule) if note: rule = HasNoteRegexp([note], use_regex=regex) generic_filter.add_rule(rule) # check the Tag if tag: model = self.tag.get_model() node = self.tag.get_active_iter() attr = model.get_value(node, 0) rule = HasTag([attr]) generic_filter.add_rule(rule) if self.generic.get_active() != 0: model = self.generic.get_model() node = self.generic.get_active_iter() obj = str(model.get_value(node, 0)) rule = MatchesFilter([obj]) generic_filter.add_rule(rule) return generic_filter def on_filters_changed(self, name_space): if name_space == 'Repository': all_filter = GenericRepoFilter() all_filter.set_name(_("None")) all_filter.add_rule(rules.repository.AllRepos([])) self.generic.set_model( build_filter_model('Repository', [all_filter])) self.generic.set_active(0) def on_tags_changed(self, tag_list): """ Update the list of tags in the tag filter. """ model = Gtk.ListStore(str) model.append(('', )) for tag_name in tag_list: model.append((tag_name, )) self.tag.set_model(model) self.tag.set_active(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)
def exportData(database, filename, error_dialog=None, option_box=None, callback=None): if not callable(callback): callback = lambda percent: None # dummy with OpenFileOrStdout(filename, encoding="utf-8") as fp: total = (len(database.note_map) + len(database.person_map) + len(database.event_map) + len(database.family_map) + len(database.repository_map) + len(database.place_map) + len(database.media_map) + len(database.citation_map) + len(database.source_map) + len(database.tag_map)) count = 0.0 # --------------------------------- # Notes # --------------------------------- for handle in database.note_map.keys(): serial = database.note_map[handle] write_line(fp, Note.create(serial)) count += 1 callback(100 * count / total) # --------------------------------- # Event # --------------------------------- for handle in database.event_map.keys(): serial = database.event_map[handle] write_line(fp, Event.create(serial)) count += 1 callback(100 * count / total) # --------------------------------- # Person # --------------------------------- for handle in database.person_map.keys(): serial = database.person_map[handle] write_line(fp, Person.create(serial)) count += 1 callback(100 * count / total) # --------------------------------- # Family # --------------------------------- for handle in database.family_map.keys(): serial = database.family_map[handle] write_line(fp, Family.create(serial)) count += 1 callback(100 * count / total) # --------------------------------- # Repository # --------------------------------- for handle in database.repository_map.keys(): serial = database.repository_map[handle] write_line(fp, Repository.create(serial)) count += 1 callback(100 * count / total) # --------------------------------- # Place # --------------------------------- for handle in database.place_map.keys(): serial = database.place_map[handle] write_line(fp, Place.create(serial)) count += 1 callback(100 * count / total) # --------------------------------- # Source # --------------------------------- for handle in database.source_map.keys(): serial = database.source_map[handle] write_line(fp, Source.create(serial)) count += 1 callback(100 * count / total) # --------------------------------- # Citation # --------------------------------- for handle in database.citation_map.keys(): serial = database.citation_map[handle] write_line(fp, Citation.create(serial)) count += 1 callback(100 * count / total) # --------------------------------- # Media # --------------------------------- for handle in database.media_map.keys(): serial = database.media_map[handle] write_line(fp, MediaObject.create(serial)) count += 1 callback(100 * count / total) # --------------------------------- # Tag # --------------------------------- for handle in database.tag_map.keys(): serial = database.tag_map[handle] write_line(fp, Tag.create(serial)) count += 1 callback(100 * count / total) return True
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
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)
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
class RepoSidebarFilter(SidebarFilter): 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") def create_widget(self): cell = Gtk.CellRendererText() cell.set_property('width', self._FILTER_WIDTH) cell.set_property('ellipsize', self._FILTER_ELLIPSIZE) self.generic.pack_start(cell, True) self.generic.add_attribute(cell, 'text', 0) self.on_filters_changed('Repository') cell = Gtk.CellRendererText() cell.set_property('width', self._FILTER_WIDTH) cell.set_property('ellipsize', self._FILTER_ELLIPSIZE) self.tag.pack_start(cell, True) self.tag.add_attribute(cell, 'text', 0) self.rtype.get_child().set_width_chars(5) self.add_text_entry(_('ID'), self.filter_id) self.add_text_entry(_('Name'), self.filter_title) self.add_entry(_('Type'), self.rtype) self.add_text_entry(_('Address'), self.filter_address) self.add_text_entry(_('URL'), self.filter_url) self.add_text_entry(_('Note'), self.filter_note) self.add_entry(_('Tag'), self.tag) self.add_filter_entry(_('Custom filter'), self.generic) self.add_regex_entry(self.filter_regex) def clear(self, obj): self.filter_id.set_text('') self.filter_title.set_text('') self.filter_address.set_text('') self.filter_url.set_text('') self.rtype.get_child().set_text('') self.filter_note.set_text('') self.tag.set_active(0) self.generic.set_active(0) def get_filter(self): gid = str(self.filter_id.get_text()).strip() title = str(self.filter_title.get_text()).strip() address = str(self.filter_address.get_text()).strip() url = str(self.filter_url.get_text()).strip() rtype = self.repo.get_type().xml_str() note = str(self.filter_note.get_text()).strip() regex = self.filter_regex.get_active() tag = self.tag.get_active() > 0 gen = self.generic.get_active() > 0 empty = not (gid or title or address or url or rtype or note or regex or tag or gen) if empty: generic_filter = None else: generic_filter = GenericRepoFilter() if gid: rule = RegExpIdOf([gid], use_regex=regex) generic_filter.add_rule(rule) rule = HasRepo([title, rtype, address, url], use_regex=regex) generic_filter.add_rule(rule) if note: rule = HasNoteRegexp([note], use_regex=regex) generic_filter.add_rule(rule) # check the Tag if tag: model = self.tag.get_model() node = self.tag.get_active_iter() attr = model.get_value(node, 0) rule = HasTag([attr]) generic_filter.add_rule(rule) if self.generic.get_active() != 0: model = self.generic.get_model() node = self.generic.get_active_iter() obj = str(model.get_value(node, 0)) rule = MatchesFilter([obj]) generic_filter.add_rule(rule) return generic_filter def on_filters_changed(self, name_space): if name_space == 'Repository': all_filter = GenericRepoFilter() all_filter.set_name(_("None")) all_filter.add_rule(rules.repository.AllRepos([])) self.generic.set_model(build_filter_model('Repository', [all_filter])) self.generic.set_active(0) def on_tags_changed(self, tag_list): """ Update the list of tags in the tag filter. """ model = Gtk.ListStore(str) model.append(('',)) for tag_name in tag_list: model.append((tag_name,)) self.tag.set_model(model) self.tag.set_active(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
def add(self, *obj): EditRepository(self.dbstate, self.uistate, [], Repository())
def exportData(database, filename, error_dialog=None, option_box=None, callback=None): if not callable(callback): callback = lambda percent: None # dummy with OpenFileOrStdout(filename, encoding="utf-8") as fp: total = (len(database.note_map) + len(database.person_map) + len(database.event_map) + len(database.family_map) + len(database.repository_map) + len(database.place_map) + len(database.media_map) + len(database.citation_map) + len(database.source_map) + len(database.tag_map)) count = 0.0 # --------------------------------- # Notes # --------------------------------- for handle in database.note_map.keys(): serial = database.note_map[handle] write_line(fp, Note.create(serial)) count += 1 callback(100 * count/total) # --------------------------------- # Event # --------------------------------- for handle in database.event_map.keys(): serial = database.event_map[handle] write_line(fp, Event.create(serial)) count += 1 callback(100 * count/total) # --------------------------------- # Person # --------------------------------- for handle in database.person_map.keys(): serial = database.person_map[handle] write_line(fp, Person.create(serial)) count += 1 callback(100 * count/total) # --------------------------------- # Family # --------------------------------- for handle in database.family_map.keys(): serial = database.family_map[handle] write_line(fp, Family.create(serial)) count += 1 callback(100 * count/total) # --------------------------------- # Repository # --------------------------------- for handle in database.repository_map.keys(): serial = database.repository_map[handle] write_line(fp, Repository.create(serial)) count += 1 callback(100 * count/total) # --------------------------------- # Place # --------------------------------- for handle in database.place_map.keys(): serial = database.place_map[handle] write_line(fp, Place.create(serial)) count += 1 callback(100 * count/total) # --------------------------------- # Source # --------------------------------- for handle in database.source_map.keys(): serial = database.source_map[handle] write_line(fp, Source.create(serial)) count += 1 callback(100 * count/total) # --------------------------------- # Citation # --------------------------------- for handle in database.citation_map.keys(): serial = database.citation_map[handle] write_line(fp, Citation.create(serial)) count += 1 callback(100 * count/total) # --------------------------------- # Media # --------------------------------- for handle in database.media_map.keys(): serial = database.media_map[handle] write_line(fp, Media.create(serial)) count += 1 callback(100 * count/total) # --------------------------------- # Tag # --------------------------------- for handle in database.tag_map.keys(): serial = database.tag_map[handle] write_line(fp, Tag.create(serial)) count += 1 callback(100 * count/total) return True
def make_repository(self, repository): if self.use_db_cache and repository.cache: data = repository.from_cache() else: data = self.dji.get_repository(repository) return Repository.create(data)
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 empty_object(self): return Repository()
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])