def _run_reporting(self, results, objfile):
     #options
     options = dict()
     
     # Build the PluginManager
     reportingPluginManager = PluginManager()
     reportingPluginManager.setPluginPlaces(["reporting"])
     reportingPluginManager.collectPlugins()
     
     # Trigger run from the "Reporting" plugins
     for pluginInfo in reportingPluginManager.getAllPlugins():
         reportingModul = pluginInfo.plugin_object
         reportingModul.set_task(self.task)
         
         # Give it the the relevant reporting.conf section.
         try:
             options = self.cfgReporting.get(pluginInfo.name)
             reportingModul.set_options(options)
         except Exception:
             log.error("Reporting module %s not found in configuration file", pluginInfo.name)  
             
         # If the processing module is disabled in the config, skip it.
         if not options.enabled:
             continue
         
         log.debug("Run Reporting: " + pluginInfo.name)
         
         try:
             # Run the Reporting module
             reportingModul.run(results, objfile)
         except Exception as e:
             log.exception("Failed to run the reporting module \"%s\":",
                           reportingModul.__class__.__name__)
Esempio n. 2
0
def main():
    parser = argparse.ArgumentParser(description='Validates file format')
    parser.add_argument('files', nargs='+',
                        help='files to be validated')
    parser.add_argument('--verbose', action='store_true',
                        default=False,
                        help='Shows help about validation')

    args = parser.parse_args()

    simplePluginManager = PluginManager()
    simplePluginManager.setPluginPlaces(["plugins"])
    simplePluginManager.collectPlugins()

    for filename in args.files:
        supported = False
        for plugin in simplePluginManager.getAllPlugins():
            methods = plugin.plugin_object
            if methods.should_manage(filename):
                supported = True
                try:
                    plugin.plugin_object.validate(filename)
                    print('%s sintax ok for %s' % (filename, plugin.name))
                    break
                except Exception as e:
                    print('Invalid file %s for %s' % (filename, plugin.name))
                    if args.verbose:
                        print(e)
        if not supported:
            print('%s cannot be validated' % filename)
def run_output_plugins(**kwargs):
  logger = logging.getLogger(__name__)
  logger.info("Begin run_output_plugins")

  simplePluginManager = PluginManager()
  logging.getLogger('yapsy').setLevel(logging.DEBUG)
  simplePluginManager.setCategoriesFilter({
     "OutputResults": output_plugin
     })

  # Tell it the default place(s) where to find plugins
  if logger:
    logger.debug("Plugin directories: %s" % (kwargs['output_plugin_directories']))
  simplePluginManager.setPluginPlaces(kwargs['output_plugin_directories'])

  simplePluginManager.collectPlugins()

  plugin_cnt = 0
  plugin_start_time = time.time()
  for plugin in simplePluginManager.getAllPlugins():
    if logger:
      logger.info("Starting plugin: %s" % (plugin.name))
    if plugin.plugin_object.initialize_plugin(details=plugin.details):
      plugin.plugin_object.emit(prediction_date=kwargs['prediction_date'].astimezone(timezone("US/Eastern")).strftime("%Y-%m-%d %H:%M:%S"),
                                execution_date=kwargs['prediction_run_date'].strftime("%Y-%m-%d %H:%M:%S"),
                                ensemble_tests=kwargs['site_model_ensemble'])
      plugin_cnt += 1
    else:
      logger.error("Failed to initialize plugin: %s" % (plugin.name))
  logger.debug("%d output plugins run in %f seconds" % (plugin_cnt, time.time() - plugin_start_time))
  logger.info("Finished run_output_plugins")
Esempio n. 4
0
 def __run_reporting_generator(self):
             
     # options
     options = dict()
     
     # Build the PluginManager
     reportingPluginManager = PluginManager()
     reportingPluginManager.setPluginPlaces(["reporting"])
     reportingPluginManager.collectPlugins()
     
     # Trigger run from the "Reporting" plugins
     for pluginInfo in sorted(reportingPluginManager.getAllPlugins(), key=lambda PluginInfo: PluginInfo.name):
         reportingModulG = pluginInfo.plugin_object
         reportingModulG.set_task(self.task)
         
         # Give it the the relevant reporting.conf section.
         try:
             options = self.cfgReporting.get(pluginInfo.name)
             reportingModulG.set_options(options)
         except Exception:
             log.error("Reporting module %s not found in configuration file", pluginInfo.name)  
             
         # If the processing module is disabled in the config, skip it.
         if not options.enabled:
             continue
         
         log.debug("Run Reporting: " + pluginInfo.name)
         
         yield reportingModulG
Esempio n. 5
0
def run():
    logging.basicConfig(level=logging.INFO)

    os.chdir('/home/mjolnir/git/PURIKURA')

    # H A N D L E  P L U G I N S
    pm = PluginManager()
    pm.setPluginPlaces(['./pyrikura/plugins'])
    pm.collectPlugins()

    for pi in pm.getAllPlugins():
        logging.info('loading plugin %s', pi.name)
        pm.activatePluginByName(pi.name)

    brokers = {}
    nodes = build()
    head = nodes[0]

    for node in nodes:
        brokers[node] = node.load(pm)

    for node, broker in brokers.items():
        for other in node._listening:
            broker.subscribe(brokers[other])

    start = time.time()
    last_time = 0
    shots = 0
    last_trigger = 0
    for broker in itertools.cycle(brokers.values()):
        broker.update()
Esempio n. 6
0
def getBankRates():
    # Load the plugins from the plugin directory.
	manager = PluginManager()
	# Server
	# manager.setPluginPlaces(["./dev/liborWatch/server/plugins"])
	# Dev
	# manager.setPluginPlaces(["./plugins"])
	# Local
	manager.setPluginPlaces(["./dev/NextLevelApps/liborWatch/server/plugins"])

	manager.collectPlugins()
	today = datetime.date.today().strftime('%Y-%m-%d')

    # Loop round the plugins and get the bank rates
	for plugin in manager.getAllPlugins():
		rates = plugin.plugin_object.getRates()
		print(rates);
		if(len(rates) != 10):
			print('Error: We did not get 10 rates from the plugin ' + plugin.name + ' - ' + str(len(rates)))
			return

		newRate = []
		iCnt = 0;
		for rate in rates:
			iCnt = iCnt + 1
			newRate.append((plugin.name, today, iCnt, rate))
#			print('execute insert statement ' + plugin.name, str(today), str(iCnt), str(rate))

		con = sqlite3.connect('liborWatch.sqlite')
		with con:
			cur = con.cursor()
			cur.execute("CREATE TABLE IF NOT EXISTS BankRate(id INTEGER PRIMARY KEY, bankName TEXT, date TEXT, fixedForYears INTEGER, rate REAL)")
			cur.executemany("INSERT INTO BankRate VALUES(NULL, ?, ?, ?, ?)", newRate)
Esempio n. 7
0
class ProfilesManager(object):

    def __init__(self):
        self.plugin_location = [PROFILE_MODULE_DIR]
        self.pluginManager = PluginManager(plugin_info_ext="plugin")

        self.pluginManager.setPluginPlaces(self.plugin_location)
        self.pluginManager.collectPlugins()

    def modules_info(self):
        """
        Get information with regards to each modules loaded. It includes author, category, copyright, description,
        details, name, version and website.
        :return: information of all modules loaded
        """
        modules_info = {}
        for pluginInfo in self.pluginManager.getAllPlugins():
            modules_info[pluginInfo.name] = pluginInfo

        return modules_info

    def configForms(self, device_serial, module_name=""):
        """
        Get the configuration views of each modules to be displayed on web interface
        :return: dictionary of pluginInfo as key and form as value
        """
        if module_name:
            plugin = self.pluginManager.getPluginByName(name=module_name)
            configForms = plugin.plugin_object.get_view()
        else:
            configForms = {}
            for pluginInfo in self.pluginManager.getAllPlugins():
                form = pluginInfo.plugin_object.get_view()
                configForms[pluginInfo] = form

        return configForms

    def run_simulation(self,option, profile_name, duration, device_serial, package_name, session):
        """
        Run profile simulation script
        :return:
        """
        plugin = self.pluginManager.getPluginByName(name=profile_name)
        if option == RANDOM_INTERACTION:
            plugin.plugin_object.runSimulation(duration,package_name, random=True, device_serial=device_serial, session=session)
        elif option == SCRIPTED_PROFILE_INTERACTION:
            plugin.plugin_object.runSimulation(duration,package_name, random=False, device_serial=device_serial, session=session)



    def setup_device(self,module, params, device_serial):
        """
        install profile apk and profile app data onto device
        :return:
        """
        pluginInfo = self.pluginManager.getPluginByName(name=module)
        if pluginInfo.name == module:
            pluginInfo.plugin_object.prepare(params, device_serial)

        return True
Esempio n. 8
0
def loadPlugins(pluginfldr,hivesdict):
    """
    Enumerate plugins in the specified directory and return the populated
    plugin manager and a list of the compatible plugins. Compatibility is
    determined by checking if the required hives were loaded sucessfully.
    """
    pluginmanager = PluginManager()
    pluginmanager.setPluginPlaces([pluginfldr])
    pluginmanager.collectPlugins()

    print ""
    logging.info("[PLUGINS IDENTIFIED: %s]" % len(pluginmanager.getAllPlugins()))

    compat_plugins = list()
    incompat_plugins = list()
    for plugin in pluginmanager.getAllPlugins():
        compat = 1
        for req in plugin.plugin_object.getRequirements():
            if (hivesdict[req][0] <> 1):
                compat = 0
                break
        if compat:
            compat_plugins.append(plugin.name)
        else:
            incompat_plugins.append(plugin.name)

    logging.info(" [%s] Compatible Plugins:" % len(compat_plugins))
    for plugin in compat_plugins:
        logging.info("  - %s" % plugin)
    logging.info(" [%s] Incompatible Plugins:" % len(incompat_plugins))
    for plugin in incompat_plugins:
        logging.info("  - %s" % plugin)

    return pluginmanager, compat_plugins
Esempio n. 9
0
class FakeSite(object):
    def __init__(self):
        self.template_system = self
        self.config = {"DISABLED_PLUGINS": [], "EXTRA_PLUGINS": [], "DEFAULT_LANG": "en"}
        self.EXTRA_PLUGINS = self.config["EXTRA_PLUGINS"]
        self.plugin_manager = PluginManager(
            categories_filter={
                "Command": Command,
                "Task": Task,
                "LateTask": LateTask,
                "TemplateSystem": TemplateSystem,
                "PageCompiler": PageCompiler,
                "TaskMultiplier": TaskMultiplier,
                "RestExtension": RestExtension,
            }
        )
        self.loghandlers = [STDERR_HANDLER]
        self.plugin_manager.setPluginInfoExtension("plugin")
        if sys.version_info[0] == 3:
            places = [os.path.join(os.path.dirname(utils.__file__), "plugins")]
        else:
            places = [os.path.join(os.path.dirname(utils.__file__), utils.sys_encode("plugins"))]
        self.plugin_manager.setPluginPlaces(places)
        self.plugin_manager.collectPlugins()

        self.timeline = [FakePost(title="Fake post", slug="fake-post")]

    def render_template(self, name, _, context):
        return '<img src="IMG.jpg">'
Esempio n. 10
0
def get_plugins():
 
    plugin_analyzer = PluginFileAnalyzerWithInfoFile(name="torrentstausanalyzer", extensions="plugin-manifest")
    plugin_locator = PluginFileLocator(analyzers=[plugin_analyzer])

    extra_plugins_dir = config.getSettingsAsDict()["extra_plugins_dir"]
    plugin_extras = os.path.join(get_config_dir(), extra_plugins_dir)

    directories = [os.path.join(os.path.dirname(os.path.realpath(__file__)), "plugins")]

    ##
    ## Allow user defined plugins
    ## These plugins should be named as
    ## name.function.{py, plugin-manifest}
    ## Example:
    ## MyPlugin.onstart.py
    ## MyPlguin.onstart.plugin-manifest
    ##
    if os.path.exists(plugin_extras):
        directories.append(plugin_extras)

    manager = PluginManager(directories_list=directories, plugin_locator=plugin_locator)
    manager.collectPlugins()
    plugins = manager.getAllPlugins()

    # Activate all loaded plugins
    for pluginInfo in plugins:
        manager.activatePluginByName(pluginInfo.name)
    return plugins
Esempio n. 11
0
 def load_plugins(cls):
     manager = PluginManager()
     manager.setPluginPlaces([os.path.join(os.getcwd(), "plugins/")])
     manager.collectPlugins()
     ret = manager.getAllPlugins()
     logger.info('Loaded {} plugins'.format(len(ret)))
     return ret
Esempio n. 12
0
class FakeSite(object):
    def __init__(self):
        self.template_system = self
        self.config = {
            'DISABLED_PLUGINS': [],
            'EXTRA_PLUGINS': [],
        }
        self.EXTRA_PLUGINS = self.config['EXTRA_PLUGINS']
        self.plugin_manager = PluginManager(categories_filter={
            "Command": Command,
            "Task": Task,
            "LateTask": LateTask,
            "TemplateSystem": TemplateSystem,
            "PageCompiler": PageCompiler,
            "TaskMultiplier": TaskMultiplier,
            "RestExtension": RestExtension,
        })
        self.plugin_manager.setPluginInfoExtension('plugin')
        if sys.version_info[0] == 3:
            places = [
                os.path.join(os.path.dirname(utils.__file__), 'plugins'),
            ]
        else:
            places = [
                os.path.join(os.path.dirname(utils.__file__), utils.sys_encode('plugins')),
            ]
        self.plugin_manager.setPluginPlaces(places)
        self.plugin_manager.collectPlugins()

    def render_template(self, name, _, context):
        return('<img src="IMG.jpg">')
Esempio n. 13
0
class FurnivallApplication(tornado.web.Application):
	def __init__(self):
		"""
		Sets up the Tornado web server and loads all the init data
		"""

		# Init mongodb database
		self.dbconnection = Connection()
		self.db = self.dbconnection['furnivall']

		# Init plugins
		self.plugin_manager = PluginManager()
		self.plugin_manager.setPluginPlaces(["./plugins"])
		self.plugin_manager.collectPlugins()
		print "Loaded plugins:"
		for plugin_info in self.plugin_manager.getAllPlugins():
			print ' * ' + plugin_info.name

		# Init routes
		urls = [
		] + Route.routes()

		settings = dict(
			static_path = os.path.join(data_dir, "static"),
			template_path = os.path.join(data_dir, "templates"),
			xsrf_cookies = False,
			cookie_secret = "11oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1ao/Vo=",
		)
		tornado.web.Application.__init__(self, urls, **settings)
Esempio n. 14
0
class AlgorithmManager():
    def __init__(self):
        self._pluginManager = PluginManager()
        self._pluginManager.setPluginPlaces(config.PLUGIN_DIR)
        self._pluginManager.collectPlugins()
        for pluginInfo in self._pluginManager.getAllPlugins():
            self._pluginManager.activatePluginByName(pluginInfo.name)
            
    def get_alg_names(self):
        for plugin in self._pluginManager.getAllPlugins():
            plugin.plugin_object.print_name()
            
    def execute_calc(self, data):
        run = []
        if not self.__is_sequence(data):
            raise Exception('Data is no array!')
        for alg in self._pluginManager.getAllPlugins():
            result, prop = alg.plugin_object.calc(data)
            run.append({alg.name : (result, prop)})
        return run

    
    def __is_sequence(self, arg):
        return (not hasattr(arg, "strip") and
            hasattr(arg, "__getitem__") or
            hasattr(arg, "__iter__"))
                 
    
        
Esempio n. 15
0
def loadPlugins(root_folder, plugin_name, categories_filter):
  from yapsy.PluginManager import PluginManager

  plugin_dirs = []
  plugin_dirs.append(configuration.fabfile_basedir + '/.fabalicious/plugins')
  plugin_dirs.append(expanduser("~") + '/.fabalicious/plugins')
  plugin_dirs.append(root_folder + '/plugins')

  log.debug("Looking for %s-plugins in %s" % (plugin_name, ", ".join(plugin_dirs)))

  manager = PluginManager()
  manager.setPluginPlaces(plugin_dirs)
  manager.setCategoriesFilter(categories_filter)
  manager.collectPlugins()

  # Activate all loaded plugins
  for pluginInfo in manager.getAllPlugins():
    manager.activatePluginByName(pluginInfo.name)

  result = {}
  for plugin in manager.getAllPlugins():

    if hasattr(plugin.plugin_object, 'aliases') and isinstance(plugin.plugin_object.aliases, list):
      for alias in plugin.plugin_object.aliases:
        result[alias] = plugin.plugin_object
    elif hasattr(plugin.plugin_object, 'alias'):
      result[plugin.plugin_object.alias] = plugin.plugin_object
    else:
      result[plugin.name] = plugin.plugin_object
  return result
Esempio n. 16
0
    def pane_data(self):
        list = []  # Holds the filter tuples (name, activated=True)

        # Get the default plugin directory, using XML
        path = os.path.expanduser("~")
        xml = xml_controller.Controller(path + "\.cxvrc.xml")
        xml.load_file()

        if os.path.exists(os.path.expanduser("~") + os.sep + "plugins"):
            default_dir = os.path.expanduser("~") + os.sep + "plugins"
        else:
            default_dir = self.dicom_view.get_main_dir() + os.sep + "plugins"

        if xml.get_plugin_directory() == "" or xml.get_plugin_directory() is None:
            directory = [default_dir]
        else:
            directory = [default_dir, xml.get_plugin_directory()]

        # Load the plugins from the default plugin directory.
        manager = PluginManager()
        manager.setPluginPlaces(directory)
        manager.setPluginInfoExtension("plugin")
        manager.collectPlugins()

        # Append tuple with plugin name and enabled=True to the list
        for plugin in manager.getAllPlugins():
            list.append((plugin.name, True))

        return list
Esempio n. 17
0
def runCrawler():
	mapURL = {}
	cfgCrawler = Config(os.path.join(RAGPICKER_ROOT, 'config', 'crawler.conf'))	
	
	# Build the PluginManager
	crawlerPluginManager = PluginManager()
	crawlerPluginManager.setPluginPlaces(["crawler"])
	crawlerPluginManager.collectPlugins()
	
	# Trigger run from the "Crawler" plugins
	for pluginInfo in sorted(crawlerPluginManager.getAllPlugins(), key=lambda PluginInfo: PluginInfo.name):
		crawlerModul = pluginInfo.plugin_object
		
		# Config for crawler module
		try:
			options = cfgCrawler.get(pluginInfo.name)
			crawlerModul.set_options(options)
		except Exception:
			log.error("Crawler module %s not found in configuration file", pluginInfo.name)  
			
		# If the crawler module is disabled in the config, skip it.
		if not options.enabled:
			continue
		
		try:
			log.debug("Run Crawler: " + pluginInfo.name)
			returnMap = crawlerModul.run()
			mapURL.update(returnMap)
		except Exception as e:
			log.error('Error (%s) in %s', e, pluginInfo.name)
	
	return mapURL
Esempio n. 18
0
def group_dashboard(request, group_id):
    # check user is allowed to access this
    user = request.user
    config_installed = 'config' in settings.INSTALLED_APPS
    user_level = user.userprofile.level
    machine_group = get_object_or_404(MachineGroup, pk=group_id)
    business_unit = machine_group.business_unit
    if business_unit not in user.businessunit_set.all():
        if user_level != 'GA':
            return redirect(index)
    if user_level == 'GA' or user_level == 'RW':
        is_editor = True
    else:
        is_editor = False
    machines = machine_group.machine_set.all()
    # Build the manager
    manager = PluginManager()
    # Tell it the default place(s) where to find plugins
    manager.setPluginPlaces([settings.PLUGIN_DIR, os.path.join(settings.PROJECT_DIR, 'server/plugins')])
    # Load all plugins
    manager.collectPlugins()
    output = []
    for plugin in manager.getAllPlugins():
        data = {}
        data['name'] = plugin.name
        (data['html'], data['width']) = plugin.plugin_object.show_widget('group_dashboard', machines, machine_group.id)
        output.append(data)
    output = utils.orderPluginOutput(output, 'group_dashboard', machine_group.id)
    c = {'user': request.user, 'machine_group': machine_group, 'user_level': user_level,  'is_editor': is_editor, 'business_unit': business_unit, 'output':output, 'config_installed':config_installed, 'request':request}
    return render_to_response('server/group_dashboard.html', c, context_instance=RequestContext(request))
Esempio n. 19
0
def main():
    # Read configuration
    config = SafeConfigParser(
        defaults = {'port':'15915',
                    'plugins_directory':'./plugins',
                    'plugins_enabled':'',
                   })
    config.read(['./conf/cm15d.conf',
                 '/etc/cm15d.conf',
                 '/etc/cm15d/cm15d.conf',
                 '/etc/cm15d/conf.d/local.conf',
                ])

    # Activate enabled plugins
    plugins = PluginManager()
    plugins.setPluginPlaces(config.get('cm15d', 'plugins_directory').split(','))
    plugins.collectPlugins()
    plugins_enabled = config.get('cm15d', 'plugins_enabled').split(',')

    for plugin in plugins.getAllPlugins():
        if plugin.name in plugins_enabled:
            plugins.activatePluginByName(plugin.name)
            print("Plugin %s enabled" % plugin.name)

    # Start server
    port = int(config.get('cm15d', 'port'))
    endpoint = TCP4ServerEndpoint(reactor, port)
    endpoint.listen(CM15DaemonFactory(plugins))
    print("Server listening on port %s" % port)
    reactor.run()
  def collect_data(self, **kwargs):
    self.logger.info("Begin collect_data")

    simplePluginManager = PluginManager()
    logging.getLogger('yapsy').setLevel(logging.DEBUG)
    simplePluginManager.setCategoriesFilter({
       "DataCollector": data_collector_plugin
       })

    # Tell it the default place(s) where to find plugins
    self.logger.debug("Plugin directories: %s" % (kwargs['data_collector_plugin_directories']))
    simplePluginManager.setPluginPlaces(kwargs['data_collector_plugin_directories'])

    simplePluginManager.collectPlugins()

    plugin_cnt = 0
    plugin_start_time = time.time()
    for plugin in simplePluginManager.getAllPlugins():
      self.logger.info("Starting plugin: %s" % (plugin.name))
      if plugin.plugin_object.initialize_plugin(details=plugin.details):
        plugin.plugin_object.start()
      else:
        self.logger.error("Failed to initialize plugin: %s" % (plugin.name))
      plugin_cnt += 1

    #Wait for the plugings to finish up.
    self.logger.info("Waiting for %d plugins to complete." % (plugin_cnt))
    for plugin in simplePluginManager.getAllPlugins():
      plugin.plugin_object.join()
    self.logger.info("%d Plugins completed in %f seconds" % (plugin_cnt, time.time() - plugin_start_time))
Esempio n. 21
0
 def init_manager():
     anl = PluginFileAnalyzerMathingRegex('custom_res_handler_plugins', r'^[A-Za-z0-9]+\.py$')
     res = PluginFileLocator(plugin_info_cls=CFCustomResourceHandler)
     res.setAnalyzers([anl])
     manager = PluginManager(plugin_locator=res, categories_filter={'CFHandlers' : CFCustomResourceHandler})
     manager.setPluginPlaces([dirname(__file__) + '/plugins'])
     manager.collectPlugins()
     return manager
Esempio n. 22
0
class BotInteraction():

    def __init__(self, config):
        self.channel = config['channel']
        self.nickname = config['nickname']
        self.prompt = config['prompt']
        self.parts = ""
        self.ping = ""
        self.username = ""
        self.message = ""
        self.manager = PluginManager()
        self.manager.setPluginPlaces(["plugins"])
        self.manager.collectPlugins()

    def handle_line(self, username, message, parts):
        print(username + ": " + message)

        if self.nickname not in parts[1] and message[0:1] == self.prompt:

            message = message.replace(">", " ").split(None, 1)
            for plugin in self.manager.getAllPlugins():  # Collect all plugins
                try:
                    # Message[0] - search plugin_name
                    plugin_yapsy = self.manager.getPluginByName(message[0])
                    command = []

                    # If the message has arguments - message[1] add to command
                    if len(message) == 2:
                        command = message[1]

                    # To found plugin send arguments.
                    return plugin_yapsy.plugin_object.execute(self.channel,
                                                              username,
                                                              command)
                except:
                    continue

    def check_ping(self, line):
        if line.find("PING") != -1:  # If server pings then pong
            line = string.split(line, " ")
            self.ping = "PONG " + line[1]

        else:
            self.ping = ""
            self.parts = string.split(line, ":")

            if "QUIT" not in self.parts[1] and \
               "JOIN" not in self.parts[1] and \
               "PART" not in self.parts[1]:

                try:
                    # Sets the message variable to the actual message sent
                    self.message = self.parts[2][:len(self.parts[2]) - 1]
                except:
                    self.message = ""
                # Sets the username variable to the actual username
                usernamesplit = string.split(self.parts[1], "!")
                self.username = usernamesplit[0]
Esempio n. 23
0
def main():   
    # Load the plugins from the plugin directory.
    manager = PluginManager(plugin_info_ext='cfg')
    manager.setPluginPlaces(["../plugins"])
    manager.collectPlugins()

    # Loop round the plugins and print their names.
    for plugin in manager.getAllPlugins():
        plugin.plugin_object.print_name()
Esempio n. 24
0
class Plugins():

    '''
    Plugins
    '''

    def __init__(self):
        '''
        Constructor
        '''

        super(Plugins, self).__init__()

        self.write_tab_dock_plugin_dict = {}
        self.write_panel_dock_plugin_dict = {}

        # Build the manager
        self._plugin_manager = PluginManager()
        # List all sub-directories of "plugins"
        plugin_path = os.path.sep.join([os.getcwd(), "plugins"])
        plugin_places = [plugin_path]
        for dirname, dirnames, filenames in os.walk(plugin_path):
            # print path to all subdirectories first.
            for subdirname in dirnames:
                plugin_places.append(os.path.join(dirname, subdirname))
        # Tell it the default place(s) where to find plugins
        self._plugin_manager.setPluginPlaces(plugin_places)
        sys.path.append(plugin_path)

        # Define the various categories corresponding to the different
        # kinds of plugins you have defined
        self._plugin_manager.setCategoriesFilter({
                                                 "GuiWriteTabDockPlugin": GuiWriteTabDockPlugin,
                                                 "GuiWritePanelDockPlugin": GuiWritePanelDockPlugin
                                                 })

        self._plugin_manager.collectPlugins()

        self.load_plugins(
            ["GuiWriteTabDockPlugin",  "GuiWritePanelDockPlugin"])

    def load_plugins(self, categories):
        '''
        function:: load_plugins(categories)
        :param categories: list
        '''

        for category in categories:
            for pluginInfo in self._plugin_manager.getPluginsOfCategory(category):
                setattr(self, pluginInfo.plugin_object.gui_class(
                ).__name__, pluginInfo.plugin_object.gui_class())
                if category is "GuiWriteTabDockPlugin":
                    self.write_tab_dock_plugin_dict[pluginInfo.plugin_object.gui_class().dock_name] \
                        = pluginInfo.plugin_object.gui_class()
                if category is "GuiWritePanelDockPlugin":
                    self.write_panel_dock_plugin_dict[pluginInfo.plugin_object.gui_class().dock_name] \
                        = pluginInfo.plugin_object.gui_class()
Esempio n. 25
0
def main():
    # Create plugin manager
    manager = PluginManager()
    manager.setPluginPlaces([PluginFolder])
    # Collect plugins
    manager.collectPlugins()

    for plugin in manager.getAllPlugins():
        plugin.plugin_object.say_hello()
Esempio n. 26
0
def index(request):
    # Get the current user's Business Units
    user = request.user
    # Count the number of users. If there is only one, they need to be made a GA
    if User.objects.count() == 1:
        # The first user created by syncdb won't have a profile. If there isn't one, make sure they get one.
        try:
            profile = UserProfile.objects.get(user=user)
        except UserProfile.DoesNotExist:
            profile = UserProfile(user=user)

        profile.level = "GA"
        profile.save()
    user_level = user.userprofile.level
    now = datetime.now()
    hour_ago = now - timedelta(hours=1)
    today = date.today()
    week_ago = today - timedelta(days=7)
    month_ago = today - timedelta(days=30)
    three_months_ago = today - timedelta(days=90)
    if user_level != "GA":
        # user has many BU's display them all in a friendly manner
        business_units = user.businessunit_set.all()
        if user.businessunit_set.count() == 1:
            # user only has one BU, redirect to it
            for bu in user.businessunit_set.all():
                return redirect("server.views.bu_dashboard", bu_id=bu.id)
                break
    else:
        machines = Machine.objects.all()
        # Build the manager
        manager = PluginManager()
        # Tell it the default place(s) where to find plugins
        manager.setPluginPlaces([settings.PLUGIN_DIR, os.path.join(settings.PROJECT_DIR, "server/plugins")])
        # Load all plugins
        manager.collectPlugins()
        output = []
        # Loop round the plugins and print their names.
        for plugin in manager.getAllPlugins():
            data = {}
            data["name"] = plugin.name
            (data["html"], data["width"]) = plugin.plugin_object.show_widget("front", machines)
            # output.append(plugin.plugin_object.show_widget('front'))
            output.append(data)
        output = utils.orderPluginOutput(output)

        # get the user level - if they're a global admin, show all of the machines. If not, show only the machines they have access to
        business_units = BusinessUnit.objects.all()
        config_installed = "config" in settings.INSTALLED_APPS

        c = {
            "user": request.user,
            "business_units": business_units,
            "output": output,
            "config_installed": config_installed,
        }
        return render_to_response("server/index.html", c, context_instance=RequestContext(request))
Esempio n. 27
0
class PluginHandler:
    def __init__(self):
        self._plugin_manager = PluginManager()
        self._category_active = {"Modifier": False, "Analyzer": False, "Comparator": False}
        self._plugin_from_category = {"Modifier": [], "Analyzer": [], "Comparator": []}
        self._modifier_plugins = []
        self._analyzer_plugins = []
        self._collect_all_plugins()

    def _collect_all_plugins(self):
        self._plugin_manager.setPluginPlaces(
            ["hugin/analyze/modifier", "hugin/analyze/analyzer", "hugin/analyze/comparator"]
        )

        # setting filter categories for pluginmanager
        self._plugin_manager.setCategoriesFilter(
            {
                # movie metadata provider
                "Modifier": IModifier,
                # movie metadata provider
                "Comparator": IComparator,
                # sub metadata provider
                "Analyzer": IAnalyzer,
            }
        )
        self._plugin_manager.collectPlugins()

    def activate_plugins_by_category(self, category):
        self._toggle_activate_plugins_by_category(category)

    def deactivate_plugins_by_category(self, category):
        self._toggle_activate_plugins_by_category(category)

    def _toggle_activate_plugins_by_category(self, category):
        plugins = self._plugin_manager.getPluginsOfCategory(category)
        is_active = self._category_active[category]
        for pluginInfo in plugins:
            if is_active:
                self._plugin_manager.deactivatePluginByName(name=pluginInfo.name, category=category)
                self._plugin_from_category[category].remove(pluginInfo)
            else:
                self._plugin_manager.activatePluginByName(name=pluginInfo.name, category=category)
                self._plugin_from_category[category].append(pluginInfo)
        self._category_active[category] = not is_active

    def get_plugins_from_category(self, category):
        plugins = []
        for plugin in self._plugin_from_category[category]:
            plugin.plugin_object.name = plugin.name
            plugin.plugin_object.description = plugin.description
            plugins.append(plugin.plugin_object)
        return plugins

    def is_activated(self, category):
        """ True if category is activated. """
        return self._category_active[category]
def plugins():   
    # Load the plugins from the plugin directory.
    manager = PluginManager()
    manager.setPluginPlaces(["plugins"])
    manager.collectPlugins()

    # Loop round the plugins and print their names.
    for p in manager.getAllPlugins():
        p.plugin_object.print_name()
        p.plugin_object.activate()
Esempio n. 29
0
def main():   
    # Load the plugins from the plugin directory.
    manager = PluginManager()
    manager.setPluginPlaces(["orthos/plugins"])
    manager.collectPlugins()

    # Loop round the plugins and print their names.
    for plugin in manager.getAllPlugins():
        print "Fo"
        plugin.plugin_object.print_name()
Esempio n. 30
0
def main():
    """docstring for main"""
    # Load the plugins from the plugin directory.
    manager = PluginManager()
    manager.setPluginPlaces(["plugins"])
    manager.collectPlugins()

    # Loop round the plugins executing them.
    for plugin in manager.getAllPlugins():
        plugin.plugin_object.run()
Esempio n. 31
0
    def initialize_plugins(self):
        self.__log.info("Collecting and loading plugins")

        try:
            plugin_manager = PluginManager()
            # TODO: change plugin descriptor extensions, plugin_manager.setPluginInfoExtension(AGENT_PLUGIN_EXT)
            plugin_manager.setCategoriesFilter({
                CARTRIDGE_AGENT_PLUGIN:
                ICartridgeAgentPlugin,
                ARTIFACT_MGT_PLUGIN:
                IArtifactManagementPlugin
            })

            plugin_manager.setPluginPlaces(
                [self.__config.read_property(constants.PLUGINS_DIR)])

            plugin_manager.collectPlugins()

            # activate cartridge agent plugins
            plugins = plugin_manager.getPluginsOfCategory(
                CARTRIDGE_AGENT_PLUGIN)
            grouped_plugins = {}
            for plugin_info in plugins:
                self.__log.debug("Found plugin [%s] at [%s]" %
                                 (plugin_info.name, plugin_info.path))
                plugin_manager.activatePluginByName(plugin_info.name)
                self.__log.info("Activated plugin [%s]" % plugin_info.name)

                mapped_events = plugin_info.description.split(",")
                for mapped_event in mapped_events:
                    if mapped_event.strip() != "":
                        if grouped_plugins.get(mapped_event) is None:
                            grouped_plugins[mapped_event] = []

                        grouped_plugins[mapped_event].append(plugin_info)

            # activate artifact management plugins
            artifact_mgt_plugins = plugin_manager.getPluginsOfCategory(
                ARTIFACT_MGT_PLUGIN)
            for plugin_info in artifact_mgt_plugins:
                self.__log.debug(
                    "Found artifact management plugin [%s] at [%s]" %
                    (plugin_info.name, plugin_info.path))
                plugin_manager.activatePluginByName(plugin_info.name)
                self.__log.info("Activated artifact management plugin [%s]" %
                                plugin_info.name)

            return plugin_manager, grouped_plugins, artifact_mgt_plugins
        except ParameterNotFoundException as e:
            self.__log.exception(
                "Could not load plugins. Plugins directory not set: %s" % e)
            return None, None, None
        except Exception as e:
            self.__log.exception("Error while loading plugin: %s" % e)
            return None, None, None
Esempio n. 32
0
def bu_dashboard(request, bu_id):
    user = request.user
    user_level = user.userprofile.level
    business_unit = get_object_or_404(BusinessUnit, pk=bu_id)
    bu = business_unit
    config_installed = 'config' in settings.INSTALLED_APPS
    if business_unit not in user.businessunit_set.all() and user_level != 'GA':
        print 'not letting you in ' + user_level
        return redirect(index)
    # Get the groups within the Business Unit
    machine_groups = business_unit.machinegroup_set.all()
    if user_level == 'GA' or user_level == 'RW':
        is_editor = True
    else:
        is_editor = False
    machines = utils.getBUmachines(bu_id)
    now = datetime.now()
    hour_ago = now - timedelta(hours=1)
    today = date.today()
    week_ago = today - timedelta(days=7)
    month_ago = today - timedelta(days=30)
    three_months_ago = today - timedelta(days=90)

    # Build the manager
    manager = PluginManager()
    # Tell it the default place(s) where to find plugins
    manager.setPluginPlaces([
        settings.PLUGIN_DIR,
        os.path.join(settings.PROJECT_DIR, 'server/plugins')
    ])
    # Load all plugins
    manager.collectPlugins()
    output = []

    # Loop round the plugins and print their names.
    for plugin in manager.getAllPlugins():
        data = {}
        data['name'] = plugin.name
        (data['html'], data['width']) = plugin.plugin_object.show_widget(
            'bu_dashboard', machines, bu.id)
        output.append(data)
    output = utils.orderPluginOutput(output, 'bu_dashboard', bu.id)

    c = {
        'user': request.user,
        'machine_groups': machine_groups,
        'is_editor': is_editor,
        'business_unit': business_unit,
        'user_level': user_level,
        'output': output,
        'config_installed': config_installed
    }
    return render_to_response('server/bu_dashboard.html',
                              c,
                              context_instance=RequestContext(request))
Esempio n. 33
0
def machine_list(request, pluginName, data, page='front', theID=None):
    user = request.user
    title = None
    # Build the manager
    manager = PluginManager()
    # Tell it the default place(s) where to find plugins
    manager.setPluginPlaces([
        settings.PLUGIN_DIR,
        os.path.join(settings.PROJECT_DIR, 'server/plugins')
    ])
    # Load all plugins
    manager.collectPlugins()
    # get a list of machines (either from the BU or the group)
    if page == 'front':
        # get all machines
        machines = Machine.objects.all()

    if page == 'bu_dashboard':
        # only get machines for that BU
        # Need to make sure the user is allowed to see this
        business_unit = get_object_or_404(BusinessUnit, pk=theID)
        machine_groups = MachineGroup.objects.filter(
            business_unit=business_unit).prefetch_related('machine_set').all()

        if machine_groups.count() != 0:
            machines_unsorted = machine_groups[0].machine_set.all()
            for machine_group in machine_groups[1:]:
                machines_unsorted = machines_unsorted | machine_group.machine_set.all(
                )
        else:
            machines_unsorted = None
        machines = machines_unsorted

    if page == 'group_dashboard':
        # only get machines from that group
        machine_group = get_object_or_404(MachineGroup, pk=theID)
        # check that the user has access to this
        machines = Machine.objects.filter(machine_group=machine_group)
    # send the machines and the data to the plugin
    for plugin in manager.getAllPlugins():
        if plugin.name == pluginName:
            (machines,
             title) = plugin.plugin_object.filter_machines(machines, data)
    c = {
        'user': user,
        'machines': machines,
        'req_type': page,
        'title': title,
        'bu_id': theID,
        'request': request
    }

    return render_to_response('server/overview_list_all.html',
                              c,
                              context_instance=RequestContext(request))
Esempio n. 34
0
 def init_manager():
     anl = PluginFileAnalyzerMathingRegex('custom_res_handler_plugins',
                                          r'^[A-Za-z0-9]+\.py$')
     res = PluginFileLocator(plugin_info_cls=CFCustomResourceHandler)
     res.setAnalyzers([anl])
     manager = PluginManager(
         plugin_locator=res,
         categories_filter={'CFHandlers': CFCustomResourceHandler})
     manager.setPluginPlaces([dirname(__file__) + '/plugins'])
     manager.collectPlugins()
     return manager
Esempio n. 35
0
def main():
    global p
    #  Load the plugins from the plugin directory.
    manager = PluginManager()
    manager.setPluginPlaces(["plugins"])
    manager.collectPlugins()
    # Loop round the plugins and print their names.
    for plugin in manager.getAllPlugins():
        p = plugin.plugin_object.print_name()
        print("path is:", p)
        plugin.plugin_object.convert_from_xml(p)
def main():
    # Load the plugins from the plugin directory.
    manager = PluginManager()
    manager.setPluginPlaces(["storage_plugin/consul"])
    manager.collectPlugins()

    # Loop round the plugins and print their names.
    for plugin in manager.getAllPlugins():
        # plugin.plugin_object.put_record('ikepolicies',Dog('12345','hello'))
        plugin.plugin_object.get_record('ikepolicies', '12345')
        plugin.plugin_object.get_record('ikepolicies', 'hello', 'name')
Esempio n. 37
0
def get_plugins(category_filter={}, plugin_places=['plugins']):

    pm = PluginManager(plugin_info_ext='plugin')

    # Normalize the paths to the location of this file.
    # XXX-ricarkol: there has to be a better way to do this.
    plugin_places = [misc.execution_path(x) for x in plugin_places]

    pm.setPluginPlaces(plugin_places)
    pm.setCategoriesFilter(category_filter)
    pm.collectPlugins()
    return pm.getAllPlugins()
Esempio n. 38
0
class FakeSite(object):
    def __init__(self):
        self.template_system = self
        self.invariant = False
        self.config = {
            'DISABLED_PLUGINS': [],
            'EXTRA_PLUGINS': [],
            'EXTRA_PLUGINS_DIRS': [extra_v6_plugin_dir],
            'DEFAULT_LANG': 'en',
            'MARKDOWN_EXTENSIONS': ['fenced_code', 'codehilite'],
            'TRANSLATIONS_PATTERN': '{path}.{lang}.{ext}',
            'LISTINGS_FOLDERS': {},
        }
        self.EXTRA_PLUGINS = self.config['EXTRA_PLUGINS']
        self.plugin_manager = PluginManager(
            categories_filter={
                "Command": Command,
                "Task": Task,
                "LateTask": LateTask,
                "TemplateSystem": TemplateSystem,
                "PageCompiler": PageCompiler,
                "TaskMultiplier": TaskMultiplier,
                "RestExtension": RestExtension,
                "MarkdownExtension": MarkdownExtension,
            })
        self.loghandlers = [nikola.utils.STDERR_HANDLER]
        self.plugin_manager.setPluginInfoExtension('plugin')
        extra_plugins_dirs = self.config['EXTRA_PLUGINS_DIRS']
        if sys.version_info[0] == 3:
            places = [
                os.path.join(os.path.dirname(nikola.utils.__file__),
                             'plugins'),
            ] + [path for path in extra_plugins_dirs if path]
        else:
            places = [
                os.path.join(os.path.dirname(nikola.utils.__file__),
                             nikola.utils.sys_encode('plugins')),
            ] + [
                nikola.utils.sys_encode(path)
                for path in extra_plugins_dirs if path
            ]
        self.plugin_manager.setPluginPlaces(places)
        self.plugin_manager.collectPlugins()

        self.timeline = [FakePost(title='Fake post', slug='fake-post')]
        self.debug = True
        self.rst_transforms = []
        # This is to make plugin initialization happy
        self.template_system = self
        self.name = 'mako'

    def render_template(self, name, _, context):
        return ('<img src="IMG.jpg">')
Esempio n. 39
0
def disabled_plugins(plugin_kind='main'):
    enabled_plugins = Plugin.objects.all()
    # Build the manager
    manager = PluginManager()
    # Tell it the default place(s) where to find plugins
    manager.setPluginPlaces([
        settings.PLUGIN_DIR,
        os.path.join(settings.PROJECT_DIR, 'server/plugins')
    ])
    # Load all plugins
    manager.collectPlugins()
    output = []

    if plugin_kind == 'main':
        for plugin in manager.getAllPlugins():
            try:
                plugin_type = plugin.plugin_object.plugin_type()
            except:
                plugin_type = 'builtin'
            if plugin_type == 'builtin':
                try:
                    item = Plugin.objects.get(name=plugin.name)
                except Plugin.DoesNotExist:
                    output.append(plugin.name)

    if plugin_kind == 'report':
        for plugin in manager.getAllPlugins():
            try:
                plugin_type = plugin.plugin_object.plugin_type()
            except:
                plugin_type = 'builtin'

            if plugin_type == 'report':
                try:
                    item = Report.objects.get(name=plugin.name)
                except Report.DoesNotExist:
                    output.append(plugin.name)

    if plugin_kind == 'machine_detail':
        for plugin in manager.getAllPlugins():
            try:
                plugin_type = plugin.plugin_object.plugin_type()
            except:
                plugin_type = 'builtin'

            if plugin_type == 'machine_detail':
                try:
                    item = MachineDetailPlugin.objects.get(name=plugin.name)
                except MachineDetailPlugin.DoesNotExist:
                    output.append(plugin.name)

    return output
Esempio n. 40
0
 def load_plugin(self):
     manager = PluginManager()
     manager.setPluginPlaces(["plugins"])
     manager.collectPlugins()
     # Loop round the plugins and print their names.
     for plugin in manager.getAllPlugins():
         print("==========>  ", format(plugin.plugin_object))
         #p="C:\Python34\directory1"
         #print("path is:======>",p)
         self.p1 = plugin.plugin_object.print_name()
         print(self.p1)
         self.p2 = PluginOne()
         self.p2.g()
Esempio n. 41
0
def parse_url(url):
    plugins_folder = os.path.join(os.path.abspath(os.path.dirname(__file__)),
                                  'plugins')
    manager = PluginManager()
    manager.setPluginPlaces([plugins_folder])
    manager.collectPlugins()
    plugins = [
        x for x in manager.getAllPlugins()
        if hasattr(x.plugin_object, 'parse_url')
    ]
    for plugin in plugins:
        for item in plugin.plugin_object.parse_url(url):
            yield item
Esempio n. 42
0
def index(request):
    # Get the current user's Business Units
    user = request.user
    # Count the number of users. If there is only one, they need to be made a GA
    if User.objects.count() == 1:
        # The first user created by syncdb won't have a profile. If there isn't one, make sure they get one.
        try:
            profile = UserProfile.objects.get(user=user)
        except UserProfile.DoesNotExist:
            profile = UserProfile(user=user)
        
        profile.level = 'GA'
        profile.save()
    user_level = user.userprofile.level
    now = datetime.now()
    hour_ago = now - timedelta(hours=1)
    today = date.today()
    week_ago = today - timedelta(days=7)
    month_ago = today - timedelta(days=30)
    three_months_ago = today - timedelta(days=90)
    if user_level != 'GA':
        # user has many BU's display them all in a friendly manner
        business_units = user.businessunit_set.all()
        if user.businessunit_set.count() == 1:
            # user only has one BU, redirect to it
            for bu in user.businessunit_set.all():
                return redirect('server.views.bu_dashboard', bu_id=bu.id)
                break
    else:
        machines = Machine.objects.all()
        # Build the manager
        manager = PluginManager()
        # Tell it the default place(s) where to find plugins
        manager.setPluginPlaces([settings.PLUGIN_DIR, os.path.join(settings.PROJECT_DIR, 'server/plugins')])
        # Load all plugins
        manager.collectPlugins()
        output = []
        # Loop round the plugins and print their names.
        for plugin in manager.getAllPlugins():
            data = {}
            data['name'] = plugin.name
            (data['html'], data['width']) = plugin.plugin_object.show_widget('front', machines)
            #output.append(plugin.plugin_object.show_widget('front'))
            output.append(data)
        output = utils.orderPluginOutput(output)    

        # get the user level - if they're a global admin, show all of the machines. If not, show only the machines they have access to
        business_units = BusinessUnit.objects.all()
        
        c = {'user': request.user, 'business_units': business_units, 'output': output}
        return render_to_response('server/index.html', c, context_instance=RequestContext(request)) 
Esempio n. 43
0
    def create_plugin_manager(category_filter, plugin_place):
        """ Creates a PluginManager object from the given folder according to the given filter
        :param category_filter:
        :param plugin_place:
        :return:
        :rtype: PluginManager
        """
        plugin_manager = PluginManager()
        plugin_manager.setCategoriesFilter(category_filter)
        plugin_manager.setPluginPlaces([plugin_place])

        plugin_manager.collectPlugins()

        return plugin_manager
Esempio n. 44
0
def ConfigurePluginManager(categories=None, pluginLocation=None):
    if categories is None:
        categories = dict(Test=ITestPlugin,
                          DAQ=IDAQPlugin,
                          App=IAppPlugin,
                          Decoder=IDecoderPlugin)
    if pluginLocation is None:
        pluginLocation = ["plugins"]
    manager = PluginManager()
    # todo: plugin directory and categories should be set some other way (command line arg parsing?)
    manager.setPluginPlaces(pluginLocation)
    manager.setCategoriesFilter(categories)
    manager.collectPlugins()
    return manager
Esempio n. 45
0
    def output_results(self, **kwargs):

        self.logger.info("Begin run_output_plugins")

        simplePluginManager = PluginManager()
        logging.getLogger('yapsy').setLevel(logging.DEBUG)
        simplePluginManager.setCategoriesFilter(
            {"OutputResults": data_collector_plugin})

        # Tell it the default place(s) where to find plugins
        self.logger.debug("Plugin directories: %s" %
                          (kwargs['output_plugin_directories']))
        simplePluginManager.setPluginPlaces(
            kwargs['output_plugin_directories'])
        yapsy_logger = logging.getLogger('yapsy')
        yapsy_logger.setLevel(logging.DEBUG)
        # yapsy_logger.parent.level = logging.DEBUG
        yapsy_logger.disabled = False

        simplePluginManager.collectPlugins()

        plugin_cnt = 0
        plugin_start_time = time.time()
        for plugin in simplePluginManager.getAllPlugins():
            try:
                self.logger.info("Starting plugin: %s" % (plugin.name))
                if plugin.plugin_object.initialize_plugin(
                        details=plugin.details,
                        prediction_date=kwargs['prediction_date'].astimezone(
                            timezone("US/Eastern")).strftime(
                                "%Y-%m-%d %H:%M:%S"),
                        execution_date=kwargs['prediction_run_date'].strftime(
                            "%Y-%m-%d %H:%M:%S"),
                        ensemble_tests=kwargs['site_model_ensemble']):
                    plugin.plugin_object.start()
                    plugin_cnt += 1
                else:
                    self.logger.error("Failed to initialize plugin: %s" %
                                      (plugin.details))
            except Exception as e:
                self.logger.exception(e)
        #Wait for the plugings to finish up.
        self.logger.info("Waiting for %d plugins to complete." % (plugin_cnt))
        for plugin in simplePluginManager.getAllPlugins():
            plugin.plugin_object.join()
            plugin.plugin_object.finalize()

        self.logger.debug("%d output plugins run in %f seconds" %
                          (plugin_cnt, time.time() - plugin_start_time))
        self.logger.info("Finished output_results")
Esempio n. 46
0
    def testMultipleCategoriesForASamePlugin(self):
        """
		Test that associating a plugin to multiple categories works as expected.
		"""
        class AnotherPluginIfce(object):
            def __init__(self):
                pass

            def activate(self):
                pass

            def deactivate(self):
                pass

        spm = PluginManager(categories_filter={
            "Default": IPlugin,
            "IP": IPlugin,
            "Other": AnotherPluginIfce,
        },
                            directories_list=[
                                os.path.join(
                                    os.path.dirname(os.path.abspath(__file__)),
                                    "plugins")
                            ])
        # load the plugins that may be found
        spm.collectPlugins()
        # check that the getCategories works
        self.assertEqual(len(spm.getCategories()), 3)
        categories = spm.getCategories()
        self.assertTrue("Default" in categories)
        # check the getPluginsOfCategory
        self.assertEqual(len(spm.getPluginsOfCategory("Default")), 1)
        plugin_info = spm.getPluginsOfCategory("Default")[0]
        self.assertTrue("Default" in plugin_info.categories)
        self.assertTrue("IP" in plugin_info.categories)
        self.assertTrue("IP" in categories)
        # check the getPluginsOfCategory
        self.assertEqual(len(spm.getPluginsOfCategory("IP")), 1)
        self.assertTrue("Other" in categories)
        # check the getPluginsOfCategory
        self.assertEqual(len(spm.getPluginsOfCategory("Other")), 0)
        # try to remove the plugin from one category and check the
        # other category
        spm.removePluginFromCategory(plugin_info, "Default")
        self.assertEqual(len(spm.getPluginsOfCategory("Default")), 0)
        self.assertEqual(len(spm.getPluginsOfCategory("IP")), 1)
        # now re-add this plugin the to same category
        spm.appendPluginToCategory(plugin_info, "Default")
        self.assertEqual(len(spm.getPluginsOfCategory("Default")), 1)
        self.assertEqual(len(spm.getPluginsOfCategory("IP")), 1)
def modelBehaviorImplementations(paths):
    """
    Return an iterable of plugin-info for every locatable implementation of this interface on a given path.
    PyDev for Eclipse reports a compilation error here on a line that is actually legal Python due to
    the schedule upon which module resolution and imports happen.
    """
    manager = PluginManager()
    manager.setPluginPlaces(paths)
    from fakeDataGenerator.model import IModelBehavior as foreignModelBehavior
    #hey PyDev: the previous line is weird, but is actually legal
    manager.setCategoriesFilter({
        "ModelBehavior" : foreignModelBehavior,                         
        })
    manager.collectPlugins()
    return manager.getPluginsOfCategory("ModelBehavior")
Esempio n. 48
0
def load_directory(plugin_folder):
    """Loads and imports a directory of plugins.

    :param plugin_folder: The folder to look for plugin files.
    :type plugin_folder: String

    :rtype: Dictionary
    :returns: A dictionary of imported plugins.

    """
    manager = PluginManager()
    manager.setPluginPlaces([plugin_folder])
    manager.collectPlugins()

    return manager
Esempio n. 49
0
    def testRecursivePluginlocation(self):
        """
		Test detection of plugins which by default must be
		recusrive. Here we give the test directory as a plugin place
		whereas we expect the plugins to be in test/plugins.
		"""
        spm = PluginManager(
            directories_list=[os.path.dirname(os.path.abspath(__file__))])
        # load the plugins that may be found
        spm.collectPlugins()
        # check that the getCategories works
        self.assertEqual(len(spm.getCategories()), 1)
        sole_category = spm.getCategories()[0]
        # check the getPluginsOfCategory
        self.assertEqual(len(spm.getPluginsOfCategory(sole_category)), 1)
Esempio n. 50
0
def main():
    # Load the plugins from the plugin directory.
    manager = PluginManager()
    manager.setPluginPlaces(["plugins\\plugins1", "plugins\\plugins2"])

    manager.setCategoriesFilter({
        "PluginOne": category.PluginOne,
        "PluginTwo": category.PluginTwo,
    })

    print { "PluginOne": category.PluginOne, "PluginTwo": category.PluginTwo }
    manager.collectPlugins()
    print manager.getPluginsOfCategory("PluginTwo")
    for plugin in manager.getPluginsOfCategory("PluginTwo"):
        plugin.plugin_object.print_name()
Esempio n. 51
0
def get_manager():
    categories = {
        catg.ApkChecker.category: catg.ApkChecker,
        catg.Unpacker.category: catg.Unpacker,
        catg.ProtectChecker.category: catg.ProtectChecker,
        catg.Auditor.category: catg.Auditor,
    }

    manager = PluginManager()
    plugin_paths = map(lambda e: os.path.join(settings.PLUGINS_DIR, e),
                       categories.keys())
    manager.setPluginPlaces(plugin_paths)
    manager.setCategoriesFilter(categories)
    manager.collectPlugins()
    return manager
Esempio n. 52
0
def main():
    global p1
    #  Load the plugins from the plugin directory.
    manager = PluginManager()
    manager.setPluginPlaces(["plugins"])
    manager.collectPlugins()
    # Loop round the plugins and print their names.
    for plugin in manager.getAllPlugins():
        print("==========>  ", format(plugin.plugin_object))
        #p="C:\Python34\directory1"
        #print("path is:======>",p)
        p1 = plugin.plugin_object.print_name()
        print(p1)
        p2 = PluginOne()
        p2.g()
    def collect_data(self, **kwargs):
        self.logger.info("Begin collect_data")
        try:
            simplePluginManager = PluginManager()

            yapsy_log = logging.getLogger('yapsy')
            yapsy_log.setLevel(logging.DEBUG)
            yapsy_log.disabled = False

            simplePluginManager.setCategoriesFilter(
                {"DataCollector": data_collector_plugin})

            # Tell it the default place(s) where to find plugins
            self.logger.debug("Plugin directories: %s" %
                              (kwargs['data_collector_plugin_directories']))
            simplePluginManager.setPluginPlaces(
                kwargs['data_collector_plugin_directories'])

            simplePluginManager.collectPlugins()

            output_queue = Queue()
            plugin_cnt = 0
            plugin_start_time = time.time()
            for plugin in simplePluginManager.getAllPlugins():
                self.logger.info("Starting plugin: %s" % (plugin.name))
                if plugin.plugin_object.initialize_plugin(
                        details=plugin.details, queue=output_queue):
                    plugin.plugin_object.start()
                else:
                    self.logger.error("Failed to initialize plugin: %s" %
                                      (plugin.name))
                plugin_cnt += 1

            #Wait for the plugings to finish up.
            self.logger.info("Waiting for %d plugins to complete." %
                             (plugin_cnt))
            for plugin in simplePluginManager.getAllPlugins():
                plugin.plugin_object.join()
                plugin.plugin_object.finalize()
            while not output_queue.empty():
                results = output_queue.get()
                if results[0] == data_result_types.MODEL_DATA_TYPE:
                    self.site_data = results[1]

            self.logger.info("%d Plugins completed in %f seconds" %
                             (plugin_cnt, time.time() - plugin_start_time))
        except Exception as e:
            self.logger.exception(e)
Esempio n. 54
0
def run():  # pragma: no cover
    plugin_manager = PluginManager(
        categories_filter={'py2swagger': Py2SwaggerPlugin},
        directories_list=[os.path.join(os.path.dirname(__file__), 'plugins')],
        plugin_info_ext='py2swagger'
    )
    plugin_manager.collectPlugins()

    parser = argparse.ArgumentParser(description='Swagger schema builder')
    parser.add_argument('-c', '--config', action='store', dest='config', help='Path to config file')
    parser.add_argument('-r', '--root', action='store', dest='root', help='Path to project root. Default is current directory or configuration file location')
    parser.add_argument('-o', '--output', action='store', dest='output', help='Output file (Default stdout)')

    sub_parsers = parser.add_subparsers(title='plugins', dest='plugin')

    # set arguments from plugins
    for plugin in plugin_manager.getAllPlugins():
        sub_parser = sub_parsers.add_parser(plugin.name,
                                            help=plugin.plugin_object.summary,
                                            description=plugin.plugin_object.description)
        plugin.plugin_object.set_parser_arguments(sub_parser)

    args = parser.parse_args()

    sys.path.append(_get_project_root_path(args.root, args.config))

    swagger_settings, plugin_settings = get_settings(args.config)

    plugin = plugin_manager.getPluginByName(args.plugin, category='py2swagger')
    if not plugin:
        sys.stderr.write('Plugin not available\n')
        sys.exit(1)

    try:
        swagger_settings_part = plugin.plugin_object.run(args, **plugin_settings)
    except Py2SwaggerPluginException as e:
        sys.stderr.write('{}\n'.format(e))
        sys.exit(1)

    swagger_settings = update_settings(swagger_settings, swagger_settings_part)
    builder = SchemaBuilder(**swagger_settings)

    swagger_schema = json.dumps(builder.schema, indent=2)
    if args.output:
        with codecs.open(args.output, 'wb', encoding='utf-8') as f:
            f.write(swagger_schema)
    else:
        sys.stdout.write(swagger_schema)
Esempio n. 55
0
def load_plugins():
    """Loads plugins from the puglins folder"""

    plugins = PluginManager()
    plugins_folder = os.path.join(os.environ['LOOKDEVTOOLS'], 'python',
                                  'ldtplugins')
    print plugins_folder
    plugins.setPluginPlaces([plugins_folder])
    plugins.collectPlugins()
    plugins.locatePlugins()
    logger.info('Plugin candidates %s' % plugins.getPluginCandidates())
    for pluginInfo in plugins.getAllPlugins():
        plugins.activatePluginByName(pluginInfo.name)
        logger.info('Plugin activated %s' %
                    plugins.activatePluginByName(pluginInfo.name))
    return plugins
Esempio n. 56
0
    def loadTechniques(self, techniquesPath, controls=None):

        # Build the manager, set load location, and then collect them

        pm = PluginManager()
        pm.updatePluginPlaces([techniquesPath])
        pm.collectPlugins()

        self.techniques = dict()

        for pluginInfo in pm.getAllPlugins():
            print('loading ' + pluginInfo.name + ' for: ' + self.name)
            # Get the object and store in dictionary

            self.techniques[pluginInfo.name] = pluginInfo.plugin_object
            self.techniques[pluginInfo.name].controlPlugins = controls
Esempio n. 57
0
def process_text():
    if not request.json or not 'transcript' in request.json:
        abort(400)
    transcript = request.json['transcript']
    # Initialize the plugin manager.
    simplePluginManager = PluginManager()
    simplePluginManager.setPluginPlaces(["./plugins"])
    simplePluginManager.getPluginLocator().setPluginInfoExtension('plugin.info')
    # Load and activate plugins.
    simplePluginManager.collectPlugins()
    response = { }
    for pluginInfo in simplePluginManager.getAllPlugins():
        returnValue = pluginInfo.plugin_object.process(transcript)
        response.update(returnValue)

    return jsonify(response), 200
Esempio n. 58
0
def get_plugin_manager(config):
    plugin_manager = PluginManager()

    plugin_manager.setPluginPlaces(
            [config.get("GENERAL", "PLUGIN_DIRECTORY")]
            )

    plugin_manager.setCategoriesFilter({
        PluginTypeName.SENSOR: ISensorPlugin,
        PluginTypeName.REPOSITORY: IRepositoryPlugin,
        PluginTypeName.DISPLAY: IDisplayPlugin
    })

    plugin_manager.collectPlugins()

    return plugin_manager
Esempio n. 59
0
def disabled_plugins():
    enabled_plugins = Plugin.objects.all()
    # Build the manager
    manager = PluginManager()
    # Tell it the default place(s) where to find plugins
    manager.setPluginPlaces([settings.PLUGIN_DIR, os.path.join(settings.PROJECT_DIR, 'server/plugins')])
    # Load all plugins
    manager.collectPlugins()
    output = []
    for plugin in manager.getAllPlugins():
        try:
            item = Plugin.objects.get(name=plugin.name)
        except Plugin.DoesNotExist:
            output.append(plugin.name)

    return output
Esempio n. 60
0
def printRagpickerInfos(print_options=False):
    infolog = logging.getLogger("Info")
    infolog.info(color("RAGPICKER_VERSION: " + RAGPICKER_VERSION, RED))
    infolog.info(color("RAGPICKER_BUILD_DATE: " + RAGPICKER_BUILD_DATE, RED))
    infolog.info(color("RAGPICKER_ROOT: " + RAGPICKER_ROOT, RED))
    infolog.info("")

    pluginPlaces = ["crawler", "preProcessing", "processing", "reporting"]

    for place in pluginPlaces:
        infolog.info(
            color("%s| " % (place + " ").upper().ljust(14, '-'), MAGENTA))
        cfg = Config(os.path.join(RAGPICKER_ROOT, 'config', place + '.conf'))
        ragpickerPluginManager = PluginManager()
        ragpickerPluginManager.setPluginPlaces([place])
        ragpickerPluginManager.collectPlugins()

        for pluginInfo in sorted(ragpickerPluginManager.getAllPlugins(),
                                 key=lambda PluginInfo: PluginInfo.name):
            options = cfg.get(pluginInfo.name)

            if options.enabled:
                infolog.info(
                    color("%s V%s   %s", MAGENTA) %
                    ("              |----[+] " + pluginInfo.name.ljust(25),
                     pluginInfo.version, pluginInfo.description))
                if print_options:
                    for key, value in options.iteritems():
                        if key != "enabled":
                            infolog.info(
                                color("                    |-- %s = %s",
                                      MAGENTA) % (key, str(value)))
            else:
                infolog.info(
                    color("%s V%s   %s", BLUE) %
                    ("              |----[-] " + pluginInfo.name.ljust(25),
                     pluginInfo.version, pluginInfo.description))

    infolog.info("")
    infolog.info(
        "            %s %s" %
        (color("([+] = enabled)", MAGENTA), color("([-] = disabled)", BLUE)))
    infolog.info("")

    checkVersion()

    sys.stdout.flush()