def __init__(self, name, include_private=True, include_living=True): """Initialize the database object for family tree `name`. This will raise if the database backend is not `sqlite`. The constructor does not open/lock the database yet. Parameters: - `include_private`: include records marked as private. Default True - `include_living`: include living people. Default True """ self.name = name self.include_private = include_private self.include_living = include_living self.dbstate = DbState() self.dbman = CLIDbManager(self.dbstate) self.user = User() self.smgr = CLIManager(self.dbstate, True, self.user) self.path = self.dbman.get_family_tree_path(name) if not self.path: raise ValueError( "Family tree {} not found. Known trees: {}".format( name, self.dbman.family_tree_list())) self.db_backend = self.get_dbid() if self.db_backend not in ALLOWED_DB_BACKENDS: raise ValueError( "Database backend '{}' of tree '{}' not supported.".format( self.db_backend, name))
def import_file(db, filename, user): """ Import a file (such as a GEDCOM file) into the given db. >>> import_file(DbDjango(), "/home/user/Untitled_1.ged", User()) """ from .grampsdb.models import Person dbstate = DbState() climanager = CLIManager(dbstate, setloader=False, user=user) # do not load db_loader climanager.do_reg_plugins(dbstate, None) pmgr = BasePluginManager.get_instance() (name, ext) = os.path.splitext(os.path.basename(filename)) format = ext[1:].lower() import_list = pmgr.get_reg_importers() for pdata in import_list: if format == pdata.extension: mod = pmgr.load_plugin(pdata) if not mod: for item in pmgr.get_fail_list(): name, error_tuple, pdata = item # (filename, (exception-type, exception, traceback), pdata) etype, exception, traceback = error_tuple print("ERROR:", name, exception) return False import_function = getattr(mod, pdata.import_function) db.prepare_import() retval = import_function(db, filename, user) db.commit_import() return retval return False
class Gramps: def __init__(self, user=None, dbstate=None): ## Setup: from gramps.cli.clidbman import CLIDbManager self.dbstate = dbstate or DbState() #we need a manager for the CLI session self.user = user or User(auto_accept=True, quiet=False) self.climanager = CLIManager(self.dbstate, setloader=True, user=self.user) self.clidbmanager = CLIDbManager(self.dbstate) def run(self, *args, stdin=None): with capture(stdin) as output: #load the plugins self.climanager.do_reg_plugins(self.dbstate, uistate=None) # handle the arguments args = [sys.executable] + list(args) argparser = ArgParser(args) argparser.need_gui() # initializes some variables argparser.print_help() argparser.print_usage() handler = ArgHandler(self.dbstate, argparser, self.climanager) # create a manager to manage the database handler.handle_args_cli() if handler.dbstate.is_open(): handler.dbstate.db.close() return output
class Gramps: def __init__(self, user=None, dbstate=None): ## Setup: from gramps.cli.clidbman import CLIDbManager self.dbstate = dbstate or DbState() #we need a manager for the CLI session self.user = user or User(auto_accept=True, quiet=False) self.climanager = CLIManager(self.dbstate, setloader=True, user=self.user) self.clidbmanager = CLIDbManager(self.dbstate) def run(self, *args, stdin=None): with capture(stdin) as output: #load the plugins self.climanager.do_reg_plugins(self.dbstate, uistate=None) # handle the arguments args = [sys.executable] + list(args) argparser = ArgParser(args) argparser.need_gui() # initializes some variables if argparser.errors: print(argparser.errors, file=sys.stderr) argparser.print_help() argparser.print_usage() handler = ArgHandler(self.dbstate, argparser, self.climanager) # create a manager to manage the database handler.handle_args_cli() if handler.dbstate.is_open(): handler.dbstate.db.close() return output
def import_as_dict(filename, user=None): """ Import the filename into a InMemoryDB and return it. """ if user is None: user = User() db = make_database("inmemorydb") db.load(None) db.set_feature("skip-import-additions", True) dbstate = DbState() climanager = CLIManager(dbstate, setloader=False, user=user) climanager.do_reg_plugins(dbstate, None) pmgr = BasePluginManager.get_instance() (name, ext) = os.path.splitext(os.path.basename(filename)) format = ext[1:].lower() import_list = pmgr.get_reg_importers() for pdata in import_list: if format == pdata.extension: mod = pmgr.load_plugin(pdata) if not mod: for item in pmgr.get_fail_list(): name, error_tuple, pdata = item # (filename, (exception-type, exception, traceback), pdata) etype, exception, traceback = error_tuple #print("ERROR:", name, exception) return False import_function = getattr(mod, pdata.import_function) results = import_function(db, filename, user) if results is None: return None return db return None
def import_as_dict(filename, user=None): """ Import the filename into a DictionaryDb and return it. """ if user is None: user = User() db = DictionaryDb() db.load(None) db.set_feature("skip-import-additions", True) dbstate = DbState() climanager = CLIManager(dbstate, setloader=False, user=user) climanager.do_reg_plugins(dbstate, None) pmgr = BasePluginManager.get_instance() (name, ext) = os.path.splitext(os.path.basename(filename)) format = ext[1:].lower() import_list = pmgr.get_reg_importers() for pdata in import_list: if format == pdata.extension: mod = pmgr.load_plugin(pdata) if not mod: for item in pmgr.get_fail_list(): name, error_tuple, pdata = item # (filename, (exception-type, exception, traceback), pdata) etype, exception, traceback = error_tuple #print("ERROR:", name, exception) return False import_function = getattr(mod, pdata.import_function) results = import_function(db, filename, user) if results is None: return None return db return None
def export_file(db, filename, user): """ Export the db to a file (such as a GEDCOM file). >>> export_file(DbDjango(), "/home/user/Untitled_1.ged", User()) """ dbstate = DbState() climanager = CLIManager(dbstate, setloader=False, user=user) # do not load db_loader climanager.do_reg_plugins(dbstate, None) pmgr = BasePluginManager.get_instance() (name, ext) = os.path.splitext(os.path.basename(filename)) format = ext[1:].lower() export_list = pmgr.get_reg_exporters() for pdata in export_list: if format == pdata.extension: mod = pmgr.load_plugin(pdata) if not mod: for item in pmgr.get_fail_list(): name, error_tuple, pdata = item etype, exception, traceback = error_tuple print("ERROR:", name, exception) return False export_function = getattr(mod, pdata.export_function) export_function(db, filename, user) return True return False
def import_file(db, filename, user): """ Import a file (such as a GEDCOM file) into the given db. >>> import_file(DbDjango(), "/home/user/Untitled_1.ged", User()) """ from .grampsdb.models import Person dbstate = DbState() climanager = CLIManager(dbstate, setloader=False, user=user) # do not load db_loader climanager.do_reg_plugins(dbstate, None) pmgr = BasePluginManager.get_instance() (name, ext) = os.path.splitext(os.path.basename(filename)) format = ext[1:].lower() import_list = pmgr.get_reg_importers() for pdata in import_list: if format == pdata.extension: mod = pmgr.load_plugin(pdata) if not mod: for item in pmgr.get_fail_list(): name, error_tuple, pdata = item # (filename, (exception-type, exception, traceback), pdata) etype, exception, traceback = error_tuple print("ERROR:", name, exception) return False import_function = getattr(mod, pdata.import_function) #db.prepare_import() retval = import_function(db, filename, user) #db.commit_import() return retval return False
def __init__(self, user=None, dbstate=None): ## Setup: from gramps.cli.clidbman import CLIDbManager self.dbstate = dbstate or DbState() #we need a manager for the CLI session self.user = user or User() self.climanager = CLIManager(self.dbstate, setloader=True, user=self.user) self.clidbmanager = CLIDbManager(self.dbstate)
def get_db(self, force_unlock: bool = False) -> DbState: """Open the database and return a dbstate instance. If `force_unlock` is `True`, will break an existing lock (use with care!). """ dbstate = DbState() user = User() smgr = CLIManager(dbstate, True, user) if force_unlock: self.break_lock() smgr.open_activate(self.path) return dbstate
def __rebuild_reg_list(self, path=None, rescan=True): self._selection_reg.handler_block(self._cursor_hndlr) self._model_reg.clear() if rescan: CLIManager.do_reg_plugins(self, self.dbstate, self.uistate, rescan=True) self.__populate_reg_list() self._selection_reg.handler_unblock(self._cursor_hndlr) if not path or int(str(path)) >= len(self._model_reg): path = '0' self._selection_reg.select_path(path) if len(self._model_reg): self._list_reg.scroll_to_cell(path, None, True, 0.5, 0)
def __init__(self, name: str = None) -> None: """Prepare and import the example DB.""" ExampleDbBase.__init__(self) self.db_path = os.path.join(os.environ["GRAMPSHOME"], "gramps", "grampsdb") os.makedirs(self.db_path, exist_ok=True) setconfig("database.path", self.db_path) dbstate = DbState() dbman = CLIDbManager(dbstate) user = User() smgr = CLIManager(dbstate, True, user) smgr.do_reg_plugins(dbstate, uistate=None) self.path, self.name = dbman.import_new_db(self.path, User()) WebDbManager.__init__(self, self.name)
def __rebuild_reg_list(self, path=None, rescan=True): self._selection_reg.handler_block(self._cursor_hndlr) self._model_reg.clear() if rescan: CLIManager.do_reg_plugins(self, self.dbstate, self.uistate, rescan=True) self.__populate_reg_list() self._selection_reg.handler_unblock(self._cursor_hndlr) if not path or int(str(path)) >= len(self._model_reg): path = '0' self._selection_reg.select_path(path) if len(self._tree_filter): self._list_reg.scroll_to_cell(path, None, True, 0.5, 0) self._cursor_changed(None)
def __init__(self, dbstate, user=None): """ The viewmanager is initialised with a dbstate on which GRAMPS is working. """ self.__centralview = None CLIManager.__init__(self, dbstate, setloader=False, user=user) self.db_loader = CLIDbLoader(self.dbstate) # there is one DeclarativeEngine for global settings self.__build_main_window() from .questiondialog import ErrorDialog if self.user is None: self.user = User(error=ErrorDialog, callback=self.uistate.pulse_progressbar, uistate=self.uistate)
def __init__(self, dbstate, user=None): """ The viewmanager is initialised with a dbstate on which GRAMPS is working. """ self.__centralview = None CLIManager.__init__(self, dbstate, setloader=False, user=user) self.db_loader = CLIDbLoader(self.dbstate) #there is one DeclarativeEngine for global settings self.__build_main_window() from .questiondialog import ErrorDialog if self.user is None: self.user = User(error=ErrorDialog, callback=self.uistate.pulse_progressbar, uistate=self.uistate)
def __init__(self, user=None, dbstate=None): ## Setup: from gramps.cli.clidbman import CLIDbManager self.dbstate = dbstate or DbState() #we need a manager for the CLI session self.user = user or User(auto_accept=True, quiet=False) self.climanager = CLIManager(self.dbstate, setloader=True, user=self.user) self.clidbmanager = CLIDbManager(self.dbstate)
def get_plugin_options(db, pid): """ Get the default options and help for this plugin. """ dbstate = DbState() climanager = CLIManager(dbstate, setloader=False, user=GUser()) # do not load db_loader climanager.do_reg_plugins(dbstate, None) pmgr = BasePluginManager.get_instance() pdata = pmgr.get_plugin(pid) if hasattr(pdata, "optionclass") and pdata.optionclass: mod = pmgr.load_plugin(pdata) optionclass = eval("mod." + pdata.optionclass) optioninstance = optionclass("Name", db) optioninstance.load_previous_values() return optioninstance.options_dict, optioninstance.options_help else: return {}, {}
class Gramps: def __init__(self, user=None, dbstate=None): ## Setup: from gramps.cli.clidbman import CLIDbManager self.dbstate = dbstate or DbState() #we need a manager for the CLI session self.user = user or User(auto_accept=True, quiet=False) self.climanager = CLIManager(self.dbstate, setloader=True, user=self.user) self.clidbmanager = CLIDbManager(self.dbstate) def run(self, *args, stdin=None, bytesio=False): with capture(stdin, bytesio=bytesio) as output: try: try: # make sure we have user directories for path in USER_DIRLIST: if not os.path.isdir(path): os.makedirs(path) except OSError as msg: print("Error creating user directories: " + str(msg)) except: print("Error reading configuration.", exc_info=True) #load the plugins self.climanager.do_reg_plugins(self.dbstate, uistate=None) # handle the arguments args = [sys.executable] + list(args) argparser = ArgParser(args) argparser.need_gui() # initializes some variables if argparser.errors: print(argparser.errors, file=sys.stderr) argparser.print_help() argparser.print_usage() handler = ArgHandler(self.dbstate, argparser, self.climanager) # create a manager to manage the database handler.handle_args_cli() if handler.dbstate.is_open(): handler.dbstate.db.close() except: print("Exception in test:") print("-" * 60) traceback.print_exc(file=sys.stdout) print("-" * 60) return output
class Gramps: def __init__(self, user=None, dbstate=None): ## Setup: from gramps.cli.clidbman import CLIDbManager self.dbstate = dbstate or DbState() #we need a manager for the CLI session self.user = user or User() self.climanager = CLIManager(self.dbstate, setloader=True, user=self.user) self.clidbmanager = CLIDbManager(self.dbstate) def run(self, *args, stdin=None, bytesio=False): with capture(stdin, bytesio=bytesio) as output: try: try: # make sure we have user directories for path in USER_DIRLIST: if not os.path.isdir(path): os.makedirs(path) except OSError as msg: print("Error creating user directories: " + str(msg)) except: print("Error reading configuration.", exc_info=True) #load the plugins self.climanager.do_reg_plugins(self.dbstate, uistate=None) # handle the arguments args = [sys.executable] + list(args) argparser = ArgParser(args) argparser.need_gui() # initializes some variables if argparser.errors: print(argparser.errors, file=sys.stderr) argparser.print_help() argparser.print_usage() handler = ArgHandler(self.dbstate, argparser, self.climanager) # create a manager to manage the database handler.handle_args_cli() if handler.dbstate.is_open(): handler.dbstate.db.close() except: print("Exception in test:") print("-" * 60) traceback.print_exc(file=sys.stdout) print("-" * 60) return output
def build_report_set(): reports = [] ################################################################## # Load plugins ################################################################## dbstate = DbState() climanager = CLIManager(dbstate, setloader=True, user=None) climanager.do_reg_plugins(dbstate, uistate=None) gpr = PluginRegister.get_instance() PLUGMAN = BasePluginManager.get_instance() CSS = PLUGMAN.process_plugin_data('WEBSTUFF') ################################################################## # GRAMPS native plugins ################################################################## # GRPH_FMT = ['odt', 'ps', 'pdf', 'svg'] GRPH_FMT = ['pdf', 'svg'] # GRPH_FMT = ['svg'] GRPH_REP = [ { 'report': 'ancestor_chart', 'options': { 'scale_tree': 2, 'maxgen': 6, 'pid': 'I0006', }, }, { 'report': 'descend_chart', 'options': { 'scale_tree': 2, 'maxgen': 6, 'pid': 'I0104', }, }, { 'report': 'family_descend_chart', 'options': { 'scale_tree': 2, 'maxgen': 6, 'pid': 'I0104', }, }, { 'report': 'fan_chart', 'options': { 'scale_tree': 2, 'maxgen': 6, 'pid': 'I0006', }, }, { 'report': 'statistics_chart', 'options': { 'scale_tree': 2, 'maxgen': 6, }, }, { 'report': 'timeline', 'options': { 'scale_tree': 2, 'maxgen': 6, }, }, { 'report': 'calendar', 'options': { 'scale_tree': 2, 'maxgen': 6, }, }, { 'report': 'familylines_graph', 'options': { 'scale_tree': 2, 'maxgen': 6, 'gidlist': 'I0104 I0045', 'limitchildren': True, 'maxchildren': 20, }, }, { 'report': 'hourglass_graph', 'options': { 'scale_tree': 2, 'maxgen': 6, 'pid': 'I0044', 'maxascend': 2, 'maxdescend': 2, }, }, { 'report': 'rel_graph', 'options': { 'scale_tree': 2, 'maxgen': 6, 'pid': 'I0044', 'filter': 3, 'event_choice': 2, }, }, ] # TEXT_FMT = ['ps', 'pdf', 'html', 'odt', 'tex', 'rtf', 'txt'] TEXT_FMT = ['html', 'pdf', 'txt'] # TEXT_FMT = ['html', 'txt'] TEXT_REP = [ { 'report': 'ancestor_report', 'options': { 'maxgen': 6, 'pid': 'I0006', }, }, { 'report': 'descend_report', 'options': { 'pid': 'I0104', }, }, { 'report': 'det_ancestor_report', 'options': { 'pid': 'I0006', }, }, { 'report': 'det_descendant_report', 'options': { 'pid': 'I0104', }, }, { 'report': 'family_group', 'options': { 'family_id': 'F0017', }, }, { 'report': 'birthday_report', 'options': {}, }, { 'report': 'endofline_report', 'options': { 'pid': 'I0006', }, }, { 'report': 'indiv_complete', 'options': {}, }, { 'report': 'kinship_report', 'options': { 'pid': 'I0044', }, }, { 'report': 'tag_report', 'options': { 'tag': 'ToDo', }, }, { 'report': 'number_of_ancestors', 'options': { 'pid': 'I0006', }, }, { 'report': 'place_report', 'options': { 'places': 'P1678 P1679 P1680', }, }, { 'report': 'summary', 'options': {}, }, { 'report': 'records', 'options': {}, }, { 'report': 'notelinkreport', 'options': {}, }, ] # Single run with all native reports (except web) in all formats for (rep_list, formats) in [ (TEXT_REP, TEXT_FMT), (GRPH_REP, GRPH_FMT), ]: for rep_info in TEXT_REP: report = rep_info['report'] options = rep_info['options'] plugin = gpr.get_plugin(report) if not plugin: print('Unknown plugin: %s' % report) continue for fmt in TEXT_FMT: of = os.path.join(GRAMPS_REP_DIR, report + '.' + fmt) new_options = { 'name': report, 'off': fmt, 'of': of, # 'show': 'all', } new_options.update(options) reports.append({ 'title': '"%s" in format "%s"' % (plugin.name, fmt), 'name': plugin.name, 'result': of, 'type': 'Native', 'category': plugin.category, 'version': plugin.version, 'options': new_options, }) ################################################################## # GRAMPS native web reports ################################################################## full_options = { 'linkhome': True, 'showdeath': True, 'showpartner': True, 'showparents': True, 'showhalfsiblings': True, 'inc_families': True, 'inc_repository': True, 'inc_gendex': True, 'inc_addressbook': True, 'placemappages': True, 'familymappages': True, } for (i, (css, full)) in enumerate([ ['default', False], ['Mainz', True], ]): report = 'navwebpage' plugin = gpr.get_plugin(report) opts = { 'name': report, 'target': os.path.join(GRAMPS_REP_DIR, 'example_NAVWEB%i' % i), 'css': CSS[css]['id'], 'living': _INCLUDE_LIVING_VALUE, } if (full): opts.update(full_options) reports.append({ 'title': '"%s" report example %i' % (plugin.name, i), 'name': report, 'result': os.path.join(GRAMPS_REP_DIR, 'example_NAVWEB%i' % i, 'index.html'), 'type': 'Native', 'category': plugin.category, 'version': VERSION, 'options': opts, }) full_options = { 'alive': False, 'fullyear': True, 'makeoneday': True, 'link_to_narweb': True, } for (i, (css, full)) in enumerate([ ['default', False], ['Mainz', True], ]): report = 'WebCal' plugin = gpr.get_plugin(report) opts = { 'name': report, 'target': os.path.join(GRAMPS_REP_DIR, 'example_WebCal%i' % i), 'css': CSS[css]['id'], 'home_link': '../../example_NAVWEB%i/index.html' % i, 'prefix': '../../example_NAVWEB%i/' % i, } page = 'January.html' if (full): opts.update(full_options) page = 'fullyearlinked.html' reports.append({ 'title': '"%s" report example %i' % (plugin.name, i), 'name': report, 'result': os.path.join(GRAMPS_REP_DIR, 'example_WebCal%i' % i, str(Today().get_year()), page), 'type': 'Native', 'category': plugin.category, 'version': VERSION, 'options': opts, }) ################################################################## # GRAMPS addons reports ################################################################## addons = [] ########## AncestorFill for fmt in TEXT_FMT: of = os.path.join(ADDONS_REP_DIR, 'AncestorFill.' + fmt) addons.append({ 'title': '"%%s" in format "%s"' % fmt, 'result': of, 'i': 'AncestorFill', 'options': { 'off': fmt, 'of': of, }, }) ########## d3-ancestralcollapsibletree addons.append({ 'title': '"%s" report example', 'result': os.path.join(ADDONS_REP_DIR, 'd3-ancestralcollapsibletree', 'index.html'), 'i': 'd3-ancestralcollapsibletree', 'options': { 'dest_path': os.path.join(ADDONS_REP_DIR, 'd3-ancestralcollapsibletree'), 'dest_file': 'index.html', 'pid': 'I0006', 'maxgen': 6, }, }) ########## d3-ancestralfanchart addons.append({ 'title': '"%s" report example', 'result': os.path.join(ADDONS_REP_DIR, 'd3-ancestralfanchart', 'index.html'), 'i': 'd3-ancestralfanchart', 'options': { 'dest_path': os.path.join(ADDONS_REP_DIR, 'd3-ancestralfanchart'), 'dest_file': 'index.html', 'pid': 'I0006', 'maxgen': 6, }, }) ########## d3-descendantindentedtree addons.append({ 'title': '"%s" report example', 'result': os.path.join(ADDONS_REP_DIR, 'd3-descendantindentedtree', 'index.html'), 'i': 'd3-descendantindentedtree', 'options': { 'dest_path': os.path.join(ADDONS_REP_DIR, 'd3-descendantindentedtree'), 'dest_file': 'index.html', 'pid': 'I0104', 'max_gen': 6, 'inc_private': True, 'inc_living': _INCLUDE_LIVING_VALUE, }, }) ########## denominoviso for (i, (mode, type, dir, pid, full)) in enumerate([ [0, 0, 0, 'I0001', True], [0, 3, 2, 'I0001', False], [0, 4, 2, 'I0001', False], [1, 0, 0, 'I0044', True], [1, 1, 0, 'I0044', False], ]): addons.append({ 'title': '"%%s" report example %i' % i, 'result': os.path.join(ADDONS_REP_DIR, 'DenominoViso%i.xhtml' % i), 'i': 'denominoviso', 'options': { 'DNMfilename': os.path.join(ADDONS_REP_DIR, 'DenominoViso%i.xhtml' % i), 'DNMchart_mode': mode, 'DNMpid': pid, 'DNMchart_type': type, 'DNMinc_attributes_m': '"True, "', 'DNMinc_addresses': full, 'DNMinc_notes': full, 'DNMinc_url': full, 'DNMinc_url_desc': full, 'DNMinc_sources': full, 'DNMinc_img': full, 'DNMcopy_img_m': '"%s, %s%i"' % (str(full), os.path.join(ADDONS_REP_DIR, 'DenominoViso'), i), }, }) ########## DescendantBook for fmt in TEXT_FMT: of = os.path.join(ADDONS_REP_DIR, 'DescendantBook.' + fmt) addons.append({ 'title': '"%%s" in format "%s"' % fmt, 'result': of, 'i': 'DescendantBook', 'options': { 'off': fmt, 'of': of, }, }) for fmt in TEXT_FMT: of = os.path.join(ADDONS_REP_DIR, 'DetailedDescendantBook.' + fmt) addons.append({ 'title': '"%%s" in format "%s"' % fmt, 'result': of, 'i': 'DetailedDescendantBook', 'options': { 'off': fmt, 'of': of, }, }) ########## Descendants Lines for fmt in GRPH_FMT: of = os.path.join(ADDONS_REP_DIR, 'DescendantsLines.' + fmt) addons.append({ 'title': '"%%s" in format "%s"' % fmt, 'result': of, 'i': 'Descendants Lines', 'options': { 'off': fmt, 'of': of, 'pid': 'I0006', }, }) ########## database-differences-report for fmt in ['html']: of = os.path.join(ADDONS_REP_DIR, 'database-differences-report.' + fmt) addons.append({ 'title': '"%%s" in format "%s"' % fmt, 'result': of, 'i': 'database-differences-report', 'options': { 'off': fmt, 'of': of, 'filename': os.path.join(os.environ['GRAMPS_RESOURCES'], 'example', 'gramps', 'example.gramps'), }, }) ########## DynamicWeb addons.extend(report_set_DynamicWeb.addon_set()) ########## FamilyTree for fmt in GRPH_FMT: of = os.path.join(ADDONS_REP_DIR, 'FamilyTree.' + fmt) addons.append({ 'title': '"%%s" in format "%s"' % fmt, 'result': of, 'i': 'FamilyTree', 'options': { 'off': fmt, 'of': of, 'pid': 'I0006', 'max_ancestor_generations': 3, 'max_descendant_generations': 3, 'papero': 1, 'protect_private': False, 'color': 1, }, }) ########## LastChangeReport for fmt in ['html']: of = os.path.join(ADDONS_REP_DIR, 'LastChangeReport.' + fmt) addons.append({ 'title': '"%%s" in format "%s"' % fmt, 'result': of, 'i': 'LastChangeReport', 'options': { 'off': fmt, 'of': of, 'what_types': '"True,True,True,True,True,True"' }, }) ########## LinesOfDescendency for fmt in ['html']: of = os.path.join(ADDONS_REP_DIR, 'LinesOfDescendency.' + fmt) addons.append({ 'title': '"%%s" in format "%s"' % fmt, 'result': of, 'i': 'LinesOfDescendency', 'options': { 'off': fmt, 'of': of, 'pid': 'I0006', 'ancestor': 'I0104', }, }) ########## ListeEclair for fmt in TEXT_FMT: of = os.path.join(ADDONS_REP_DIR, 'ListeEclair.' + fmt) addons.append({ 'title': '"%%s" in format "%s"' % fmt, 'result': of, 'i': 'ListeEclair', 'options': { 'off': fmt, 'of': of, }, }) ########## PedigreeChart for fmt in GRPH_FMT: of = os.path.join(ADDONS_REP_DIR, 'PedigreeChart.' + fmt) addons.append({ 'title': '"%%s" in format "%s"' % fmt, 'result': of, 'i': 'PedigreeChart', 'options': { 'off': fmt, 'of': of, 'maxgen': 6, 'pid': 'I0006', }, }) ########## PersonEverythingReport for fmt in TEXT_FMT: of = os.path.join(ADDONS_REP_DIR, 'PersonEverythingReport.' + fmt) addons.append({ 'title': '"%%s" in format "%s"' % fmt, 'result': of, 'i': 'PersonEverythingReport', 'options': { 'off': fmt, 'of': of, }, }) ########## Repositories Report for fmt in TEXT_FMT: of = os.path.join(ADDONS_REP_DIR, 'RepositoriesReportOptions.' + fmt) addons.append({ 'title': '"%%s" in format "%s"' % fmt, 'result': of, 'i': 'Repositories Report Options', 'options': { 'off': fmt, 'of': of, }, }) for fmt in TEXT_FMT: of = os.path.join(ADDONS_REP_DIR, 'RepositoriesReport.' + fmt) addons.append({ 'title': '"%%s" in format "%s"' % fmt, 'result': of, 'i': 'Repositories Report', 'options': { 'off': fmt, 'of': of, }, }) ########## TodoReport reports = [] addons = [] for fmt in TEXT_FMT: of = os.path.join(ADDONS_REP_DIR, 'TodoReport.' + fmt) addons.append({ 'title': '"%%s" in format "%s"' % fmt, 'result': of, 'i': 'TodoReport', 'options': { 'off': fmt, 'of': of, 'tag': 'ToDo', }, }) ########## Check if addon exists in the addons listings for addon in addons: plugin = gpr.get_plugin(addon['i']) if not plugin: print('Unknown plugin: %s' % addon['i']) continue addon['options'].update({ 'name': addon['i'], }) addon.update({ 'title': addon['title'] % plugin.name, 'name': plugin.name, 'type': 'Addon', 'category': plugin.category, 'version': plugin.version, }) del addon['i'] reports.append(addon) return reports
def build_report_set(): reports = [] ################################################################## # Load plugins ################################################################## dbstate = DbState() climanager = CLIManager(dbstate, setloader = True, user = None) climanager.do_reg_plugins(dbstate, uistate = None) gpr = PluginRegister.get_instance() PLUGMAN = BasePluginManager.get_instance() CSS = PLUGMAN.process_plugin_data('WEBSTUFF') ################################################################## # GRAMPS native plugins ################################################################## # GRPH_FMT = ['odt', 'ps', 'pdf', 'svg'] GRPH_FMT = ['pdf', 'svg'] # GRPH_FMT = ['svg'] GRPH_REP = [ { 'report': 'ancestor_chart', 'options': { 'scale_tree': 2, 'maxgen': 6, 'pid': 'I0006', }, }, { 'report': 'descend_chart', 'options': { 'scale_tree': 2, 'maxgen': 6, 'pid': 'I0104', }, }, { 'report': 'family_descend_chart', 'options': { 'scale_tree': 2, 'maxgen': 6, 'pid': 'I0104', }, }, { 'report': 'fan_chart', 'options': { 'scale_tree': 2, 'maxgen': 6, 'pid': 'I0006', }, }, { 'report': 'statistics_chart', 'options': { 'scale_tree': 2, 'maxgen': 6, }, }, { 'report': 'timeline', 'options': { 'scale_tree': 2, 'maxgen': 6, }, }, { 'report': 'calendar', 'options': { 'scale_tree': 2, 'maxgen': 6, }, }, { 'report': 'familylines_graph', 'options': { 'scale_tree': 2, 'maxgen': 6, 'gidlist': 'I0104 I0045', 'limitchildren': True, 'maxchildren': 20, }, }, { 'report': 'hourglass_graph', 'options': { 'scale_tree': 2, 'maxgen': 6, 'pid': 'I0044', 'maxascend': 2, 'maxdescend': 2, }, }, { 'report': 'rel_graph', 'options': { 'scale_tree': 2, 'maxgen': 6, 'pid': 'I0044', 'filter': 3, 'event_choice': 2, }, }, ] # TEXT_FMT = ['ps', 'pdf', 'html', 'odt', 'tex', 'rtf', 'txt'] TEXT_FMT = ['html', 'pdf', 'txt'] # TEXT_FMT = ['html', 'txt'] TEXT_REP = [ { 'report': 'ancestor_report', 'options': { 'maxgen': 6, 'pid': 'I0006', }, }, { 'report': 'descend_report', 'options': { 'pid': 'I0104', }, }, { 'report': 'det_ancestor_report', 'options': { 'pid': 'I0006', }, }, { 'report': 'det_descendant_report', 'options': { 'pid': 'I0104', }, }, { 'report': 'family_group', 'options': { 'family_id': 'F0017', }, }, { 'report': 'birthday_report', 'options': {}, }, { 'report': 'endofline_report', 'options': { 'pid': 'I0006', }, }, { 'report': 'indiv_complete', 'options': {}, }, { 'report': 'kinship_report', 'options': { 'pid': 'I0044', }, }, { 'report': 'tag_report', 'options': { 'tag': 'ToDo', }, }, { 'report': 'number_of_ancestors', 'options': { 'pid': 'I0006', }, }, { 'report': 'place_report', 'options': { 'places': 'P1678 P1679 P1680', }, }, { 'report': 'summary', 'options': {}, }, { 'report': 'records', 'options': {}, }, { 'report': 'notelinkreport', 'options': {}, }, ] # Single run with all native reports (except web) in all formats for (rep_list, formats) in [ (TEXT_REP, TEXT_FMT), (GRPH_REP, GRPH_FMT), ]: for rep_info in TEXT_REP: report = rep_info['report'] options = rep_info['options'] plugin = gpr.get_plugin(report) if not plugin: print('Unknown plugin: %s' % report) continue for fmt in TEXT_FMT: of = os.path.join(GRAMPS_REP_DIR, report + '.' + fmt) new_options = { 'name': report, 'off': fmt, 'of': of, # 'show': 'all', } new_options.update(options) reports.append({ 'title': '"%s" in format "%s"' % (plugin.name, fmt), 'name': plugin.name, 'result': of, 'type': 'Native', 'category': plugin.category, 'version': plugin.version, 'options': new_options, }) ################################################################## # GRAMPS native web reports ################################################################## full_options = { 'linkhome': True, 'showdeath': True, 'showpartner': True, 'showparents': True, 'showhalfsiblings': True, 'inc_families': True, 'inc_repository': True, 'inc_gendex': True, 'inc_addressbook': True, 'placemappages': True, 'familymappages': True, } for (i, (css, full)) in enumerate([ ['default', False], ['Mainz', True], ]): report = 'navwebpage' plugin = gpr.get_plugin(report) opts = { 'name': report, 'target': os.path.join(GRAMPS_REP_DIR, 'example_NAVWEB%i' % i), 'css': CSS[css]['id'], 'living': _INCLUDE_LIVING_VALUE, } if (full): opts.update(full_options) reports.append({ 'title': '"%s" report example %i' % (plugin.name, i), 'name': report, 'result': os.path.join(GRAMPS_REP_DIR, 'example_NAVWEB%i' % i, 'index.html'), 'type': 'Native', 'category': plugin.category, 'version': VERSION, 'options': opts, }) full_options = { 'alive': False, 'fullyear': True, 'makeoneday': True, 'link_to_narweb': True, } for (i, (css, full)) in enumerate([ ['default', False], ['Mainz', True], ]): report = 'WebCal' plugin = gpr.get_plugin(report) opts = { 'name': report, 'target': os.path.join(GRAMPS_REP_DIR, 'example_WebCal%i' % i), 'css': CSS[css]['id'], 'home_link': '../../example_NAVWEB%i/index.html' % i, 'prefix': '../../example_NAVWEB%i/' % i, } page = 'January.html' if (full): opts.update(full_options) page = 'fullyearlinked.html' reports.append({ 'title': '"%s" report example %i' % (plugin.name, i), 'name': report, 'result': os.path.join(GRAMPS_REP_DIR, 'example_WebCal%i' % i, str(Today().get_year()), page), 'type': 'Native', 'category': plugin.category, 'version': VERSION, 'options': opts, }) ################################################################## # GRAMPS addons reports ################################################################## addons=[] ########## AncestorFill for fmt in TEXT_FMT: of = os.path.join(ADDONS_REP_DIR, 'AncestorFill.' + fmt) addons.append({ 'title': '"%%s" in format "%s"' % fmt, 'result': of, 'i': 'AncestorFill', 'options': { 'off': fmt, 'of': of, }, }) ########## d3-ancestralcollapsibletree addons.append({ 'title': '"%s" report example', 'result': os.path.join(ADDONS_REP_DIR, 'd3-ancestralcollapsibletree', 'index.html'), 'i': 'd3-ancestralcollapsibletree', 'options': { 'dest_path': os.path.join(ADDONS_REP_DIR, 'd3-ancestralcollapsibletree'), 'dest_file': 'index.html', 'pid': 'I0006', 'maxgen': 6, }, }) ########## d3-ancestralfanchart addons.append({ 'title': '"%s" report example', 'result': os.path.join(ADDONS_REP_DIR, 'd3-ancestralfanchart', 'index.html'), 'i': 'd3-ancestralfanchart', 'options': { 'dest_path': os.path.join(ADDONS_REP_DIR, 'd3-ancestralfanchart'), 'dest_file': 'index.html', 'pid': 'I0006', 'maxgen': 6, }, }) ########## d3-descendantindentedtree addons.append({ 'title': '"%s" report example', 'result': os.path.join(ADDONS_REP_DIR, 'd3-descendantindentedtree', 'index.html'), 'i': 'd3-descendantindentedtree', 'options': { 'dest_path': os.path.join(ADDONS_REP_DIR, 'd3-descendantindentedtree'), 'dest_file': 'index.html', 'pid': 'I0104', 'max_gen': 6, 'inc_private': True, 'inc_living': _INCLUDE_LIVING_VALUE, }, }) ########## denominoviso for (i, (mode, type, dir, pid, full)) in enumerate([ [0, 0, 0, 'I0001', True], [0, 3, 2, 'I0001', False], [0, 4, 2, 'I0001', False], [1, 0, 0, 'I0044', True], [1, 1, 0, 'I0044', False], ]): addons.append({ 'title': '"%%s" report example %i' % i, 'result': os.path.join(ADDONS_REP_DIR, 'DenominoViso%i.xhtml' % i), 'i': 'denominoviso', 'options': { 'DNMfilename': os.path.join(ADDONS_REP_DIR, 'DenominoViso%i.xhtml' % i), 'DNMchart_mode': mode, 'DNMpid': pid, 'DNMchart_type': type, 'DNMinc_attributes_m': '"True, "', 'DNMinc_addresses': full, 'DNMinc_notes': full, 'DNMinc_url': full, 'DNMinc_url_desc': full, 'DNMinc_sources': full, 'DNMinc_img': full, 'DNMcopy_img_m': '"%s, %s%i"' % (str(full), os.path.join(ADDONS_REP_DIR, 'DenominoViso'), i), }, }) ########## DescendantBook for fmt in TEXT_FMT: of = os.path.join(ADDONS_REP_DIR, 'DescendantBook.' + fmt) addons.append({ 'title': '"%%s" in format "%s"' % fmt, 'result': of, 'i': 'DescendantBook', 'options': { 'off': fmt, 'of': of, }, }) for fmt in TEXT_FMT: of = os.path.join(ADDONS_REP_DIR, 'DetailedDescendantBook.' + fmt) addons.append({ 'title': '"%%s" in format "%s"' % fmt, 'result': of, 'i': 'DetailedDescendantBook', 'options': { 'off': fmt, 'of': of, }, }) ########## Descendants Lines for fmt in GRPH_FMT: of = os.path.join(ADDONS_REP_DIR, 'DescendantsLines.' + fmt) addons.append({ 'title': '"%%s" in format "%s"' % fmt, 'result': of, 'i': 'Descendants Lines', 'options': { 'off': fmt, 'of': of, 'pid': 'I0006', }, }) ########## database-differences-report for fmt in ['html']: of = os.path.join(ADDONS_REP_DIR, 'database-differences-report.' + fmt) addons.append({ 'title': '"%%s" in format "%s"' % fmt, 'result': of, 'i': 'database-differences-report', 'options': { 'off': fmt, 'of': of, 'filename': os.path.join(os.environ['GRAMPS_RESOURCES'], 'example', 'gramps', 'example.gramps'), }, }) ########## DynamicWeb addons.extend(report_set_DynamicWeb.addon_set()) ########## FamilyTree for fmt in GRPH_FMT: of = os.path.join(ADDONS_REP_DIR, 'FamilyTree.' + fmt) addons.append({ 'title': '"%%s" in format "%s"' % fmt, 'result': of, 'i': 'FamilyTree', 'options': { 'off': fmt, 'of': of, 'pid': 'I0006', 'max_ancestor_generations': 3, 'max_descendant_generations': 3, 'papero': 1, 'protect_private': False, 'color': 1, }, }) ########## LastChangeReport for fmt in ['html']: of = os.path.join(ADDONS_REP_DIR, 'LastChangeReport.' + fmt) addons.append({ 'title': '"%%s" in format "%s"' % fmt, 'result': of, 'i': 'LastChangeReport', 'options': { 'off': fmt, 'of': of, 'what_types': '"True,True,True,True,True,True"' }, }) ########## LinesOfDescendency for fmt in ['html']: of = os.path.join(ADDONS_REP_DIR, 'LinesOfDescendency.' + fmt) addons.append({ 'title': '"%%s" in format "%s"' % fmt, 'result': of, 'i': 'LinesOfDescendency', 'options': { 'off': fmt, 'of': of, 'pid': 'I0006', 'ancestor': 'I0104', }, }) ########## ListeEclair for fmt in TEXT_FMT: of = os.path.join(ADDONS_REP_DIR, 'ListeEclair.' + fmt) addons.append({ 'title': '"%%s" in format "%s"' % fmt, 'result': of, 'i': 'ListeEclair', 'options': { 'off': fmt, 'of': of, }, }) ########## PedigreeChart for fmt in GRPH_FMT: of = os.path.join(ADDONS_REP_DIR, 'PedigreeChart.' + fmt) addons.append({ 'title': '"%%s" in format "%s"' % fmt, 'result': of, 'i': 'PedigreeChart', 'options': { 'off': fmt, 'of': of, 'maxgen': 6, 'pid': 'I0006', }, }) ########## PersonEverythingReport for fmt in TEXT_FMT: of = os.path.join(ADDONS_REP_DIR, 'PersonEverythingReport.' + fmt) addons.append({ 'title': '"%%s" in format "%s"' % fmt, 'result': of, 'i': 'PersonEverythingReport', 'options': { 'off': fmt, 'of': of, }, }) ########## Repositories Report for fmt in TEXT_FMT: of = os.path.join(ADDONS_REP_DIR, 'RepositoriesReportOptions.' + fmt) addons.append({ 'title': '"%%s" in format "%s"' % fmt, 'result': of, 'i': 'Repositories Report Options', 'options': { 'off': fmt, 'of': of, }, }) for fmt in TEXT_FMT: of = os.path.join(ADDONS_REP_DIR, 'RepositoriesReport.' + fmt) addons.append({ 'title': '"%%s" in format "%s"' % fmt, 'result': of, 'i': 'Repositories Report', 'options': { 'off': fmt, 'of': of, }, }) ########## TodoReport reports=[] addons=[] for fmt in TEXT_FMT: of = os.path.join(ADDONS_REP_DIR, 'TodoReport.' + fmt) addons.append({ 'title': '"%%s" in format "%s"' % fmt, 'result': of, 'i': 'TodoReport', 'options': { 'off': fmt, 'of': of, 'tag': 'ToDo', }, }) ########## Check if addon exists in the addons listings for addon in addons: plugin = gpr.get_plugin(addon['i']) if not plugin: print('Unknown plugin: %s' % addon['i']) continue addon['options'].update({ 'name': addon['i'], }) addon.update({ 'title': addon['title'] % plugin.name, 'name': plugin.name, 'type': 'Addon', 'category': plugin.category, 'version': plugin.version, }) del addon['i'] reports.append(addon) return reports
class Db(): """Class for database handling.""" def __init__(self, name, include_private=True, include_living=True): """Initialize the database object for family tree `name`. This will raise if the database backend is not `sqlite`. The constructor does not open/lock the database yet. Parameters: - `include_private`: include records marked as private. Default True - `include_living`: include living people. Default True """ self.name = name self.include_private = include_private self.include_living = include_living self.dbstate = DbState() self.dbman = CLIDbManager(self.dbstate) self.user = User() self.smgr = CLIManager(self.dbstate, True, self.user) self.path = self.dbman.get_family_tree_path(name) if not self.path: raise ValueError( "Family tree {} not found. Known trees: {}".format( name, self.dbman.family_tree_list())) self.db_backend = self.get_dbid() if self.db_backend not in ALLOWED_DB_BACKENDS: raise ValueError( "Database backend '{}' of tree '{}' not supported.".format( self.db_backend, name)) @property def db(self): """Return the database or a proxy database.""" _db = self.dbstate.db if not self.include_private: _db = PrivateProxyDb(_db) if not self.include_living: _db = LivingProxyDb(_db, LivingProxyDb.MODE_INCLUDE_FULL_NAME_ONLY) return _db def get_dbid(self): """Get the database backend.""" return get_dbid_from_path(self.path) def is_locked(self): """Returns a boolean whether the database is locked.""" return os.path.isfile(os.path.join(self.path, "lock")) def open(self, force=False): """Open the database. If `force` is `True`, will break an existing lock (use with care!). """ if force: self.dbman.break_lock(self.path) return self.smgr.open_activate(self.path) def close(self, *args, **kwargs): """Close the database (if it is open).""" if self.dbstate.is_open(): return self.dbstate.db.close(*args, **kwargs)