def run_plugins(configuration, section, output, test_id, func): result = [] plugin_list = configuration[section]["enabled_plugins"].split() plugin_base = PluginBase(package='plugins') plugin_source = plugin_base.make_plugin_source(searchpath=['./plugins']) for plugin_name in plugin_list: logging.debug(f"Executing {func} of plugin {plugin_name}.") plugin = plugin_source.load_plugin(plugin_name) try: function_to_call = getattr(plugin, func, None) if function_to_call != None: plugin_state = ", ".join(global_plugin_state.keys()) logging.debug( f"Current plugin state contains [{plugin_state}]") call_result = function_to_call(global_plugin_state, configuration[section], output, test_id) result.append(call_result) except Exception as e: logging.critical(f"Cannot invoke plugin {plugin_name}: {e}") return result
def __init__(self, db, rc, tmpdir, dpi): """ Create the renderer. Args: db (psycopg2 DB): The GIS database rc (RenderingConfiguration): rendering parameters. tmpdir (os.path): Path to a temp dir that can hold temp files. dpi (integer): output resolution for bitmap formats """ # Note: street_index may be None self.db = db self.rc = rc self.tmpdir = tmpdir self.grid = None # The implementation is in charge of it self.paper_width_pt = \ commons.convert_mm_to_pt(self.rc.paper_width_mm) self.paper_height_pt = \ commons.convert_mm_to_pt(self.rc.paper_height_mm) self._title_margin_pt = 0 self.dpi = dpi plugin_path = os.path.abspath( os.path.join(os.path.dirname(__file__), './render_plugins')) self.plugin_base = PluginBase(package='ocitysmap.layout_plugins') self.plugin_source = self.plugin_base.make_plugin_source( searchpath=[plugin_path])
def __init__(self): if Hoster.plugin_source is not None: return plugin_base = PluginBase(package='hoster.plugins') Hoster.plugin_source = plugin_base.make_plugin_source( searchpath=['./hoster']) with Hoster.plugin_source: for p in Hoster.plugin_source.list_plugins(): h = Hoster.plugin_source.load_plugin(p) if not hasattr(h, p): log.debug("Plugin " + p + " is invalid (No class named " + p + "in module)") continue if not Config.get("hoster/" + p + "/active", True): continue h = getattr(h, p) if not configured(h): log.error("Plugin " + h.__name__ + " is activated but not configured. Deactivating.") continue h = h() h.plugin_name = p if not isinstance(h, BasePlugin): log.error("Plugin " + p + " is invalid (Not extending BasePlugin)") continue log.debug("Loaded plugin " + p) Hoster.hoster.append(h) for n in h.config_values: if not Config.get("hoster/" + p + "/" + n): print "Hoster", p, \ "needs a", n + ". You need to add a", n, "for", p, "to config.json " \ "to use the plugin."
def reload_plugins(): global __db_sources, __loaded_plugins, source, builtins_source __db_sources = [] __loaded_plugins = {} base = PluginBase(package='metgem_app.plugins') if source is not None: source = None source = base.make_plugin_source(searchpath=[PLUGINS_PATH], identifier="MetGem") if builtins_source is None: builtins_source = base.make_plugin_source(searchpath=[os.path.join(APP_PATH, 'metgem_app', 'plugins')], identifier="MetGem_builtins") for plugin_name in builtins_source.list_plugins(): plugin = load_plugin(builtins_source, plugin_name) if plugin is not None: __loaded_plugins[plugin_name] = plugin for plugin_name in source.list_plugins(): plugin = load_plugin(source, plugin_name) if plugin_name in __loaded_plugins: if plugin.__version__ >= __loaded_plugins[plugin_name].__version__: __loaded_plugins[plugin_name] = plugin for plugin in __loaded_plugins.values(): for name, obj in inspect.getmembers(plugin, inspect.isclass): if issubclass(obj, DbSource): register_db_source(obj())
def __init__(self, config): """ Creates a new instance of ts3base and initializes all neccessary parameters """ # init threading threading.Thread.__init__(self) # set config for whole class self.config = config # debug message self.debprint('instance initialized') # init callbacks self.callbacks = defaultdict(dict) # list of all classes (instances, objects, however) self.classes = {} # identifier + package name for pluginbase self.identifier = config['id'] self.package = 'ts3eventscripts' + self.identifier # init pluginbase self.pluginbase = PluginBase(package=self.package) # lock for command socket send & receive method self.sendlock = Lock() # init ts3 connection self.ts3_init() # load user plugins self.plugin_load() for plugin in self.pluginsource.list_plugins(): self.debprint(plugin) # init all plugins self.plugin_init()
def __init__(self, name, params): self.logger = logging.getLogger(self.__class__.__name__) self.pluginParams = params self.name = name self.name_lower = name.lower() self.moduleName = self.name_lower.capitalize() self.subject_aggregated = False self.subject_aggregated_default = False self.paths = paths.paths_dict() self.plugin_base = PluginBase(package='ExperimentRunner.plugins') if self.name_lower == 'android' or self.name_lower == 'trepn' or self.name_lower == 'batterystats': plugin_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'Plugins') self.plugin_source = self.plugin_base.make_plugin_source(searchpath=[plugin_path]) self.pluginModule = self.plugin_source.load_plugin(self.moduleName) self.currentProfiler = getattr(self.pluginModule, self.moduleName)(params, self.paths) self.name = self.name_lower else: plugin_path = os.path.join(paths.CONFIG_DIR, 'Plugins') if os.path.isdir(plugin_path): copyfile(os.path.join(paths.ROOT_DIR, 'ExperimentRunner', 'Plugins', 'Profiler.py'), os.path.join( plugin_path, 'Profiler.py')) self.plugin_source = self.plugin_base.make_plugin_source(searchpath=[plugin_path]) self.pluginModule = self.plugin_source.load_plugin(self.name) self.currentProfiler = getattr(self.pluginModule, self.name)(params, self.paths) else: raise ImportError self.logger.debug('%s: Initialized' % self.name)
def __init__(self, filter_file: str = "filters.py", mapping_path: str = "mapping.json", feed_source: str = None): self.feed_source: str = feed_source self.filters_file: str = os.path.abspath(filter_file) self.mapping_path: str = os.path.abspath(mapping_path) self.mapping_json: dict = self._load_json(self.mapping_path) self._plugin = None self._filter_module = os.path.splitext( os.path.basename(self.filters_file) )[0] # # Load filter file as a Python plugin # if self.filters_file: # # Load dynamically the source code # plugin_base = PluginBase(package='feed_to_exporter.plugins') self._plugin = plugin_base.make_plugin_source( searchpath=[ os.path.dirname(self.filters_file)]) self._target_url_fixed = None self._token: dict = None self._mapping_obj: SimpleNamespace = None self._wordpress_api: str = None
def run(cu_xml: str, dep_file: str, loop_counter_file: str, reduction_file: str, plugins: List[str]) \ -> DetectionResult: cu_dict, dependencies, loop_data, reduction_vars = parse_inputs( cu_xml, dep_file, loop_counter_file, reduction_file) pet = PETGraphX(cu_dict, dependencies, loop_data, reduction_vars) # TODO add visualization # pet.show() plugin_base = PluginBase(package='plugins') plugin_source = plugin_base.make_plugin_source( searchpath=[Path(__file__).parent / 'plugins']) for plugin_name in plugins: p = plugin_source.load_plugin(plugin_name) print("executing plugin before: " + plugin_name) pet = p.run_before(pet) pattern_detector = PatternDetectorX(pet) res: DetectionResult = pattern_detector.detect_patterns() for plugin_name in plugins: p = plugin_source.load_plugin(plugin_name) print("executing plugin after: " + plugin_name) pet = p.run_after(pet) return res
def get_source(checker_paths=[]): """Load all of the checkers using pluginbase.""" # define the "package" in which the checks reside # the term "package" corresponds to "module.sub-module" checker_base = PluginBase(package=constants.packages.Checks) # remove any directories from the path listings that are Nothing (i.e., "") # this case occurs when the optional --checkerdir is not provided on command-line if constants.markers.Nothing in checker_paths: checker_paths.remove(constants.markers.Nothing) # Create the directory where the internal checkers live inside of GatorGrader. # Note that this directory includes the home for GatorGrader, which can be set # by an environment variable and otherwise defaults to the directory from which # GatorGrader was run and then the directory where internal checkers are stored. internal_checker_path = files.create_path( constants.checkers.Internal_Checkers_Dir, home=util.get_gatorgrader_home()) # create the listing of the paths that could contain checkers, including # all of the provided paths for external checkers and the directory that # contains all of the internal checkers provided by GatorGrader all_checker_paths = checker_paths + [str(internal_checker_path)] # Create and return a source of checkers using PluginBase. # The documentation for this function advices that you # give an identifier to the source for the plugins # because this will support saving and transfer, if needed. # Only perform this operation if the checker source is None, # meaning that it has not already been initialized. # pylint: disable=global-statement global CHECKER_SOURCE if CHECKER_SOURCE is None: CHECKER_SOURCE = checker_base.make_plugin_source( identifier=constants.checkers.Plugin_Base_Identifier, searchpath=all_checker_paths, ) return CHECKER_SOURCE
def run(cu_xml: str, dep_file: str, loop_counter_file: str, reduction_file: str, plugins: List[str], file_mapping: Optional[str] = None, cu_inst_result_file: Optional[str] = None, llvm_cxxfilt_path: Optional[str] = None) -> DetectionResult: pet = PETGraphX.from_parsed_input( *parse_inputs(cu_xml, dep_file, loop_counter_file, reduction_file)) # TODO add visualization # pet.show() plugin_base = PluginBase(package='plugins') plugin_source = plugin_base.make_plugin_source( searchpath=[Path(__file__).parent / 'plugins']) for plugin_name in plugins: p = plugin_source.load_plugin(plugin_name) print("executing plugin before: " + plugin_name) pet = p.run_before(pet) pattern_detector = PatternDetectorX(pet) res: DetectionResult = pattern_detector.detect_patterns( cu_xml, dep_file, loop_counter_file, reduction_file, file_mapping, cu_inst_result_file, llvm_cxxfilt_path) for plugin_name in plugins: p = plugin_source.load_plugin(plugin_name) print("executing plugin after: " + plugin_name) pet = p.run_after(pet) return res
def __init__(self): # Setup a plugin base for "machine_stats.plugins" and make sure to load # all the default built-in plugins from the plugins folder. self._base = PluginBase(package="machine_stats_plugins", searchpath=[get_path("./plugins")]) self._source = self._base.make_plugin_source(searchpath=[])
def setup_pluginbase(extra_policies_path=None): """Sets up plugin base with default path and provided path Args: extra_policies_path (str): Extra path to find plugins in Returns: PluginSource: PluginBase PluginSource for finding plugins """ here = pathlib.Path(__file__).parent.absolute() default_path_obj = here / "../policies" default_path = str(default_path_obj.resolve()) all_paths = [default_path] if extra_policies_path: extra_policies_obj = pathlib.Path(extra_policies_path) if extra_policies_obj.is_dir(): extra_policies = get_directory_path(extra_policies_obj) all_paths.insert(0, str(extra_policies)) else: raise InvalidPoliciesDirectory LOG.info("Searching for policies in %s", str(all_paths)) plugin_base = PluginBase(package='lavatory.policy_plugins') plugin_source = plugin_base.make_plugin_source(searchpath=all_paths) LOG.debug("Policies found: %s", str(plugin_source.list_plugins())) return plugin_source
def __init__(self, db, rc, tmpdir, dpi): """ Create the renderer. Args: rc (RenderingConfiguration): rendering parameters. tmpdir (os.path): Path to a temp dir that can hold temp files. street_index (StreetIndex): None or the street index object. """ # Note: street_index may be None self.db = db self.rc = rc self.tmpdir = tmpdir self.grid = None # The implementation is in charge of it self.paper_width_pt = \ commons.convert_mm_to_pt(self.rc.paper_width_mm + 2 * self.PRINT_BLEED_MM) \ + 2 * self.PRINT_SAFE_MARGIN_PT self.paper_height_pt = \ commons.convert_mm_to_pt(self.rc.paper_height_mm + 2 * self.PRINT_BLEED_MM) \ + 2 * self.PRINT_SAFE_MARGIN_PT self._title_margin_pt = 0 self.dpi = dpi plugin_path = os.path.abspath(os.path.join(os.path.dirname(__file__), './render_plugins')) self.plugin_base = PluginBase(package='ocitysmap.layout_plugins') self.plugin_source = self.plugin_base.make_plugin_source(searchpath=[plugin_path])
def __init__(self): PluginBase.__init__(self) self.name = 'WebTools' self.logger = logging.getLogger('teslabot.plugin.webtools') # Load imageboard URL parser settings try: self.imageboard_urls = Config().get(self.name.lower(), 'imageboard').split() except ConfigParser.NoSectionError: self.logger.debug('Imageboard settings not found.') self.imageboard_urls = [] self.news = { 'lupdate': None, 'uinterval': 60 * 5, 'cur_ed': 'us', 'set': False, } self.strings.URL_GOOGLE = 'https://news.google.com/news?edchanged=1&ned={0}&authuser=0' self.strings.URL_GOOGLE_SEARCH = 'https://www.google.com/search?hl=en&gl=us&tbm=nws&authuser=0&q={0}' self.strings.NO_NEWS_SET = 'There is no news set currently selected. Type news help ' \ 'for more information.' self.strings.KEYWORD_NOT_FOUND = 'No news items found.' self.strings.NEWS_SET_REFRESHED = 'The news set has been updated!'
def GetConfig(self): services = self.GetServices() config = "" # Use PluginBase to find the plugins here = os.path.abspath(os.path.dirname(__file__)) get_path = partial(os.path.join, here) plugin_base = PluginBase(package='plugins') plugin_source = plugin_base.make_plugin_source( searchpath=[get_path('plugins')]) # Call each plugin and pass in the list of services for plugin_name in plugin_source.list_plugins(): plugin = plugin_source.load_plugin(plugin_name) # Add each plugin output to the config string we're building section = plugin.invoke(services) if (section is not None): config = (config + str(section)) defaultSection = self.GenerateDefaultInputConfig(config) if (defaultSection is not None): print( "No data sources configured or detected. Enabling default: device temperature." ) config = (config + str(defaultSection)) return config
def _init_manager(self): if self.init: return self.plugin_base = PluginBase(package='burpui.plugins.ext') self.plugin_source = self.plugin_base.make_plugin_source( searchpath=self.searchpath) self.init = True
def __init__(self, loop: AbstractEventLoop): # init event loop and dispatcher self._loop = loop self._ch = Channel(self._loop) logging.basicConfig( format= '%(asctime)s [%(levelname)s] (%(pathname)s:%(lineno)d): %(message)s', datefmt='%Y-%m-%d %H:%M:%S') self._loger = logging.getLogger() self._loger.setLevel("DEBUG") # load plugins plugin_base = PluginBase("my_plugin") self._plugin_source = plugin_base.make_plugin_source( searchpath=["./plugins"]) self._plugins = dict() for name in self._plugin_source.list_plugins(): self._loger.debug("loading: " + name) plugin = self._plugin_source.load_plugin(name) if hasattr(plugin, "setup"): self._plugins[name] = plugin.setup(self._loop, self._ch, self._loger) # after setup self._loop.run_until_complete(self.on_setup_done())
def __init__(self): PluginBase.__init__(self) self.name = 'Trivia' self.logger = logging.getLogger('teslabot.plugin.trivia') self.alive = True try: self.channel = Config().get(self.name.lower(), 'channel') except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): self.logger.warn('Unable to load trivia plugin. Channel name is missing.') # This ensures this plugin is never called self._callbacks = [] return # Number of 5 second intervals between asking a question or giving a hint self.askpause = 2 # Default number of questions to ask in a round self.defaultnumquestions = 10 self.startingmsg = u"Trivia starting. Questions: {0}" self.stoppingmsg = u"Trivia stopping." self.questionmsg = u"Q{2}. [{0}] {1}" self.okanswermsg = u"{0} got it for {1} points. Total: {2}, streak: {3}. " \ + u"Answer: {4}" self.noanswermsg = u"No one got it. The answer was: {0}" self.rankingsmsg = u"{0} wins! Final scores: {1}" self.skippingmsg = u'Skipping this terrible question.' self.nextvotemsg = u'{0} voted to skip this question. {1} more votes needed.' self.roundendmsg = u"Round of trivia complete. '.trivia [number]' to start " \ + u"playing again." self.questions = load_questions(os.path.abspath('plugins/trivia')) self.logger.info("Loaded {0} trivia questions.".format(len(self.questions))) self.reset()
def _initialize_plugin_source(self): plugin_base = PluginBase(package='cis.plugins.validation') plugin_source = plugin_base.make_plugin_source(searchpath=[ os.path.join(os.path.abspath(os.path.dirname(__file__)), '../plugins/validation/') ]) return plugin_source
def __init__(self, **kwargs): logging.getLogger(__name__) package = kwargs.get('package', 'rule_backend.plugins') self._plugin_base = PluginBase(package=package) self._plugin_dir = kwargs.get('plugin_dir', '.') plugin_path = self.get_path(self._plugin_dir) self._source = self._plugin_base.make_plugin_source( searchpath=[plugin_path])
def __init__(self): PluginBase.__init__(self) self.name = 'XDCC' self.logger = logging.getLogger('teslabot.plugin.XDCC') self._qtimeout = 1 self._dcc_port = 6500 self._dcc_ip = None self.working_dir = None try: self._dcc_ip = Config().get(self.name.lower(), 'ip') except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) as e: pass try: self._dcc_port = Config().get(self.name.lower(), 'port') except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) as e: pass try: self.working_dir = Config().get(self.name.lower(), 'directory') if not os.path.isdir(self.working_dir): self.working_dir = None self.logger.debug('Provided directory path is not valid.') except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) as e: pass finally: if self.working_dir == None: # Cannot load directory path; disable XDCC commands self.chat_commands = [] self.logger.debug('Cannot load directory path. XDCC commands disabled.') self._sessions = FileSessionManager(self.working_dir) self._server = None # A list of DCCSocket clients. They may or may not be active. self._manager = DCCSocketManager() # Number of activate file transfers self._transfers_active = 0 # Maximum number of file transfers self.max_conns = 5 # Time to wait (in secs) before closing the server to new connections self.new_conn_timeout = 20 # Last time (in UNIX secs) that a new server connection was expected self._last_request = None self.strings.TRANSFER_FAILURE = u'[{0}] failed!' self.strings.TRANSFER_SUCCESS = u'[{0}] was successful!' self.strings.QUEUE_FULL = u'There is currently a file transfer ' \ u'waiting to be accepted. Please try again in a few seconds.' self.strings.ACTIVE_CONN_PLURAL = u'There are currently {0} active ' \ u'connections.' self.strings.ACTIVE_CONN_SINGULAR = u'There is currently one active ' \ u'connection.' self.strings.ACTIVE_CONN_NONE = u'There are no active connections.'
def _load_notifier(self, name, params={}): plugin_base = PluginBase(package="check_certs.plugins") plugin_source = plugin_base.make_plugin_source( searchpath=[os.path.join(os.path.dirname(__file__), "./plugins")]) # keep a reference to the plugin self.plugin_source.add(plugin_source) plugin = plugin_source.load_plugin(name + "_notifier") plugin.setup(self, params)
def get_plugin_source(): """Creates and returns a 'plugin_source' object as defined by PluginBase, which provides access plugins. """ here = os.path.abspath(os.path.dirname(__file__)) get_path = partial(os.path.join, here) plugin_base = PluginBase(package='plugins') plugin_source = plugin_base.make_plugin_source(searchpath=[get_path('plugins')]) return plugin_source
def load_plugins(): """Load plugins.""" plugin_base = PluginBase(package="dontforget.plugins") plugin_source = plugin_base.make_plugin_source( identifier=DEFAULT_PIPES_DIR_NAME, searchpath=[str(Path(__file__).parent / DEFAULT_PIPES_DIR_NAME)], persist=True, ) for plugin_module in plugin_source.list_plugins(): plugin_source.load_plugin(plugin_module)
def import_plugins(plugin_mount, plugin_base_dir): ''' Imports all plugins in plugin_base_dir with packagename plugin_mount :param plugin_mount: The packagename that the plugins will reside in :param plugin_base_dir: The directory that contains the plugins :return: A pluginbase.PluginSource containing all plugins from plugin_base_dir ''' plugin_base = PluginBase(package=plugin_mount) plugin_src_dirs = _get_plugin_src_dirs(plugin_base_dir) return plugin_base.make_plugin_source(searchpath=plugin_src_dirs)
def load_plugins(self): self.discord_callbacks = dict() self.discord_commands = dict() self.plugins = dict() self.plugin_base = PluginBase(package='__main__.plugins') self.plugin_source = self.plugin_base.make_plugin_source( searchpath=[os.path.join(self.cube_root, "./plugins")]) for plugin in self.plugin_source.list_plugins(): self.plugins[plugin] = self.plugin_source.load_plugin(plugin) self.plugins[plugin].Plugin(self) self.logger.info(f'Loaded "{plugin}" into the plugin cache.')
def load_plugins(): current_dir = os.path.abspath( os.path.dirname(os.path.abspath(os.path.dirname(__file__)))) plugin_dir = os.path.join(current_dir, 'plugin') plugin_base = PluginBase(package='plugin', searchpath=[plugin_dir]) plugin_source = plugin_base.make_plugin_source(searchpath=[plugin_dir], persist=True) plugin_dict = {} for plugin_name in plugin_source.list_plugins(): plugin_dict[plugin_name] = plugin_source.load_plugin(plugin_name) return plugin_dict
def __init__(self): PluginBase.__init__(self) self.name = 'Statistics' self.logger = logging.getLogger('teslabot.plugin.statistics') self.conn = None self.alive = True self.path_schema = os.path.abspath('plugins/statistics/schema.sql') self.path_statsdb = os.path.abspath('plugins/statistics/stats.sqlite3') self.channels = {} self.users = {}
def _init_plugins(self): self.plugin_base = PluginBase( package='filter_plugins.{}'.format(self.FILTER_TYPE)) self.filter_plugins = dict() self.plugin_source = self.plugin_base.make_plugin_source(searchpath=[ os.path.join(get_dir_of_file(__file__), '../filter_plugins/{}'.format(self.FILTER_TYPE)) ]) plugin_list = self.plugin_source.list_plugins() for item in plugin_list: plugin = self.plugin_source.load_plugin(item) plugin.setup(self)
def load_authentication_plugin(server_folder, plugin_name): try: from pluginbase import PluginBase plugin_base = PluginBase(package="plugins/authenticator") plugins_dir = os.path.join(server_folder, "plugins", "authenticator") plugin_source = plugin_base.make_plugin_source( searchpath=[plugins_dir]) auth = plugin_source.load_plugin(plugin_name).get_class() return auth except: print("Error loading authenticator plugin '%s'" % plugin_name) raise
def __init__(self, resource, provider): path = pathlib.Path(__file__).parent.resolve() path = path / resource all_paths = [str(path)] self.paths = all_paths self.provider = provider plugin_base = PluginBase(package='foremast.plugins') self.plugin_source = plugin_base.make_plugin_source( searchpath=self.paths, persist=True)
def loadplugins(pluginbasepath, verbose=False, silent=False): plugin_base = PluginBase(package='gtool.plugins') plugin_source = plugin_base.make_plugin_source(searchpath=__enumerateplugins(pluginbasepath), identifier='gtool', persist=True) _plugins = plugin_source.list_plugins() for plugin_name in _plugins: #plugin_source.list_plugins(): if verbose: print('[VERBOSE] loading plug-in:', plugin_name) _plugin = plugin_source.load_plugin(plugin_name) registerPlugin(plugin_name.upper(), _plugin.load()) if not verbose and not silent: print('Loaded %s plugins (use verbose mode to list them)' % len(_plugins))
def __init__(self, api: "bubblesub.api.Api") -> None: """Initialize self. :param api: core API """ super().__init__() self._api = api self._cmd_registry: T.Dict[str, T.Tuple[str, T.Type[BaseCommand]]] = {} self._plugin_menu: T.List[MenuItem] = [] self._plugin_base = PluginBase(package="bubblesub.api.cmd.plugins") self._plugin_sources: T.Dict[str, T.Any] = {} self._plugin_modules: T.List[T.Any] = []
def main(): plugin_base = PluginBase(package='plugins') plugin_source = plugin_base.make_plugin_source(searchpath=['plugins']) for plugin in plugin_source.list_plugins(): p = plugin_source.load_plugin(plugin) p.do_something() for k, v in p.__dict__.items(): if not inspect.isclass(v): continue print(type(v)) if issubclass(v.__class__, BaseClass.__class__): print(k)
def load_authentication_plugin(server_folder, plugin_name): try: from pluginbase import PluginBase plugin_base = PluginBase(package="plugins/authenticator") plugins_dir = os.path.join(server_folder, "plugins", "authenticator") plugin_source = plugin_base.make_plugin_source( searchpath=[plugins_dir]) auth = plugin_source.load_plugin(plugin_name).get_class() # it is necessary to keep a reference to the plugin, otherwise it is removed # and some imports fail auth.plugin_source = plugin_source return auth except: print("Error loading authenticator plugin '%s'" % plugin_name) raise
def __init__(self): PluginBase.__init__(self) self.name = 'Paulcon' self.logger = logging.getLogger('teslabot.plugin.paulcon') self.LEVEL_MSG = [["IT'S OVER", C_BLACK], ["IT'S HAPPENING", C_RED], ["IT'S TOO LATE", C_RED], ["YOU CAN'T STOP IT", C_BROWN], ["YOU ASKED FOR THIS", C_BROWN], ["YOU COULD HAVE PREVENTED THIS", C_YELLOW], ["WHY DIDN'T YOU LISTEN?", C_YELLOW], ["YOU DIDN'T LISTEN", C_YELLOW], ["IT BEGINS", C_YELLOW], ["IT HASN'T EVEN BEGUN", C_GREEN]] self.cur_level = 9 self.cur_time = datetime.fromtimestamp(int(time.time())).strftime('%Y-%m-%d %H:%M')
def load_plugins(conf): plugin_path = [pkg_resources.resource_filename('wtf', 'plugins')] try: plugin_path += conf['common']['plugin_path'] except (KeyError, TypeError): pass plugin_base = PluginBase('wtf.plugins') plugin_source = plugin_base.make_plugin_source(searchpath=plugin_path) plugins = [] for plugin_name in plugin_source.list_plugins(): plugin_module = plugin_source.load_plugin(plugin_name) _classes = inspect.getmembers(plugin_module, inspect.isclass) plugins += [_class for name, _class in _classes if issubclass(_class, Plugin) and not _class == Plugin] return plugins
def load_plugins(): here = os.path.abspath(os.path.dirname(__file__)) get_path = partial(os.path.join, here) plugin_dir = get_path('plugins') plugin_base = PluginBase( package='wafw00f.plugins', searchpath=[plugin_dir] ) plugin_source = plugin_base.make_plugin_source( searchpath=[plugin_dir], persist=True ) plugin_dict = {} for plugin_name in plugin_source.list_plugins(): plugin_dict[plugin_name] = plugin_source.load_plugin(plugin_name) return plugin_dict
def __init__(self): PluginBase.__init__(self) self.name = 'CoreCommands' self.logger = logging.getLogger('teslabot.plugin.corecommands') self.set_cmd('kick', self.CMD_CHANNEL) self.set_cmd('kickban', self.CMD_CHANNEL) self.set_cmd('ban', self.CMD_CHANNEL) self.set_cmd('unban', self.CMD_CHANNEL) self.admin_commands = ['reload', 'say', 'action', 'join', 'leave', 'quit', 'nick', 'plugins'] self.lang_001 = 'Plugins: {0}' self.lang_002 = 'Type \x0310{0}commands\x03 for a list of available commands. Type \x0310{0}(command) help\x03 ' \ 'to view the help text of a specific command. Note that the parentheses should not be included.' self.lang_003 = 'Goodbye.' self.users = {}
def __init__(self): PluginBase.__init__(self) self.name = 'WebTools' self.logger = logging.getLogger('teslabot.plugin.webtools') # Load imageboard URL parser settings try: self.imageboard_urls = Config().get(self.name.lower(), 'imageboard').split() except ConfigParser.NoSectionError: self.logger.debug('Imageboard settings not found.') self.imageboard_urls = [] self.news = { 'lupdate': None, 'uinterval': 60*5, 'cur_ed': 'us', 'set': False, } self.strings.URL_GOOGLE = 'https://news.google.com/news?edchanged=1&ned={0}&authuser=0' self.strings.URL_GOOGLE_SEARCH = 'https://www.google.com/search?hl=en&gl=us&tbm=nws&authuser=0&q={0}' self.strings.NO_NEWS_SET = 'There is no news set currently selected. Type news help ' \ 'for more information.' self.strings.KEYWORD_NOT_FOUND = 'No news items found.' self.strings.NEWS_SET_REFRESHED = 'The news set has been updated!'
#!/usr/bin/env python # -*- coding: utf-8 -*- from __future__ import absolute_import import click from .config import config # Treat commands as plugins with the help of `pluginbase` library from pluginbase import PluginBase plugin_base = PluginBase(package='cmdr.commands') plugin_source = plugin_base.make_plugin_source(searchpath=[config.COMMANDS_PATH]) class Commander(object): def get_command(self, command_name): for plugin_name in plugin_source.list_plugins(): if plugin_name == command_name: command = plugin_source.load_plugin(plugin_name) return command else: raise RuntimeError( 'Command `{0}` not found. Please ensure that a Python ' 'module (or package) named "{0}.py" (or "{0}/__init__.py") ' 'exists in "{1}"'.format(command_name, config.COMMANDS_PATH) ) def get_command_list(self):
#import application #import models #import response #import security from pluginbase import PluginBase plugin_base = PluginBase(package='imp.plugins') plugin_src = plugin_base.make_plugin_source(searchpath=["./plugins"]) #plugin_src.appdata = {"app": application, "models": models, "response": response, "security": security} plugins = [] for plugin in plugin_src.list_plugins(): plugins.append(plugin_src.load_plugin(plugin))
class Pluggable(object): name = 'Pluggable' def setup(self, name=None, paths=None): paths = paths or ['./plugins'] self.plugin_base = PluginBase(package='plugins') self.setup_source(name) def setup_source(self, name): # and a source which loads the plugins from the "app_name/plugins" # folder. We also pass the application name as identifier. This # is optional but by doing this out plugins have consistent # internal module names which allows pickle to work. self.source = self.plugin_base.make_plugin_source( searchpath=[get_path('./plugins')], identifier=name) def import_plugin(self, name): ''' Import a plugin by name ''' return self.source.load_plugin(name) def register_load(self): ''' Load the plugins, registering classes, modules and functions outside the plugin loader. Returned is a list of registered plugins. ''' plugins = [x for x in self.source.list_plugins()] _s = 's' if len(plugins) != 1 else '' print 'setting up from {0} plugin location{1}'.format(len(plugins), _s) return self.load_plugins() def load_plugins(self): # Here we list all the plugins the source knows about, load them # and the use the "setup" function provided by the plugin to # initialize the plugin. plugins = self.source.list_plugins() for plugin_name in plugins: self.source.load_plugin(plugin_name) return _registered_plugins def register_iter(self): for plugin in _registered_plugins: yield plugin def create(self, app): ''' iterate the plugins, instansiating each and proving a pointer ''' for plugin in _registered_plugins: if hasattr(plugin, 'instance') is False: inst = self.create_instance(plugin) inst.app = app ri = IPlugin(plugin.entity, inst) _registered_plugins[_registered_plugins.index(plugin)] = ri def create_instance(self, plugin): ''' Return an instance of a pluggable object based upon the entity provided. If a class is provided, it's assumed this is correctly foratted. IF a method is passed an instance of Plugin is generated with the name of the function as the command. ''' if hasattr(plugin, 'entity') is False: import pdb; pdb.set_trace() # breakpoint 1703bfb0 // entity = plugin.entity # print plugin if isclass(entity): inst = entity() elif isfunction(entity): inst = Plugin(entity.__name__, entity) else: inst = entity # get name # create plugin return inst def register_reduce(self, name, init_value): ''' reduce the value through each name on the register list. returned is the value passed through all register methods defined by the name argument ''' v = init_value for rplugin in self.register_iter(): _v = getattr(rplugin.instance, name)(v) v = _v if _v is not None else v return v def generate_commands(self, app): ''' Iterate each command, producing the correct methods to be implemented on the core object. ''' gdo = [] ghelp = [] gcmpl = [] for rplugin in self.register_iter(): inst = rplugin.instance name, perf = self.generate_do_commands(app, inst) gdo.append(name) name, perf = self.generate_help_commands(app, inst) ghelp.append(name) name, perf = self.generate_complete_commands(app, inst) gcmpl.append(name) self.do_commands = gdo self.help_commands = ghelp self.complete_commands = gcmpl def generate_do_commands(self, app, inst): if hasattr(inst, 'perform'): # build attr name = inst.get_command_name() perf = partial(self.run_command, inst.perform, app) setattr(app, name, perf) return (name, perf) def generate_help_commands(self, app, inst): if hasattr(inst, 'help'): # build attr name = inst.get_help_name() perf = partial(self.run_help, inst.help, app) setattr(app, name, perf) return (name, perf) def generate_complete_commands(self, app, inst): if hasattr(inst, 'complete'): # build attr name = inst.get_complete_name() perf = partial(self.run_complete, inst.complete, app) setattr(app, name, perf) return (name, perf) def run_help(self, perform_method, app, *args): ''' Run a help command ''' help_str = None if isinstance(perform_method, (str, unicode)): help_str = perform_method elif ismethod(perform_method): help_str = perform_method(app) app._out(help_str) return help_str def run_command(self, perform_method, app, *args, **kw): ''' run a command as handled by the app called by partial() providing the app as the first arg. ''' v = perform_method(app, *args, **kw) if v is not None: app._out(v) return v def run_complete(self, perform_method, app, *args): '''''' v = perform_method(app, *args) if v is not None: app._out(v) return v def __getattr__(self, name): ''' delegate to a reduce value through the plugins ''' if hasattr(Plugin, name): return partial(self.register_reduce, name) else: raise AttributeError('{0} is not defined on Plugin'.format(name))
amp = 1 generators = [] generatorsByName = {} generatorList = {} currentTime = time.time() print "==== PARTYLED ====\nSimulation: ", IsSimulated class wrapper_Application(object): def register_generator(self, name, generator): global generatorList generatorList[name] = generator wrapperApp = wrapper_Application() generatorBase = PluginBase(package='partyled.generatorplugins') generatorSource = generatorBase.make_plugin_source(searchpath=[get_path('./generators/')]) for plugin_name in generatorSource.list_plugins(): plugin = generatorSource.load_plugin(plugin_name) plugin.setup(wrapperApp, STRIPCOUNT) print "! Generator plugins: ", generatorList.items() def setupPWM(): pwm1 = PWM(0x40) # PCA9685 board one pwm2 = PWM(0x41) # PCA9685 board two pwm1.setPWMFreq(100) # Not too low, to keep responsiveness to signals high pwm2.setPWMFreq(100) # Also not too high, to prevent voltage rise to cut off and reduce brightness return (pwm1, pwm2)
import objc import sys import os my_path = NSBundle.bundleForClass_(objc.lookUpClass("CSShapeCapture").class__()).resourcePath() + "/Python" sys.path.append(my_path) from pluginbase import PluginBase from Foundation import * from CSShapePathWrapper import * sys.dont_write_bytecode = True plugin_base = PluginBase(package='shapeplugins') library_dirs = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSAllDomainsMask - NSSystemDomainMask, YES) plugin_dirs = map(lambda x: x + "/Application Support/CocoaSplit/Plugins/Paths", library_dirs) plugin_dirs.append(NSBundle.bundleForClass_(objc.lookUpClass("CSShapeCapture").class__()).builtInPlugInsPath() + "/Paths") plugin_source = plugin_base.make_plugin_source(searchpath=plugin_dirs) class CSShapePathLoader(NSObject): def init(self): self = objc.super(CSShapePathLoader,self).init() return self @objc.signature('@@:@') def pathLoaderPath_(self, pluginName):
from pluginbase import PluginBase base = PluginBase(package='dummy.modules') plugin_source = base.make_plugin_source( searchpath=['./plugins']) # This dangles around. This will be collected when the interpreter # shuts down. hello = plugin_source.load_plugin('hello')
import datetime import os import sqlalchemy.exc from pluginbase import PluginBase from footynews.aggregator.base import Article, InvalidArticle from footynews.daily_report import DailyReport from footynews.db.models import Articles, db_session here = os.path.abspath(os.path.dirname(__file__)) plugin_base = PluginBase(package="web_scraping") plugin_source = plugin_base.make_plugin_source(searchpath=[os.path.join(here, "web_scraping_plugins")]) def main(): daily_report = DailyReport(datetime.date.today()) for plugin in plugin_source.list_plugins(): source = plugin_source.load_plugin(plugin).setup() for article in getattr(source, "extract")(): if isinstance(article, Article): try: db_session.add(Articles(article)) db_session.commit() except sqlalchemy.exc.IntegrityError as e: if "duplicate key value violates unique constraint" in e.args[0]: print(" Article url {0} already exists".format(article.url)) db_session.rollback() daily_report.update(article) if datetime.datetime.now().hour == 23:
You should have received a copy of the GNU General Public License along with 'git gud'. If not, see <http://www.gnu.org/licenses/>. """ import sys import os import spacy.en from . import nlp # plugins from pluginbase import PluginBase plugin_base = PluginBase(package='gitgud.plugins') plugin_source = plugin_base.make_plugin_source( searchpath=['./plugins', '/usr/share/git/git-gud/plugins']) for p in plugin_source.list_plugins(): plugin_source.load_plugin(p) from xmlrpc.server import SimpleXMLRPCServer PORT = 4224 # Daemonization def detach(): os.chdir('/')
__author__ = 'avishai' import pkg_resources from pluginbase import PluginBase plugins_path = pkg_resources.resource_filename('wtf', 'plugins') plugin_base = PluginBase('wtf.plugins') plugin_source = plugin_base.make_plugin_source(searchpath=[plugins_path]) def load_plugin(name): return plugin_source.load_plugin(name)
def setup(self, name=None, paths=None): paths = paths or ['./plugins'] self.plugin_base = PluginBase(package='plugins') self.setup_source(name)
def setup_module(module): global plugin_source plugin_base = PluginBase(package='hoster.plugins') plugin_source = plugin_base.make_plugin_source( searchpath=['../hoster'])
def _load_plugins(plugin_path, plugins, plugin_filter, filter_class, base_url, internal_attributes=None, *args): """ Loads endpoint plugins :type plugin_path: list[str] :type plugins: list[str] :type plugin_filter: (type | str) -> bool :type internal_attributes: dict[string, dict[str, str | list[str]]] :type args: Any :rtype list[satosa.plugin_base.endpoint.InterfaceModulePlugin] :param plugin_path: Path to the plugin directory :param plugins: A list with the name of the plugin files :param plugin_filter: Filter what to load from the module file :param args: Arguments to the plugin :return: A list with all the loaded plugins """ plugin_base = PluginBase(package='satosa_plugins') plugin_source = plugin_base.make_plugin_source(searchpath=plugin_path) loaded_plugins = [] loaded_plugin_names = [] for module_file_name in plugins: try: module = plugin_source.load_plugin(module_file_name) for name, obj in inspect.getmembers(module, plugin_filter): loaded_plugins.append(obj(base_url, *args)) loaded_plugin_names.append(module_file_name) except ImportError as error: LOGGER.debug("Not a py file or import error '%s': %s", module_file_name, error) dict_parsers = [_load_dict, _load_json, _load_yaml] _config = None for path in plugin_path: done = False for parser in dict_parsers: _config = parser("%s/%s" % (path, module_file_name)) if _config and "plugin" in _config: if _config["plugin"] == filter_class: done = True break else: _config = None if done: break if _config is not None: try: if "plugin" in _config and "MicroService" in _config["plugin"]: # Load micro service if all(k in _config for k in ("plugin", "module")): module_class = locate(_config["module"]) instance = None if "config" in _config: instance = module_class(internal_attributes, _config["config"]) else: instance = module_class(internal_attributes) loaded_plugins.append(instance) else: LOGGER.warn("Missing mandatory configuration parameters in " "the micro service plugin %s ('plugin', 'module')." % module_file_name) else: if all(k in _config for k in ("name", "plugin", "module", "config")): plugin_class = getattr(sys.modules[__name__], _config["plugin"]) module_class = locate(_config["module"]) if not module_class: raise ValueError("Can't find module '%s'" % _config["module"]) name = _config["name"] config = json.dumps(_config["config"]) replace = [ ("<base_url>", base_url), ("<name>", _config["name"]) ] for _replace in replace: config = config.replace(_replace[0], _replace[1]) config = json.loads(config) module = plugin_class(module_class, name, config) loaded_plugins.append(module) loaded_plugin_names.append(module_file_name) else: LOGGER.warn("Missing mandatory configuration parameters in " "the plugin %s (plugin, module, receiver and/or config)." % module_file_name) except Exception as e: LOGGER.exception("Cannot create the module %s." % module_file_name) except Exception as error: LOGGER.exception("The configuration file %s is corrupt." % module_file_name) raise SATOSAConfigurationError( "The configuration file %s is corrupt." % module_file_name) from error LOGGER.debug("Loaded plugins: {}".format(loaded_plugin_names)) return loaded_plugins
def main(settings_file='~/.inprocess.json', opt_location=False): # Redefine Parser class MyParser(optparse.OptionParser): def format_epilog(self, formatter): return self.epilog # Parse Command Line options parser = MyParser(epilog=( '\n(c)2013 Adam Jackman ([email protected])\n') ) parser.add_option("-s", "--settings", dest="settings_file", help="set settings file", metavar="FILE") parser.add_option('-l', '--location', action="store_true", default=False, help="Print storage locations") options, arguments = parser.parse_args() # Set Variables if options.settings_file is not None: settings_file = options.settings_file with open(expanduser(settings_file), 'rb') as f: settings = json.loads(f.read()) Parseable.settings = settings # Pass along settings to the Parseable Class if options.location or opt_location: print('Storage Locations:\n' 'Settings: %s\n' 'Inbox: %s\n' 'inx files: %s\n' 'inx storage: %s') % (settings_file, settings['inbox_file'], settings['inbox_dir'], settings['storage_dir']) sys.exit(0) # Import all Parseable classes from parseables folder plugin_base = PluginBase(package='parseables') parsables_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'parseables/'); plugin_source = plugin_base.make_plugin_source(searchpath=[parsables_dir]) for plugin_name in plugin_source.list_plugins(): plugin = plugin_source.load_plugin(plugin_name) # List parseable things parseables = Parseable.__subclasses__() # list all direct subclasses of Parseable # Grab the list of inx files from the inbox directory, plus the inbox file files = os.listdir(settings['inbox_dir']) fp = re.compile( r"inx [0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}-[0-9]{2}-[0-9]{2}") files = filter(lambda file: fp.match(file), files) old_files = [settings['inbox_dir'] + file for file in files] new_files = [settings['storage_dir'] + file for file in files] now = get_now() if os.path.exists(settings['inbox_file']): inbox_store = settings['storage_dir'] + "inbox " + now.strftime('%Y-%m-%dT%H-%M-%S') + ".md" old_files = [settings['inbox_file']] + old_files new_files = [inbox_store] + new_files # Setup output inbox_header = ("# Inbox\n`inbox.md` created " + now.strftime('%B %d, %Y %H:%M:%S') + "\n\n*" + " *"*29 + "\n\n") inbox_contents = '' # Loop through the list of files for f_index, file in enumerate(old_files): with open(file, 'rb') as f: line = f.readline() while line != '': for ident in parseables: if ident.identify(line): if ident.multiline: lines = [] record = True while ident.identify_end(line) is None: lines = lines + [line] line = f.readline() if line == '': inbox_contents = inbox_contents + ''.join(lines) + '\n' break if record: try: ident(lines).record() except: inbox_contents = inbox_contents + ''.join(lines) + '\n' else: try: ident(line).record() except: inbox_contents = inbox_contents + line break else: # Runs if we don't know how to parse the current line inbox_contents = inbox_contents + line line = f.readline() # After File has been processed: # Add blank line to remaining contents inbox_contents = inbox_contents + '\n\n' # Move the file to storage shutil.move(file, new_files[f_index]) # Log inProcess run try: with open(settings['data_dir'] + 'log_inProcess.csv', 'ab') as csvfile: spamwriter = csv.writer(csvfile, quoting=csv.QUOTE_MINIMAL) spamwriter.writerow([now]) except IOError: raise RecordError('Problem writing to inProcess log') # Write inbox contents to file inbox_contents = re.sub(r'\n\s+\n', '\n\n', inbox_contents) # Change inbox if re.sub('\n', '', inbox_contents) != '': inbox_contents = inbox_header + inbox_contents inbox_contents = re.sub(r"\s*\n\s*\n\s*\n+", r"\n\n", inbox_contents) with open(settings['inbox_file'], 'wb') as f: f.write(inbox_contents)