Example #1
0
 def apply_proxy(self, proxy_name, dbase):
     """Apply the named proxy to the database and return."""
     if proxy_name == "privacy":
         if self.private:
             dbase = PrivateProxyDb(dbase)
     elif proxy_name == "living":
         if self.living != LivingProxyDb.MODE_INCLUDE_ALL:
             dbase = LivingProxyDb(
                 dbase,
                 self.living,
                 current_year=self.current_year,
                 years_after_death=self.years_after_death,
                 llocale=self.locale,
             )
     elif proxy_name == "person":
         if self.pfilter is not None and not self.pfilter.is_empty():
             dbase = FilterProxyDb(dbase,
                                   person_filter=self.pfilter,
                                   user=User())
     elif proxy_name == "event":
         if self.efilter is not None and not self.efilter.is_empty():
             dbase = FilterProxyDb(dbase,
                                   event_filter=self.efilter,
                                   user=User())
     elif proxy_name == "note":
         if self.nfilter is not None and not self.nfilter.is_empty():
             dbase = FilterProxyDb(dbase,
                                   note_filter=self.nfilter,
                                   user=User())
     elif proxy_name == "reference":
         if self.reference:
             dbase = ReferencedBySelectionProxyDb(dbase, all_people=True)
     else:
         raise AttributeError("no such proxy '%s'" % proxy_name)
     return dbase
Example #2
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)
Example #3
0
def call(*args):
    """ Call Gramps to perform the action with out and err captured """
    print("call:", args)
    gramps = Gramps(user=User())
    out, err = gramps.run(*args)
    print("out:", out, "err:", err)
    return out, err
Example #4
0
 def write(self) -> None:
     """Write the example DB to a SQLite DB and change the DB path."""
     self.tmp_dbdir = tempfile.mkdtemp()
     self.old_path = getconfig("database.path")
     setconfig("database.path", self.tmp_dbdir)
     dbman = CLIDbManager(DbState())
     dbman.import_new_db(self.path, User())
Example #5
0
 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)
Example #6
0
    def get(self, args: Dict) -> Response:
        """Get statistics from records."""
        db_handle = get_db_handle()
        locale = get_locale_for_language(args["locale"], default=True)
        person_filter = get_person_filter(db_handle, args)

        database = db_handle
        if args["private"]:
            database = PrivateProxyDb(db_handle)

        if args["living"] != "IncludeAll":
            database = LivingProxyDb(
                database,
                LIVING_FILTERS[args["living"]],
                llocale=locale,
            )

        records = find_records(
            database,
            person_filter,
            args["rank"],
            None,
            trans_text=locale.translation.sgettext,
            name_format=None,
            living_mode=LIVING_FILTERS["IncludeAll"],
            user=User(),
        )

        profiles = []
        for record in records:
            profile = {
                "description": record[0],
                "key": record[1],
                "objects": []
            }
            for item in record[2]:
                try:
                    value = item[1].format(precision=3,
                                           as_age=True,
                                           dlocale=locale)
                except AttributeError:
                    value = str(item[1])
                query_method = db_handle.method("get_%s_from_handle", item[3])
                obj = query_method(item[4])
                profile["objects"].append({
                    "gramps_id": obj.gramps_id,
                    "handle": item[4],
                    "name": str(item[2]),
                    "object": item[3],
                    "value": value,
                })
            profiles.append(profile)

        return self.response(200, profiles)
def run_import(db_handle: DbReadBase, file_obj: IO[bytes],
               extension: str) -> None:
    """Generate the import."""
    tmp_dir = tempfile.gettempdir()
    file_name = os.path.join(tmp_dir, f"{uuid.uuid4()}.{extension}")
    plugin_manager = BasePluginManager.get_instance()
    for plugin in plugin_manager.get_import_plugins():
        if extension == plugin.get_extension():
            import_function = plugin.get_import_function()
            with open(file_name, "wb") as f:
                f.write(file_obj.read())
            result = import_function(db_handle, file_name, User())
            os.remove(file_name)
            if not result:
                abort(500)
            return
Example #8
0
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
Example #9
0
    def test_write_report(self):
        """
        Creates a report from test data.
        """
        options = FamilyChroniclesOptions("Familiy Chronicles", self.db)
        options.load_previous_values()
        options.menu.get_option_by_name('pid').set_value(TEST_PERSON_ID)

        docgen_plugin = Familychroniclestest.__get_docgen_plugin('latexdoc')
        doc_class = docgen_plugin.get_basedoc()

        styles = StyleSheet()
        options.make_default_style(styles)
        paper_layout = PaperStyle(PaperSize("a4", None, None), PAPER_LANDSCAPE)
        doc = doc_class(styles, paper_layout, [])
        options.set_document(doc)
        options.set_output(TEST_OUTPUT)

        # Initialization sequence inspired by _reportdialog.py, report()
        my_report = FamilyChronicles(self.db, options, User())
        my_report.doc.init()
        my_report.begin_report()
        my_report.write_report()
        my_report.end_report()
Example #10
0
 def load(self) -> DbReadBase:
     """Return a DB instance with in-memory Gramps example DB."""
     return import_as_dict(self.path, User())
Example #11
0
 def setUpClass(cls):
     """ Import test data as in-memory database """
     cls.db = import_as_dict(TEST_INPUT, User())
Example #12
0
 def call(self, *args):
     #print("call:", args)
     self.gramps = Gramps(user=User())
     out, err = self.gramps.run(*args)
     #print("out:", out, "err:", err)
     return out, err
Example #13
0
 def call(cls, *args):
     #print("call:", args)
     gramps = Gramps(user=User())
     out, err = gramps.run(*args)
     #print("out:", out, "err:", err)
     return out, err