def get_solver(solver_name): if not get_plugin_path("solver"): return for f in [ FileObject(get_plugin_path("solver"), solver_name + ".py"), FileObject(get_plugin_path("solver"), solver_name, solver_name + ".py") ]: if f.exists: sys.path.insert(0, f.dir_name) try: py_mod = imp.load_source(solver_name, f.path) break except: log_traceback("Unable to load plugin {}".format(solver_name)) return else: logging.error("{} does not exist".format(f)) return if not "Plugin" in dir(py_mod): logging.error("No plugin class found in {}".format(f)) return return py_mod.Plugin
def render(self, template): import jinja2 tpl_dir = os.path.join(get_plugin_path("webtools"), self.name) jinja = jinja2.Environment(loader=jinja2.FileSystemLoader(tpl_dir)) jinja.filters["format_time"] = format_time jinja.filters["s2tc"] = s2tc jinja.filters["slugify"] = slugify template = jinja.get_template("{}.html".format(template)) return template.render(**self.context)
def get_validator(object_type, **kwargs): plugin_path = get_plugin_path("validator") if not plugin_path: return f = FileObject(plugin_path, object_type + ".py") if f.exists: try: py_mod = imp.load_source(object_type, f.path) except: log_traceback("Unable to load plugin {}".format(plugin_name)) return else: return if not "Plugin" in dir(py_mod): logging.error("No plugin class found in {}".format(f)) return return py_mod.Plugin(**kwargs)
def get_validator(object_type, **kwargs): plugin_path = get_plugin_path("validator") if not plugin_path: return f = FileObject(plugin_path, object_type + ".py") if f.exists: try: py_mod = imp.load_source(object_type, f.path) except Exception: log_traceback(f"Unable to load plugin {f.base_name}") return else: return if "Plugin" not in dir(py_mod): logging.error(f"No plugin class found in {f.base_name}") return return py_mod.Plugin(**kwargs)
def set_template(self, name): tpl_dir = os.path.join(get_plugin_path("webtools"), self.name) self.view.template_path = os.path.join(tpl_dir, "{}.html".format(name))