Exemplo n.º 1
0
    def load_plugins(self, ns='jules.plugins'):
        """Load engine plugins, and sort them by their plugin_order attribute."""

        # Loading "plain" plugins first, which are the plugin modules under jules.plugins
        plugins = load(ns)
        if not self.plugins:
            self.plugins = plugins
        else:
            self.plugins._plugins += plugins._plugins
        self.plugins._plugins.sort(key=lambda p: getattr(p, 'plugin_order', 0))

        # Load Template plugins, which inject API into templates
        self.template_plugins = load('jules.plugins', subclasses=jules.plugins.TemplatePlugin)
Exemplo n.º 2
0
    def _prepare_contents(self, engine):
        ext_plugins = {}
        content_plugins = load('jules.plugins', subclasses=jules.plugins.ContentPlugin)
        for plugin in content_plugins:
            for ext in plugin.extensions:
                ext_plugins[ext] = plugin(engine)

        content_path = None
        if 'content' in self.meta:
            content_path = os.path.abspath(os.path.expanduser(self.meta['content']))
        else:
            for input_dir, directory, filename in self:
                if content_path is not None:
                    break
                for ext in ext_plugins:
                    if filename.endswith(ext):
                        content_path = os.path.join(input_dir, directory, filename)
                        break

        content_parser = ext_plugins[ext]

        if content_path:
            try:
                self.content = ext_plugins[ext].parse(open(content_path))
            except IOError:
                pass
        if not self.content:
            src = self.meta.get('content')
            if src:
                self.content = ext_plugins[ext].parse_string(src)
Exemplo n.º 3
0
    def _load(self, *args, **kwargs):
        # FIXME: namespace hack
        plugins = []
        for ns in self.nss:
            plugins.extend(load(ns, *args, **kwargs))

        return plugins
Exemplo n.º 4
0
def find_Plugins(plugin, path="plugins", cls=Destinations):
    plugins = load(path, cls)
    for i in range(0, len(plugins)):
        log.debug("Plugin Found: %s", plugins[i].DESTINATION)
        if plugins[i].DESTINATION == plugin:
            log.debug("Destination %s found", plugins[i].DESTINATION)
            return plugins[i]
Exemplo n.º 5
0
def get_plugin_names(blacklist=None, without_backref=False):
    """ Return the list of plugins names.

    :arg blacklist: name or list of names to not return
    :type blacklist: string or list of strings
    :arg without_backref: whether or not to include hooks that
        have backref "None"
    :type without_backref: bool
    :return: list of plugin names (strings)
    """
    from pagure.hooks import BaseHook

    plugins = load("pagure.hooks", subclasses=BaseHook)
    if not blacklist:
        blacklist = []
    elif not isinstance(blacklist, list):
        blacklist = [blacklist]

    output = [
        plugin.name for plugin in plugins
        if plugin.name not in blacklist and (plugin.backref or without_backref)
    ]
    # The default hook is not one we show
    if "default" in output:
        output.remove("default")
    return sorted(output)
Exemplo n.º 6
0
    def _load_checks(self):
        """
        Load all checks in FedoraReview.checks + external plugin
        directories and add them to self.checkdict
        """

        self.checkdict = _CheckDict()
        self.groups = {}

        appdir = os.path.realpath(
            os.path.join(os.path.dirname(__file__)))
        sys.path.insert(0, appdir)
        sys.path.insert(0, XdgDirs.app_datadir)
        plugins = load('plugins')
        for plugin in sorted(plugins, key=lambda p: len(p.__name__)):
            if plugin.__name__ == 'plugins.plugins':
                continue
            registry = plugin.Registry(self)
            tests = registry.register(plugin)
            self.checkdict.extend(tests)
            self.groups[registry.group] = registry
        for c in self.checkdict:
            if not self.checkdict[c].registry:
                self.checkdict[c].registry = self.groups[c.group]
        sys.path.remove(XdgDirs.app_datadir)
        sys.path.remove(appdir)
Exemplo n.º 7
0
    def _load_checks(self):
        """
        Load all checks in FedoraReview.checks + external plugin
        directories and add them to self.checkdict
        """

        self.checkdict = _CheckDict()
        self.groups = {}

        appdir = os.path.realpath(os.path.join(os.path.dirname(__file__)))
        sys.path.insert(0, appdir)
        sys.path.insert(0, XdgDirs.app_datadir)
        plugins = load('plugins')
        for plugin in sorted(plugins, key=lambda p: len(p.__name__)):
            if plugin.__name__ == 'plugins.plugins':
                continue
            registry = plugin.Registry(self)
            tests = registry.register(plugin)
            self.checkdict.extend(tests)
            self.groups[registry.group] = registry
        for c in self.checkdict:
            if not self.checkdict[c].registry:
                self.checkdict[c].registry = self.groups[c.group]
        sys.path.remove(XdgDirs.app_datadir)
        sys.path.remove(appdir)
Exemplo n.º 8
0
def get_plugin(plugin_name):
    ''' Return the list of plugins names. '''
    from pagure.hooks import BaseHook
    plugins = load('pagure.hooks', subclasses=BaseHook)
    for plugin in plugins:
        if plugin.name == plugin_name:
            return plugin
Exemplo n.º 9
0
def get_enabled_plugins(project, with_default=False):
    """ Returns a list of plugins enabled for a specific project.

    Args:
        project (model.Project): The project to look for.
        with_default (boolean): Wether or not the returned list should
            include the default hook/plugin.
    Returns: (list): A  list of tuples (pluginclass, dbobj) with the plugin
        classess and dbobjects for plugins enabled for the project.
    """
    from pagure.hooks import BaseHook
    from pagure.hooks.default import Default

    enabled = []
    if with_default:
        enabled = [(Default(), None)]
    for plugin in load("pagure.hooks", subclasses=BaseHook):
        if plugin.name == "default":
            continue
        plugin.db_object()
        if hasattr(project, plugin.backref):
            dbobj = getattr(project, plugin.backref)
            if dbobj and dbobj.active:
                enabled.append((plugin, dbobj))
    return enabled
 def __makeServerObj(self,objGeneratorName,objGeneratorFolder,objGeneratorPackageName,objGeneratorSubclass,objGeneratorNotFoundException,serverConfig,objSection,serverConfigPath):
     ''' Make an objSection from the config file path of an objSection, and the required socket
     
     :param serverConfig config ini path to the socket
     :param objSection a string to get the objSection objSection
     :param serverConfigPath:
     :returns an objSection type socket
     '''
     
     #get server specific config for objSection (socket number etc)
     outletParams = turpleList2Dict(serverConfig.items(objSection))
     
     #get objSection type so we can pull its config data
     outletConfig=serverConfig.get(objSection, objGeneratorName)
     outletConfigPath = os.path.join(objGeneratorFolder,outletConfig + ".ini")
     outletConfig = SafeConfigParser()
     
     #Create the objSection with server params and objSection config 
     outletConfig.read(outletConfigPath)
     outletConfigDict={}
     self.mainDaemon.debug("Loading:"+str(outletConfigPath))
     for section in outletConfig.sections(): 
         outletConfigDict[section] = turpleList2Dict(outletConfig.items(objGeneratorName))
     
     #Find from type the kind of objSection
     outlets = load(objGeneratorPackageName,subclasses=objGeneratorSubclass)
     outletType = outletConfigDict[objGeneratorName]['type']
     for outletClass in outlets:
         if outletClass.__name__ == outletType:
             return outletClass(objSection,outletConfigDict,outletParams)
     raise objGeneratorNotFoundException(outletConfigPath,outletType)
Exemplo n.º 11
0
def get_plugin(plugin_name):
    """ Return the list of plugins names. """
    from pagure.hooks import BaseHook

    plugins = load("pagure.hooks", subclasses=BaseHook)
    for plugin in plugins:
        if plugin.name == plugin_name:
            return plugin
Exemplo n.º 12
0
 def __init__(self):
     self.plugins = []
     plugins = load(TEST_MODULES_DIR,subclasses=serviceTesters.TemplateTester.TemplateTester)
     print plugins
     for plugin in plugins:
         if plugin.__name__ in pluginLoadList:
             self.plugins.append(plugin(self))
     
     for plugin in self.plugins:
         plugin.test()
Exemplo n.º 13
0
def get_plugin_names(blacklist=None):
    ''' Return the list of plugins names. '''
    plugins = load('pagure.hooks', subclasses=BaseHook)
    if not blacklist:
        blacklist = []
    elif not isinstance(blacklist, list):
        blacklist = [blacklist]
    output = [
        plugin.name for plugin in plugins if plugin.name not in blacklist
    ]
    return output
 def _getClassDictIndex(self,package,subclass):
     ''' Get a list of modules
     
     :param package: The package path to search
     :param subclass: The subclass to search for 
     :return: A list of the names of the classes ''' 
     classTypeDict = {}
     outlets = load(package,subclasses=subclass)
     for outletClass in outlets:
         if not outletClass.__name__ in classTypeDict:
             classTypeDict[outletClass.__name__] = outletClass.__doc__
     return classTypeDict
Exemplo n.º 15
0
def get_plugin_names(blacklist=None):
    ''' Return the list of plugins names. '''
    plugins = load('pagure.hooks', subclasses=BaseHook)
    if not blacklist:
        blacklist = []
    elif not isinstance(blacklist, list):
        blacklist = [blacklist]
    output = [
        plugin.name
        for plugin in plugins
        if plugin.name not in blacklist
    ]
    return sorted(output)
Exemplo n.º 16
0
    def run(self):
        """
        Run the program.  This is the main entrypoint to the magnate client
        """
        # Create the statedir if it doesn't exist
        if not os.path.exists(self.cfg['state_dir']):
            os.makedirs(self.cfg['state_dir'])

        twiggy.dict_config(self.cfg['logging'])

        # Base data attributes
        self._load_data_definitions()

        ui_plugins = load('magnate.ui', subclasses=UserInterface)
        for UIClass in ui_plugins:  #pylint: disable=invalid-name
            if UIClass.__module__.startswith('magnate.ui.{}'.format(
                    self.cfg['ui_plugin'])):
                break
        else:
            print('Unknown user ui: {}'.format(self.cfg['ui_plugin']))
            return 1

        # Try using uvloop instead of the asyncio event loop
        if self.cfg['use_uvloop']:
            try:
                import uvloop
            except Exception:
                print(
                    'Could not import uvloop.  Falling back on asyncio event loop'
                )
            try:
                asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
            except Exception:
                print(
                    'Could not set uvloop to be the event loop.  Falling back on asyncio event loop'
                )

        loop = asyncio.get_event_loop()
        self.pubpen = PubPen(loop)
        self._setup_markets()
        self.dispatcher = Dispatcher(self, self.markets)

        # UIClass is always available because we'd have already returned (via
        # the for-else) if UIClass was not defined
        try:
            user_interface = UIClass(self.pubpen, self.cfg['ui_args'])  # pylint: disable=undefined-loop-variable
            return user_interface.run()
        except Exception as e:
            mlog.trace('error').error(
                'Exception raised while running the user interface')
            raise
Exemplo n.º 17
0
def main():
    """
    Main entrypoint of the script

    "It all starts here"
    """
    subcommands = load('build_ansible.command_plugins',
                       subclasses=commands.Command)

    arg_parser = create_arg_parser(os.path.basename(sys.argv[0]))
    arg_parser.add_argument(
        '--debug',
        dest='debug',
        required=False,
        default=False,
        action='store_true',
        help='Show tracebacks and other debugging information')
    subparsers = arg_parser.add_subparsers(
        title='Subcommands',
        dest='command',
        help='for help use build-ansible.py SUBCOMMANDS -h')
    subcommands.pipe('init_parser', subparsers.add_parser)

    if argcomplete:
        argcomplete.autocomplete(arg_parser)

    args = arg_parser.parse_args(sys.argv[1:])
    if args.command is None:
        print('Please specify a subcommand to run')
        sys.exit(1)

    for subcommand in subcommands:
        if subcommand.name == args.command:
            command = subcommand
            break
    else:
        # Note: We should never trigger this because argparse should shield us from it
        print('Error: {0} was not a recognized subcommand'.format(
            args.command))
        sys.exit(1)

    try:
        retval = command.main(args)
    except (errors.DependencyError, errors.MissingUserInput,
            errors.InvalidUserInput) as e:
        print(e)
        if args.debug:
            raise
        sys.exit(2)

    sys.exit(retval)
Exemplo n.º 18
0
def _parse_args(args=tuple(sys.argv)):
    """Parse command line arguments"""
    parser = argparse.ArgumentParser(description='A space themed trading game')
    parser.add_argument('--version', action='version', version=__version__)
    parser.add_argument('--conf-file',
                        dest='cfg_file',
                        action='store',
                        default=None,
                        help='Alternate location for configuration file')
    parser.add_argument(
        '--ui-args',
        dest='ui_args',
        action='append',
        default=[],
        help='Extra arguments for the user interface plugins. Only needed if the'
        ' arguments conflict with stellar magnate arguments.  Specify this for each extra arg'
    )
    parser.add_argument(
        '--use-uvloop',
        dest='uvloop',
        action='store_true',
        default=False,
        help='Enable use of uvloop instead of the default asyncio event loop.')
    parser.add_argument(
        '--_testing-configuration',
        dest='test_cfg',
        action='store_true',
        help='Overrides data file locations for running from a source checkout.'
        ' For development only')

    ui_plugin_names = []
    ui_plugins = load('magnate.ui', subclasses=UserInterface)
    for plugin in ui_plugins:
        ui_plugin_names.append(plugin.__module__[len('magnate.ui.'):])

    parser.add_argument('--ui-plugin',
                        dest='ui_plugin',
                        action='store',
                        default=None,
                        help='Specify a user interface plugin to use.'
                        ' Valid plugin names: {}'.format(
                            ', '.join(ui_plugin_names)))

    args, remainder = parser.parse_known_args(args[1:])

    # Extra arguments for the ui plugins
    remainder.extend(args.ui_args)
    args.ui_args = remainder

    return args
Exemplo n.º 19
0
def get_plugin_and_folder(inputzip=None, inputdir=None, inputfile=None):
    """ Main function. """

    if (inputzip and inputdir) \
            or (inputzip and inputfile) \
            or (inputdir and inputfile):
        raise MQ2Exception('You must provide either a zip file or a '
                           'directory or an input file as input.')
    if not inputzip and not inputdir and not inputfile:
        raise MQ2Exception('You must provide either a zip file or a '
                           'directory or an input file as input.')

    # retrieve input: file, directory, zip
    if inputzip:
        tmp_folder = set_tmp_folder()
        extract_zip(inputzip, tmp_folder)
    elif inputfile:
        tmp_folder = inputfile
    else:
        tmp_folder = inputdir

    # retrieve the plugins
    plugins = load('MQ2.plugins', subclasses=PluginInterface)
    LOG.debug('Plugin loaded: %s' % [plugin.name for plugin in plugins])

    # keep only the plugins that will work
    plugins = [plugin for plugin in plugins if plugin.is_applicable()]
    LOG.debug('Plugin applicable: %s' % [plugin.name for plugin in plugins])

    # keep only the plugins that have the file(s) they need
    if inputfile:
        plugins = [
            plugin for plugin in plugins if plugin.valid_file(tmp_folder)
        ]
    else:
        plugins = [
            plugin for plugin in plugins if plugin.get_files(tmp_folder)
        ]

    LOG.debug('Plugin w/ valid input: %s' %
              [plugin.name for plugin in plugins])

    if len(plugins) > 1:
        raise MQ2Exception('Your dataset contains valid input for '
                           'several plugins.')
    if len(plugins) == 0:
        raise MQ2Exception('Invalid dataset: your input cannot not be '
                           'processed by any of the current plugins.')
    plugin = plugins[0]
    return (plugin, tmp_folder)
Exemplo n.º 20
0
def _get_comparators():
    plugins = load("dacman.plugins", subclasses=Comparator)
    comparators = {}
    for plugin in plugins:
        comparator = plugin()
        LOG.debug(f'comparator={comparator}')
        supports = comparator.supports()
        LOG.info("Plugin {} supports: {}".format(plugin, supports))
        if type(supports) == list:
            for s in supports:
                _add_comparator(s, comparator, comparators)
        else:
            _add_comparator(supports, comparator, comparators)

    return comparators
Exemplo n.º 21
0
Arquivo: mq2.py Projeto: PBR/MQ2
def get_plugin_and_folder(inputzip=None, inputdir=None, inputfile=None):
    """ Main function. """

    if (inputzip and inputdir) \
            or (inputzip and inputfile) \
            or (inputdir and inputfile):
        raise MQ2Exception('You must provide either a zip file or a '
                           'directory or an input file as input.')
    if not inputzip and not inputdir and not inputfile:
        raise MQ2Exception('You must provide either a zip file or a '
                           'directory or an input file as input.')

    # retrieve input: file, directory, zip
    if inputzip:
        tmp_folder = set_tmp_folder()
        extract_zip(inputzip, tmp_folder)
    elif inputfile:
        tmp_folder = inputfile
    else:
        tmp_folder = inputdir

    # retrieve the plugins
    plugins = load('MQ2.plugins', subclasses=PluginInterface)
    LOG.debug('Plugin loaded: %s' % [plugin.name for plugin in plugins])

    # keep only the plugins that will work
    plugins = [plugin for plugin in plugins if plugin.is_applicable()]
    LOG.debug('Plugin applicable: %s' % [plugin.name for plugin in plugins])

    # keep only the plugins that have the file(s) they need
    if inputfile:
        plugins = [plugin for plugin in plugins
                   if plugin.valid_file(tmp_folder)]
    else:
        plugins = [plugin for plugin in plugins
                   if plugin.get_files(tmp_folder)]

    LOG.debug('Plugin w/ valid input: %s' %
              [plugin.name for plugin in plugins])

    if len(plugins) > 1:
        raise MQ2Exception('Your dataset contains valid input for '
                           'several plugins.')
    if len(plugins) == 0:
        raise MQ2Exception('Invalid dataset: your input cannot not be '
                           'processed by any of the current plugins.')
    plugin = plugins[0]
    return (plugin, tmp_folder)
Exemplo n.º 22
0
def do_test(args):
    from straight.plugin import load
    from straight.plugin.loaders import ClassLoader
    plugin_classes = load('neurounitscontrib.test.plugins',
                          subclasses=TestingPluginBase)
    plugins = plugin_classes.produce()

    print 'Testing Plugins:'
    for plugin in plugins:
        print ' * Plugin:', plugin.get_name()

    # Run all:
    print 'Running:'
    for plugin in plugins:
        print ' * Plugin:', plugin.get_name()
        plugin.run(args)
Exemplo n.º 23
0
def do_test(args):
    from straight.plugin import load
    from straight.plugin.loaders import ClassLoader
    plugin_classes = load('neurounitscontrib.test.plugins', subclasses=TestingPluginBase)
    plugins = plugin_classes.produce()


    print 'Testing Plugins:'
    for plugin in plugins:
        print ' * Plugin:', plugin.get_name()

    # Run all:
    print 'Running:'
    for plugin in plugins:
        print ' * Plugin:', plugin.get_name()
        plugin.run(args)
Exemplo n.º 24
0
def load_plugin_by_name(name):
    """
    >>> plugin = load_plugin_by_name('cloudstack')
    >>> plugin.__name__
    'vdt.deployplugin.cloudstack'
    >>> plugin.template
    '\\n\\n[cloudstack]\\napiurl = http://example.com:8080/client/api\\napikey =\\nsecretkey =\\ndomainid = 29\\nzoneid = 6\\ntemplateid = 519\\nserviceid = 17\\ncloudinit_puppet = http://example.com/vdt-puppet-agent.cloudinit\\ncloudinit_base = http://example.com/vdt-base.cloudinit\\n'
    >>> plugin.Provider.prompt
    'cloudstack> '
    """
    plugins = load(PLUGIN_NAMESPACE)
    full_name = "%s.%s" % (PLUGIN_NAMESPACE, name)
    try:
        plugin = (plugin for plugin in plugins if plugin.__name__ == full_name).next()
        return plugin
    except StopIteration:
        raise UnknownPlugin(name, [plugin.__name__.split('.').pop() for plugin in plugins])
Exemplo n.º 25
0
def get_plugin_names(blacklist=None):
    """ Return the list of plugins names. """
    from pagure.hooks import BaseHook

    plugins = load("pagure.hooks", subclasses=BaseHook)
    if not blacklist:
        blacklist = []
    elif not isinstance(blacklist, list):
        blacklist = [blacklist]

    output = [
        plugin.name for plugin in plugins if plugin.name not in blacklist
    ]
    # The default hook is not one we show
    if "default" in output:
        output.remove("default")
    return sorted(output)
Exemplo n.º 26
0
def get_plugin_names(blacklist=None):
    ''' Return the list of plugins names. '''
    from pagure.hooks import BaseHook
    plugins = load('pagure.hooks', subclasses=BaseHook)
    if not blacklist:
        blacklist = []
    elif not isinstance(blacklist, list):
        blacklist = [blacklist]

    output = [
        plugin.name
        for plugin in plugins
        if plugin.name not in blacklist
    ]
    # The default hook is not one we show
    if 'default' in output:
        output.remove('default')
    return sorted(output)
Exemplo n.º 27
0
def do_demo(args):
    from straight.plugin import load
    plugin_classes = load('neurounitscontrib.demo.plugins',
                          subclasses=DemoPluginBase)
    plugins = plugin_classes.produce()

    print 'Testing Plugins:'
    for plugin in plugins:
        print ' * Plugin:', plugin.get_name()

    # Run all:
    print 'Running:'
    for plugin in plugins:
        print ' * Plugin:', plugin.get_name()
        plugin.run(args)

    import pylab
    pylab.show()
Exemplo n.º 28
0
def do_demo(args):
    from straight.plugin import load
    plugin_classes = load('neurounitscontrib.demo.plugins', subclasses=DemoPluginBase)
    plugins = plugin_classes.produce()


    print 'Testing Plugins:'
    for plugin in plugins:
        print ' * Plugin:', plugin.get_name()

    # Run all:
    print 'Running:'
    for plugin in plugins:
        print ' * Plugin:', plugin.get_name()
        plugin.run(args)


    import pylab
    pylab.show()
Exemplo n.º 29
0
 def __init__(self, args, spec_file, srpm_file):
     self.checks = []
     self.ext_checks = []
     self.args = args  # Command line arguments & options
     self.cache = args.cache
     self.nobuild = args.nobuild
     self._results = {'PASSED': [], 'FAILED': [], 'NA': [], 'USER': []}
     if spec_file:
         self.spec = SpecFile(spec_file)
     else:
         self.spec = None
     self.sources = Sources()
     self.log = get_logger()
     if srpm_file:
         self.srpm = SRPMFile(srpm_file)
     else:
         self.srpm = None
     self.plugins = load('FedoraReview.checks')
     self.add_check_classes()
Exemplo n.º 30
0
    def add_check_classes(self):
        """
        Get all check classes in FedoraReview.checks + external plugin
        directories and add them to self.checkdict
        """

        self.checkdict = _CheckDict()
        self.groups = {}

        # appdir gets used when running from git
        appdir = os.path.abspath(os.path.join(__file__, '../../..'))
        # sysappdir gets used when running from /usr.  We expect pluings
        # directory to be symlinked in same directory as this __file__
        sysappdir = os.path.abspath(os.path.dirname(__file__))
        sys.path.insert(0, sysappdir)
        sys.path.insert(0, appdir)
        sys.path.insert(0, XdgDirs.app_datadir)
        plugins = load('plugins')
        for plugin in plugins:
            registry = plugin.Registry(self)
            tests = registry.register(plugin)
            self.checkdict.extend(tests)
            self.groups[registry.group] = registry
        sys.path.remove(XdgDirs.app_datadir)
        sys.path.remove(appdir)
        sys.path.remove(sysappdir)

        ext_dirs = []
        if "REVIEW_EXT_DIRS" in os.environ:
            ext_dirs = os.environ["REVIEW_EXT_DIRS"].split(":")
        ext_dirs.extend(Settings.ext_dirs)
        for ext_dir in ext_dirs:
            if not os.path.isdir(ext_dir):
                continue
            for plugin in os.listdir(ext_dir):
                full_path = os.path.join(ext_dir, plugin)
                if os.path.isfile(full_path) and os.access(full_path, os.X_OK):
                    if full_path.endswith('.py'):
                        continue
                    self.log.debug('Add external module: %s' % full_path)
                    pl = JSONPlugin(self, full_path)
                    tests = pl.register()
                    self.checkdict.extend(tests)
Exemplo n.º 31
0
 def __init__(self, args, spec_file, srpm_file, cache=False,
         nobuild=False, mock_config='fedora-rawhide-i386'):
     self.checks = []
     self.ext_checks = []
     self.args = args  # Command line arguments & options
     self.cache = cache
     self.nobuild = nobuild
     self._results = {'PASSED': [], 'FAILED': [], 'NA': [], 'USER': []}
     self.deprecated = []
     if spec_file:
         self.spec = SpecFile(spec_file)
     else:
         self.spec = None
     self.sources = Sources(cache=cache, mock_config=mock_config)
     self.log = get_logger()
     if srpm_file:
         self.srpm = SRPMFile(srpm_file, cache=cache, nobuild=nobuild,
             mock_config=mock_config, spec=self.spec)
     else:
         self.srpm = None
     self.plugins = load('FedoraReview.checks')
     self.add_check_classes()
Exemplo n.º 32
0
def get_enabled_plugins(project):
    """ Returns a list of plugins enabled for a specific project.

    Args:
        project (model.Project): The project to look for.
    Returns: (list): A  list of tuples (pluginclass, dbobj) with the plugin
        classess and dbobjects for plugins enabled for the project.
    """
    from pagure.hooks import BaseHook

    enabled = []
    for plugin in load("pagure.hooks", subclasses=BaseHook):
        if plugin.backref is None:
            if plugin.is_enabled_for(project):
                enabled.append((plugin, None))
        else:
            plugin.db_object()
            if hasattr(project, plugin.backref):
                dbobj = getattr(project, plugin.backref)
                if dbobj and dbobj.active:
                    enabled.append((plugin, dbobj))
    return enabled
Exemplo n.º 33
0
def load_plugin_by_name(name):
    """
    Load the plugin with the specified name.
    
    >>> plugin = load_plugin_by_name('default')
    >>> api = dir(plugin)
    >>> 'build_package' in api
    True
    >>> 'get_version' in api
    True
    >>> 'set_package_version' in api
    True
    >>> 'set_version' in api
    True
    """
    plugins = load(PLUGIN_NAMESPACE)
    full_name = "%s.%s" % (PLUGIN_NAMESPACE, name)
    try:
        plugin = (plugin for plugin in plugins if plugin.__name__ == full_name).next()
        return plugin
    except StopIteration:
        raise UnknownPlugin([plugin.__name__.split('.').pop() for plugin in plugins])
Exemplo n.º 34
0
 def __init__(self, spec_file, srpm_file):
     ''' Create a Checks set. srpm_file and spec_file are required,
     unless invoked from ChecksLister.
     '''
     self.checks = []
     self.ext_checks = []
     self._results = {'PASSED': [], 'FAILED': [], 'NA': [], 'USER': []}
     self.log = Settings.get_logger()
     if hasattr(self, 'sources'):
         # This is  a listing instance
         self.srpm = None
         self.spec=None
     else:
         self.spec = SpecFile(spec_file)
         self.sources = Sources(self.spec)
         self.srpm = SRPMFile(srpm_file, self.spec)
     self.plugins = load('FedoraReview.checks')
     self.add_check_classes()
     if Settings.single:
         self.set_single_check(Settings.single)
     elif Settings.exclude:
         self.exclude_checks(Settings.exclude)
Exemplo n.º 35
0
def load_plugin_by_name(name):
    """
    Load the plugin with the specified name.
    
    >>> plugin = load_plugin_by_name('default')
    >>> api = dir(plugin)
    >>> 'build_package' in api
    True
    >>> 'get_version' in api
    True
    >>> 'set_package_version' in api
    True
    >>> 'set_version' in api
    True
    """
    plugins = load(PLUGIN_NAMESPACE)
    full_name = "%s.%s" % (PLUGIN_NAMESPACE, name)
    try:
        plugin = (plugin for plugin in plugins
                  if plugin.__name__ == full_name).next()
        return plugin
    except StopIteration:
        raise UnknownPlugin(
            [plugin.__name__.split('.').pop() for plugin in plugins])
Exemplo n.º 36
0
def main(argv):
    import sys
    import argparse
    from straight.plugin import load

    parser = argparse.ArgumentParser()
    parser.add_argument('-c', '--config', default='csbot.cfg',
                        help='Configuration file [default: %(default)s]')
    args = parser.parse_args(argv[1:])

    # Start twisted logging
    log.startLogging(sys.stdout)

    # Find plugins
    plugins = load('csbot.plugins', subclasses=Plugin)
    print "Plugins found:", plugins

    # Start client
    f = BotFactory(config=args.config,
                   plugins=plugins,
                   channels=['#cs-york-dev'],
                   command_prefix='!')
    reactor.connectTCP('irc.freenode.net', 6667, f)
    reactor.run()
Exemplo n.º 37
0
def get_plugin_names():
    ''' Return the list of plugins names. '''
    plugins = load('anitya.lib.backends', subclasses=BaseBackend)
    output = [plugin.name for plugin in plugins]
    return output
Exemplo n.º 38
0
import ast
import sys
import string
import inspect

from analyser.bases import BaseClassCheck
from straight.plugin import load

plugins = load('analyser.extensions', subclasses=BaseClassCheck)


def check_class(node):
    # The call() function yields a function object
    # http://straightplugin.readthedocs.io/en/latest/api.html#straight.plugin.manager.PluginManager.call
    # Not sure why..
    for p in plugins.call('check_violation', node):
        if p:
            p()


def analyse(file_path):
    with open(file_path) as f:
        root = ast.parse(f.read())
        for node in ast.walk(root):
            if isinstance(node, ast.ClassDef):
                check_class(node)


if __name__ == '__main__':
    if len(sys.argv) != 2:
        sys.exit('Usage: main.py <file path>')
Exemplo n.º 39
0
def get_plugin_tables():
    ''' Return the list of all plugins. '''
    plugins = load('pagure.hooks', subclasses=BASE)
    return plugins
Exemplo n.º 40
0
def get_plugins():
    ''' Return the list of plugins. '''
    return load('anitya.lib.backends', subclasses=BaseBackend)
Exemplo n.º 41
0
Arquivo: app.py Projeto: nilleb/magpie
            subkind: str = None) -> Tuple[Optional[bytes], Optional[str]]:
        raise NotImplementedError

    def persist(
        self,
        commit_id: str,
        data: bytes,
        filepath: str,
        branch: str = None,
        kind: str = None,
        subkind: str = None,
    ):
        raise NotImplementedError


reference_adapter_plugins = load("magpie.plugins", subclasses=ReferenceAdapter)


def iter_callable(git, ref):
    def call():
        return git.iter_git_commits([ref])

    return call


def determine_parent_commit(db_commits: frozenset,
                            iter_callable: Callable) -> Optional[str]:
    for commits_chunk in iter_callable():
        for commit in commits_chunk:
            if commit in db_commits:
                return commit
Exemplo n.º 42
0
import signal
import sys
import threading

from straight.plugin import load

from pathspider.base import SHUTDOWN_SENTINEL
from pathspider.base import QUEUE_SIZE

from pathspider.chains.base import Chain

from pathspider.observer import Observer

from pathspider.network import interface_up

chains = load("pathspider.chains", subclasses=Chain)


def run_observer(args):
    logger = logging.getLogger("pathspider")

    if args.list_chains:
        print("The following chains are available:\n")
        for chain in chains:
            print(chain.__name__.lower()[:-5])
        print("\nSpider safely!")
        sys.exit(0)

    interface = args.interface

    if not ":" in args.interface:
    ETC_DIR= appendProjectPath()
    config.read(os.path.join(ETC_DIR,"config.ini"))
    return config,ETC_DIR
config,ETC_DIR = loadConfig()


SVXLINK_CMD = config.get('main', 'SVXLINK_CMD')
dirname, filename = os.path.split(os.path.abspath(__file__))
MODULES_DIR=config.get('main', 'MODULES_DIR')
PLAY_SOUND_COMMAND = os.path.join(dirname,config.get('main', 'PLAY_SOUND_COMMAND'))
TONES_PATH = os.path.join(dirname,'..',config.get('main', 'TONES_PATH'))
SOUNDS_PATH = os.path.join(dirname,'..',config.get('main', 'SOUNDS_PATH'))

pluginLoadList=json.loads(config.get("main","pluginLoadList"))

plugins = load(MODULES_DIR,subclasses=modules.SvxlinkwrapperModule.SvxlinkwrapperModule)

class SvxLinkWrapper:
    '''
    Main SvxLinkWrapper
    '''
    def __init__(self):
        '''
        Constructor
        '''
        self.config = config
        #loads all the plugins listed in to self.plugins
        self.plugins = []
        for plugin in plugins:
            if plugin.__name__ in pluginLoadList:
                self.plugins.append(plugin(self))
Exemplo n.º 44
0
def get_plugin_tables():
    ''' Return the list of all plugins. '''
    plugins = load('pagure.hooks', subclasses=BASE)
    return plugins
Exemplo n.º 45
0
 def get_plugins(self):
     ''' Return the list of plugins.'''
     return load(self._namespace, subclasses=self._base_class)
Exemplo n.º 46
0
    def _getPlugins(self, namespace, cls):
        """Utility to load and instansiate a set of plugins."""

        for plugin in load(namespace, subclasses=cls):
            if plugin.__module__ != "straight.command":
                yield plugin()
Exemplo n.º 47
0
#  from pysnip.snip import Snip, registered_snips
from pysnip.snip import Snip, registered_snips
from pysnip.management import commands
from straight.plugin import load
load("pysnip.collection", subclasses=Snip)



__version__ = '0.1'
Exemplo n.º 48
0
def get_plugin_names():
    ''' Return the list of plugins names. '''
    plugins = load('anitya.lib.backends', subclasses=BaseBackend)
    output = [plugin.name for plugin in plugins]
    return output
Exemplo n.º 49
0
def get_plugin_tables():
    """ Return the list of all plugins. """
    plugins = load("pagure.hooks", subclasses=BASE)
    return plugins
Exemplo n.º 50
0
def get_plugin(plugin_name):
    ''' Return the plugin corresponding to the given plugin name. '''
    plugins = load('anitya.lib.backends', subclasses=BaseBackend)
    for plugin in plugins:
        if plugin.name == plugin_name:
            return plugin
Exemplo n.º 51
0
def get_plugin(plugin_name):
    ''' Return the list of plugins names. '''
    plugins = load('pagure.hooks', subclasses=BaseHook)
    for plugin in plugins:
        if plugin.name == plugin_name:
            return plugin
Exemplo n.º 52
0
def main():
    class SubcommandHelpFormatter(argparse.RawDescriptionHelpFormatter):
        def _format_action(self, action):
            parts = super()._format_action(action)
            if action.nargs == argparse.PARSER:
                #parts = "\n".join([line for line in parts.split("\n")[1:]])
                parts += "\n\nOnion safely!"
            return parts

    parser = argparse.ArgumentParser(
        description='A bushel of onions is 57 lbs',
        formatter_class=SubcommandHelpFormatter)
    parser.add_argument("--verbose",
                        action="store_true",
                        help="Enhanced logging")
    subparsers = parser.add_subparsers(help="Subcommands")

    parser_scrape = subparsers.add_parser(
        "scrape",
        help=
        "Recursively download all documents referenced by the latest consensus"
    )
    parser_scrape.add_argument("--client",
                               help="Download in client mode",
                               action="store_true")
    parser_scrape.add_argument("--archive-path",
                               help="Alternative path to the archive",
                               default=".")
    parser_scrape.set_defaults(coro=scrape)

    parser_scrub = subparsers.add_parser(
        "scrub", help="Check for missing documents in the filesystem storage")
    parser_scrub.add_argument(
        "path", help="Path to consensus(es) to use as starting points")
    parser_scrub.add_argument(
        "--legacy-archive",
        help="Strict CollecTor File Structure Protocol mode",
        default=False,
        action="store_true")
    parser_scrub.add_argument(
        "--ignore-extra-info",
        help="Ignore references to extra-info descriptors",
        default=False,
        action="store_true")
    parser_scrub.set_defaults(coro=scrub)

    cmds = load("bushel.cmd", subclasses=PluggableCommand)

    for cmd in cmds:
        cmd.register_subparser(subparsers)

    args = parser.parse_args()
    logging.getLogger("bushel").setLevel(
        logging.DEBUG if args.verbose else logging.INFO)
    logging.getLogger("stem").setLevel(logging.INFO)
    if vars(args).get("func"):
        args.func(args)
    elif vars(args).get("coro"):
        asyncio.run(args.coro(args))
    else:
        parser.print_help()
Exemplo n.º 53
0
# -*- coding: utf-8 -*-

import ConfigParser
from straight.plugin import load
from ircbot import IRCBot

if __name__ == '__main__':
    from modules.module import Module
    
    config = ConfigParser.ConfigParser()
    config.readfp(open('config.ini'))
    
    bot = IRCBot()
    bot.set_config(config)
    
    plugins = [plugin_class() for plugin_class in load("modules", Module)]
    for plugin in plugins:
        bot.load_module(plugin)
    bot.end_load_modules()
    
    bot.connect(config.get('core', 'server'), int(config.get('core', 'port')))
Exemplo n.º 54
0
def main():
    args = docopt(__doc__)
    configure_debug(args["--debug"])
    secret_url = "http://krebsco.de/secret"  # return 1337
    profile = environ.get("CONNECTION_FILENAME", None)
    timeout = float(args['--timeout'])
    wait = float(args['--wait'])
    # plugins implement:
    #  match_connection: check connection profile is a possible hotspot (optional)
    #  match: check if the initial request is possibly the hotspot of the  plugin
    # accept: click the "accept AGB" button of the hotspot
    plugins = load("prisonbreak.plugins")

    if args['--force-run']:
        log.info("CONNECTION_FILENAME environment is not set"
                  "and --force-run is set, assuming unconditional run")
    elif args['STATUS'] == 'down':
        log.info('device went down, doing nothing')
        exit(0)
    elif not profile:
        log.info("CONNECTION_FILENAME environment is not set"
                  ", assuming run as condition-change and doing nothing")
        exit(0)
    else:
        log.info("CONNECTION_FILENAME set"
                 ", checking if any plugin matches connection pattern")
        matched = False
        config = configparser.ConfigParser()
        config.read(profile)
        for plug in plugins:
            if "match_connection" in dir(plug):
                log.debug(f"running match() provided by {plug}")
                if plug.match_connection(config):
                    matched = True
            else:
                log.debug(f"{plug} does not provide matching function")
        if matched:
            log.info("at least one plugin matched Connection"
                     " for being a possible AGB prison")
        else:
            log.info("no plugin matched connection profile"
                     ", exiting")
            exit(0)

    s = requests.Session()
    s.headers.update(
        {
            "User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:65.0)"
                          "Gecko/20100101 Firefox/65.0"
        }
    )
    if wait:
        log.info(f"Waiting for {wait} seconds before trying to connect")
        sleep(wait)

    initial_response = s.get(secret_url,timeout=timeout)

    if initial_response.text.startswith("1337"):
        log.info("Received the correct challenge token"
                 ", assuming no captive portal")
        if args['--force-token']:
            log.info("Continuing even though we got the correct token!")
        else:
            exit(0)

    for plug in plugins:
        name = plug.__name__
        log.info(f"Running Plugin {name}")
        matched = plug.match(initial_response)
        if args['--force-match']:
            log.info("Force-match set, skipping plugin match."
                     f"Response would be {matched}")
        elif not matched:
            log.info(f"{name} cannot log into hotspot")
            continue
        if plug.accept(initial_response, s):
            log.info(f"{name} successful?")
            if s.get(secret_url,timeout=timeout).text.startswith("1337"):
                log.info(f"{name} successful!")
                exit(0)
            else:
                log.warn(f"{name} failed to break free, continuing")

        else:
            log.info(f"{name} returned False, continuing")

    log.error("No plug was able to establish a connection")
Exemplo n.º 55
0
def get_plugin_names():
    ''' Return the list of plugins names. '''
    plugins = load('progit.hooks', subclasses=BaseHook)
    output = [plugin.name for plugin in plugins]
    return output
Exemplo n.º 56
0
import argparse
import logging
import json
import sys
import threading
import csv

from straight.plugin import load

from pathspider.base import PluggableSpider
from pathspider.base import SHUTDOWN_SENTINEL
from pathspider.network import interface_up

plugins = load("pathspider.plugins", subclasses=PluggableSpider)


def job_feeder_ndjson(inputfile, spider):
    logger = logging.getLogger("feeder")
    seen_targets = set()
    with open(inputfile) as fh:
        logger.debug("job_feeder: started")
        for line in fh:
            try:
                job = json.loads(line)
                if 'dip' in job.keys():
                    if job['dip'] in seen_targets:
                        logger.debug(
                            "This target has already had a job submitted, skipping."
                        )
                        continue
                    seen_targets.add(job['dip'])
Exemplo n.º 57
0
def main():
    args = docopt(__doc__)
    secret_url = "http://krebsco.de/secret"  # return 1337
    profile = environ.get("CONNECTION_FILENAME", None)
    timeout = float(args['--timeout'])
    tries = int(args['--retry'])
    notify = not args['--no-notify']
    timeout_wait = float(args['--timeout-wait'])
    wait = float(args['--wait'])
    debug = args["--debug"]


    configure_debug(debug)
    # plugins implement:
    #  match_connection: check connection profile is a possible hotspot (optional)
    #  match: check if the initial request is possibly the hotspot of the  plugin
    # accept: click the "accept AGB" button of the hotspot
    plugins = load("prisonbreak.plugins")

    if notify:
        log.info("Initializing notify")
        try:
            notify2.init('prison-break')
        except Exception as e:
            log.error("Error while initializing notify")
            log.error(e)

            log.info("For notifications to work, the DISPLAY and DBUS_SESSION_BUS_ADDRESS environment Variables must be set correctly (the logged in user). This is how they are currently set up :")
            log.info(f"DISPLAY={os.environ.get('DISPLAY')}")
            log.info(f"DBUS_SESSION_BUS_ADDRESS={os.environ.get('DBUS_SESSION_BUS_ADDRESS')}")
            notify=False
    note = functools.partial(send_notify,do_notify=notify)


    if args['--force-run']:
        log.info("CONNECTION_FILENAME environment is not set"
                  "and --force-run is set, assuming unconditional run")
    elif args['STATUS'] == 'down':
        log.info('device went down, doing nothing')
        exit(0)
    elif not profile:
        log.info("CONNECTION_FILENAME environment is not set"
                  ", assuming run as condition-change and doing nothing. Force with --force-run")
        exit(0)
    else:
        log.info("CONNECTION_FILENAME set"
                 ", checking if any plugin matches connection pattern")
        matched = False
        config = configparser.ConfigParser()
        config.read(profile)
        for plug in plugins:
            if "match_connection" in dir(plug):
                log.debug(f"running match() provided by {plug}")
                if plug.match_connection(config):
                    matched = True
            else:
                log.debug(f"{plug} does not provide matching function")
        if matched:
            log.info("at least one plugin matched Connection"
                     " for being a possible AGB prison")
        else:
            log.info("no plugin matched connection profile"
                     ", exiting")
            exit(0)

    s = requests.Session()
    s.headers.update(
        {
            "User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:65.0)"
                          "Gecko/20100101 Firefox/65.0"
        }
    )
    if wait:
        log.info(f"Waiting for {wait} seconds before trying to connect")
        sleep(wait)

    for n in range(tries):
        try:
            initial_response = s.get(secret_url,timeout=timeout)
        except Timeout as t:
            log.info(f"Timeout number {n+1}, waiting {timeout_wait} seconds")
            continue
        except requests.exceptions.ConnectionError as t:
            log.info(f"Connection Error {n+1}, waiting {timeout_wait} seconds")
        else:
            log.debug(f"Success in try {n+1}")
            break
        sleep(timeout_wait)
    else:
        log.error(f'Unable to Retrieve the initial response after {tries} tires')
        exit(1)


    if initial_response.text.startswith("1337"):
        log.info("Received the correct challenge token"
                 ", assuming no captive portal")
        if args['--force-token']:
            log.info("Continuing even though we got the correct token!")
        else:
            exit(0)

    note("trying to connect with the available prison-break plugins",title="Prison-Break detected captive Portal!")
    for plug in plugins:
        name = plug.__name__
        sname = name.split(".")[-1]
        log.info(f"Running Plugin {name}")
        matched = plug.match(initial_response)
        if args['--force-match']:
            log.info("Force-match set, skipping plugin match."
                     f"Response would be {matched}")
        elif not matched:
            log.info(f"{name} cannot log into hotspot")
            continue
        note("Trying to accept AGBs for you now!",title=f"Prison-Break Plugin {name}")
        #notify2.Notification("Summary", "Some body text", "notification-message-im").show()
        if plug.accept(initial_response, s):
            log.info(f"{name} successful?")
            if s.get(secret_url,timeout=timeout).text.startswith("1337"):
                #notify2.Notification("Prison-Break", "Plugin {name} successful", "notification-message-im").show()

                log.info(f"{name} successful!")
                note("Managed to click you through the AGB captive portal.\nYou are now logged in!",title=f"Prison-Break Plugin {name}",timeout=20,critical=True)
                exit(0)
            else:
                #notify2.Notification("Prison-Break", "Plugin {name} tried to accept AGB but failed", "notification-message-im").show()
                log.warn(f"{name} failed to break free, continuing")
                note("Failed to log in, trying next plugin",title=f"Prison-Break Plugin {name}")

        else:
            log.info(f"{name} returned False, continuing")

    log.error("No plug was able to establish a connection")
    note("No Plugin was able to log through the captive portal, you will probably have to do it by hand, sorry!",title="Prison-Break failed",critical=True)
Exemplo n.º 58
0
 def get_plugins(self):
     ''' Return the list of plugins.'''
     return load(self._namespace, subclasses=self._base_class)
Exemplo n.º 59
0
def get_plugin(plugin_name):
    ''' Return the plugin corresponding to the given plugin name. '''
    plugins = load('anitya.lib.backends', subclasses=BaseBackend)
    for plugin in plugins:
        if plugin.name.lower() == plugin_name.lower():
            return plugin