def run_report( db_handle: DbReadBase, report_id: str, report_options: Dict, allow_file: bool = False, ): """Generate the report.""" if "off" in report_options and report_options["off"] in REPORT_FILTERS: abort(422) _resources = ResourcePath() os.environ["GRAMPS_RESOURCES"] = str(Path(_resources.data_dir).parent) reload_custom_filters() plugin_manager = BasePluginManager.get_instance() for report_data in plugin_manager.get_reg_reports(gui=False): if report_data.id == report_id: if report_data.category not in REPORT_DEFAULTS: abort(404) if "off" not in report_options: report_options["off"] = REPORT_DEFAULTS[report_data.category] file_type = "." + report_options["off"] file_type = _EXTENSION_MAP.get(file_type) or file_type if file_type not in MIME_TYPES: current_app.logger.error( "Can not find {} in MIME_TYPES".format(file_type) ) abort(500) if current_app.config.get("REPORT_DIR"): report_path = current_app.config.get("REPORT_DIR") else: report_path = tempfile.gettempdir() file_name = os.path.join( report_path, "{}{}".format(uuid.uuid4(), file_type) ) report_options["of"] = file_name report_profile = get_report_profile(db_handle, plugin_manager, report_data) validate_options(report_profile, report_options, allow_file=allow_file) module = plugin_manager.load_plugin(report_data) option_class = getattr(module, report_data.optionclass) report_class = getattr(module, report_data.reportclass) cl_report( db_handle, report_data.name, report_data.category, report_class, option_class, report_options, ) return file_name, file_type abort(404)
def run_export(db_handle: DbReadBase, extension: str, options): """Generate the export.""" export_path = TEMP_DIR if current_app.config.get("EXPORT_PATH"): export_path = current_app.config.get("EXPORT_PATH") file_name = os.path.join(export_path, "{}.{}".format(uuid.uuid4(), extension)) _resources = ResourcePath() os.environ["GRAMPS_RESOURCES"] = str(Path(_resources.data_dir).parent) filters.reload_custom_filters() plugin_manager = BasePluginManager.get_instance() for plugin in plugin_manager.get_export_plugins(): if extension == plugin.get_extension(): export_function = plugin.get_export_function() result = export_function(db_handle, file_name, User(), options) if not result: abort(500) return file_name, "." + extension
def __init__(self) -> None: """Initialize self.""" for path in USER_DIRLIST: os.makedirs(path, exist_ok=True) _resources = ResourcePath() doc_dir = _resources.doc_dir os.environ["GRAMPS_RESOURCES"] = str(Path(_resources.data_dir).parent) self.path = os.path.join(doc_dir, "example", "gramps", "example.gramps") if os.path.isfile(self.path): self.is_zipped = False else: self.is_zipped = True self.tmp_gzdir = tempfile.mkdtemp() self.path_gz = os.path.join(doc_dir, "example", "gramps", "example.gramps.gz") if not os.path.isfile(self.path_gz): raise ValueError("Neither example.gramps nor example.gramps.gz" " found at {}".format( os.path.dirname(self.path_gz))) self.path = self._extract_to_tempfile()
def __init__(self) -> None: """Initialize self.""" _resources = ResourcePath() doc_dir = _resources.doc_dir self.path = os.path.join(doc_dir, "example", "gramps", "example.gramps") if os.path.isfile(self.path): self.is_zipped = False else: self.is_zipped = True self.tmp_gzdir = tempfile.mkdtemp() self.path_gz = os.path.join( doc_dir, "example", "gramps", "example.gramps.gz" ) if not os.path.isfile(self.path_gz): raise ValueError( "Neither example.gramps nor example.gramps.gz" " found at {}".format(os.path.dirname(self.path_gz)) ) self.path = self._extract_to_tempfile() self.tmp_dbdir = None self.old_path = None
WEB_DIR = os.path.join(ROOT_DIR, 'webapp') USE_TIPS = False if sys.platform == 'win32': USE_THUMBNAILER = False else: USE_THUMBNAILER = True #------------------------------------------------------------------------- # # Paths to data files. # #------------------------------------------------------------------------- from gramps.gen.utils.resourcepath import ResourcePath _resources = ResourcePath() DATA_DIR = _resources.data_dir IMAGE_DIR = _resources.image_dir TIP_DATA = os.path.join(DATA_DIR, "tips.xml") PAPERSIZE = os.path.join(DATA_DIR, "papersize.xml") ICON = os.path.join(IMAGE_DIR, "gramps.png") LOGO = os.path.join(IMAGE_DIR, "logo.png") SPLASH = os.path.join(IMAGE_DIR, "splash.jpg") LICENSE_FILE = os.path.join(_resources.doc_dir, 'COPYING') #------------------------------------------------------------------------- # # Init Localization #