Beispiel #1
0
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())
    """
    from gprime.dbstate import DbState
    from gprime.cli.grampscli import CLIManager
    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
Beispiel #2
0
 def run_action(self, action, handler):
     options, options_help = self.get_plugin_options(action.handle)
     args = {}
     for key, default_value in options.items():
         args[key] = handler.get_argument(key)
     if action.ptype == "Report":
         clr = run_report(self.gramps_database,
                          action.handle,
                          of="/tmp/test.html",
                          off="html",
                          **args)
         # can check for results with clr
     elif action.ptype == "Import":
         filename = download(
             args["i"],
             "/tmp/%s-%s-%s.%s" % (str(profile.user.username), str(handle),
                                   timestamp(), args["iff"]))
         if filename is not None:
             import_file(self.gramps_database, filename, User())  # callback
     elif action.ptype == "Export":
         pmgr = BasePluginManager.get_instance()
         pdata = pmgr.get_plugin(action.handle)
         export_file(self.gramps_database, "export." + pdata.extension,
                     User())  # callback
     handler.redirect("/action")
Beispiel #3
0
 def get_plugin_options(self, pid):
     """
     Get the default options and help for this plugin.
     """
     pmgr = BasePluginManager.get_instance()
     pdata = pmgr.get_plugin(pid)
     if hasattr(pdata, "optionclass") and pdata.optionclass:
         mod = pmgr.load_plugin(pdata)
         optionclass = getattr(mod, pdata.optionclass)
         optioninstance = optionclass("Name", self.gramps_database)
         optioninstance.load_previous_values()
         return optioninstance.options_dict, optioninstance.options_help
     else:
         return {}, {}
Beispiel #4
0
 def get_items(self, sort_handles=False):
     if self._cache is None:
         self._cache_map = {}
         pmgr = BasePluginManager.get_instance()
         cl_list = []
         for reg_action in [
                 "get_reg_reports", "get_reg_exporters", "get_reg_importers"
         ]:
             cl_list += getattr(pmgr, reg_action)()
         self._cache = sorted([(pdata.name, self.plugtype(pdata.ptype),
                                pdata.id) for pdata in cl_list])
         self.count = len(self._cache)
         for items in self._cache:
             self._cache_map[items[2]] = items
     return [x[2] for x in self._cache]
Beispiel #5
0
 def run_action(self, action, handler):
     options, options_help = self.get_plugin_options(action.handle)
     args = {}
     for key, default_value in options.items():
         args[key] = handler.get_argument(key)
     if action.ptype == "Report":
         output_file = "/tmp/%s.pdf" % action.name
         clr = run_report(self.gramps_database,
                          action.handle,
                          username=self.handler.current_user,
                          of=output_file,
                          off="pdf", **args)
         # can check for results with clr
         if clr:
             download_to_user(output_file, self.handler)
         else:
             handler.send_message("Error in report")
             handler.redirect(self.handler.app.make_url("/action"))
     elif action.ptype == "Import":
         filename = upload(args["i"], "/tmp/%s-%s-%s.%s" % (str(profile.user.username),
                                                              str(handle),
                                                              timestamp(),
                                                              args["iff"]))
         if filename is not None:
             result = import_file(self.gramps_database, filename, User()) # callback
             if result:
                 handler.redirect(self.handler.app.make_url("/action"))
             else:
                 handler.send_message("Error in import")
                 handler.redirect(self.handler.app.make_url("/action"))
     elif action.ptype == "Export":
         pmgr = BasePluginManager.get_instance()
         pdata = pmgr.get_plugin(action.handle)
         output_file = "/tmp/export." + pdata.extension
         result = export_file(self.gramps_database, output_file, User()) # callback
         if result:
             download_to_user(output_file, self.handler)
         else:
             handler.send_message("Error in export")
             handler.redirect(self.handler.app.make_url("/action"))