Пример #1
0
def load_all_plugins():
    """
    Attempt to load all enabled plugins.  Passes the existing config and 
    options object to each plugin and allows them to add/update each.
    
    """
    for res in run_hooks('pre_plugins_hook'):
        pass  # No result expected

    namespaces['root'].config['enabled_plugins'] = get_enabled_plugins()

    for plugin in namespaces['root'].config['enabled_plugins']:
        load_plugin(plugin)

    for (namespace, res) in run_hooks('options_hook'):
        for opt in res._get_all_options():
            if opt.get_opt_string() == '--help':
                pass
            else:
                if namespaces.has_key(namespace):
                    namespaces[namespace].options.add_option(opt)
                else:
                    log.warning("namespace '%s' doesn't exist!" % namespace)

    for res in run_hooks('post_plugins_hook'):
        pass  # No result expected
Пример #2
0
def load_all_plugins():
    """
    Attempt to load all enabled plugins.  Passes the existing config and 
    options object to each plugin and allows them to add/update each.
    
    """
    for res in run_hooks('pre_plugins_hook'):
        pass # No result expected
       
    namespaces['root'].config['enabled_plugins'] = get_enabled_plugins()

    for plugin in namespaces['root'].config['enabled_plugins']:
        load_plugin(plugin)
        
    for (namespace, res) in run_hooks('options_hook'):
        for opt in res._get_all_options(): 
            if opt.get_opt_string() == '--help':
                pass
            else:
                if namespaces.has_key(namespace):
                    namespaces[namespace].options.add_option(opt)
                else:
                    log.warning("namespace '%s' doesn't exist!" % namespace)
    
    for res in run_hooks('post_plugins_hook'):
        pass # No result expected
Пример #3
0
def get_config(namespace='root'):
    """
    Get a namespace's config.  Returns a ConfigObj object.
    
    Optional Arguments:
    
        namespace
            The namespace to pull the config object from.  Default: 'root'.
    
    """
    if namespaces.has_key(namespace):
        return namespaces[namespace].config
    else:
        raise CementRuntimeError, "the namespace '%s' doesn't exist" % \
            namespace
Пример #4
0
def get_namespace(namespace):
    """
    Return the namespace object whose label is 'namespace'.
    
    Required Arguments:
    
        namespace
            The label of the namespace object to return
    
    """
    if namespaces.has_key(namespace):
        return namespaces[namespace]
    else:
        raise CementRuntimeError, "the namespace '%s' doesn't exist" % \
            namespace
Пример #5
0
def get_config(namespace='root'):
    """
    Get a namespace's config.  Returns a ConfigObj object.
    
    Optional Arguments:
    
        namespace
            The namespace to pull the config object from.  Default: 'root'.
    
    """    
    if namespaces.has_key(namespace):
        return namespaces[namespace].config
    else:
        raise CementRuntimeError, "the namespace '%s' doesn't exist" % \
            namespace
Пример #6
0
def get_namespace(namespace):
    """
    Return the namespace object whose label is 'namespace'.
    
    Required Arguments:
    
        namespace
            The label of the namespace object to return
    
    """
    if namespaces.has_key(namespace):
        return namespaces[namespace]
    else:
        raise CementRuntimeError, "the namespace '%s' doesn't exist" % \
            namespace
Пример #7
0
def define_namespace(namespace, namespace_obj):
    """
    Define a namespace for commands, options, configuration, etc.  
    
    Required Arguments:
    
        namespace
            Label of the namespace
        namespace_obj
            CementNamespace object.  Stored in global 'namespaces' dict as 
            namespaces['namespace']
                     
    """
    if namespaces.has_key(namespace):
        raise CementRuntimeError, \
            "Namespace '%s' already defined!" % namespace
    elif re.search('-', namespace):
        raise CementRuntimeError, \
            "Namespaces can not have '-', use '_' instead."

    namespaces[namespace] = namespace_obj
    log.debug("namespace '%s' initialized" % namespace)
Пример #8
0
def define_namespace(namespace, namespace_obj):
    """
    Define a namespace for commands, options, configuration, etc.  
    
    Required Arguments:
    
        namespace
            Label of the namespace
        namespace_obj
            CementNamespace object.  Stored in global 'namespaces' dict as 
            namespaces['namespace']
                     
    """
    if namespaces.has_key(namespace):
        raise CementRuntimeError, \
            "Namespace '%s' already defined!" % namespace
    elif re.search('-', namespace):
        raise CementRuntimeError, \
            "Namespaces can not have '-', use '_' instead."
        
    namespaces[namespace] = namespace_obj
    log.debug("namespace '%s' initialized" % namespace)
Пример #9
0
    log.debug("loading plugin '%s'" % plugin)
    if config.has_key('show_plugin_load') and config['show_plugin_load']:
        print 'loading %s plugin' % plugin

    try:
        __import__(provider)
    except ImportError, error:
        raise CementConfigError, 'unable to load plugin provider: %s' % error

    loaded = False
    try:
        plugin_module = __import__('%s.bootstrap' % provider, globals(),
                                   locals(), [plugin])
        getattr(plugin_module, plugin)
        if namespaces.has_key(plugin):
            loaded = True
            log.debug("loaded '%s' plugin" % plugin)
    except AttributeError, error:
        log.debug('AttributeError => %s' % error)

    if not loaded:
        raise CementRuntimeError, \
            "Plugin '%s' is not installed or is broken. Try --debug?" % plugin

    plugin_config_file = os.path.join(
        namespaces['root'].config['plugin_config_dir'], '%s.conf' % plugin)

    set_config_opts_per_file(plugin, plugin, plugin_config_file)
    for _file in namespaces['root'].config['config_files']:
        set_config_opts_per_file(plugin, plugin, _file)
Пример #10
0
    
    log.debug("loading plugin '%s'" % plugin)
    if config.has_key('show_plugin_load') and config['show_plugin_load']:
        print 'loading %s plugin' % plugin
    
    try: 
        __import__(provider)
    except ImportError, error:
        raise CementConfigError, 'unable to load plugin provider: %s' % error
        
    loaded = False
    try:
        plugin_module = __import__('%s.bootstrap' % provider, 
            globals(), locals(), [plugin])
        getattr(plugin_module, plugin)
        if namespaces.has_key(plugin):
            loaded = True
            log.debug("loaded '%s' plugin" % plugin)
    except AttributeError, error:
        log.debug('AttributeError => %s' % error)
                                
    if not loaded:
        raise CementRuntimeError, \
            "Plugin '%s' is not installed or is broken. Try --debug?" % plugin
        
    plugin_config_file = os.path.join(
        namespaces['root'].config['plugin_config_dir'], '%s.conf' % plugin
        )

    set_config_opts_per_file(plugin, plugin, plugin_config_file)
    for _file in namespaces['root'].config['config_files']: