예제 #1
0
def register_namespace(namespace_obj):
    """
    Wraps up defining a namespace, as well as revealing the actual controller
    object (as it is passed as a string).
    
    Require Arguments:
    
        namespace_obj
            Namespace object that is fully established (and ready to be 
            added to the global namespaces dictionary)
            
    Usage:
    
    .. code-block:: python
    
        from cement.core.namespace import CementNamespace, register_namespace

        example = CementNamespace('example', controller='ExampleController')
        example.config['foo'] = 'bar'
        example.options.add_option('-F', '--foo', action='store',
            dest='foo', default=None, help='Example Foo Option')
        register_namespace(example)
        
    """
    define_namespace(namespace_obj.label, namespace_obj)

    # Reveal the controller object.
    base = namespace_obj.provider

    mymod = __import__('%s.controllers.%s' % (base, namespace_obj.label),
                       globals(), locals(), [namespace_obj.controller])
    cont = getattr(mymod, namespace_obj.controller)
    namespaces[namespace_obj.label].controller = cont
    for _file in namespaces['root'].config['config_files']:
        set_config_opts_per_file(namespace_obj.label, namespace_obj.label,
                                 _file)
예제 #2
0
파일: namespace.py 프로젝트: derks/cement
def register_namespace(namespace_obj):
    """
    Wraps up defining a namespace, as well as revealing the actual controller
    object (as it is passed as a string).
    
    Require Arguments:
    
        namespace_obj
            Namespace object that is fully established (and ready to be 
            added to the global namespaces dictionary)
            
    Usage:
    
    .. code-block:: python
    
        from cement.core.namespace import CementNamespace, register_namespace

        example = CementNamespace('example', controller='ExampleController')
        example.config['foo'] = 'bar'
        example.options.add_option('-F', '--foo', action='store',
            dest='foo', default=None, help='Example Foo Option')
        register_namespace(example)
        
    """
    define_namespace(namespace_obj.label, namespace_obj)
    
    # Reveal the controller object.
    base = namespace_obj.provider
    
    mymod = __import__('%s.controllers.%s' % (base, namespace_obj.label), 
                       globals(), locals(), [namespace_obj.controller])
    cont = getattr(mymod, namespace_obj.controller)                  
    namespaces[namespace_obj.label].controller = cont
    for _file in namespaces['root'].config['config_files']:
        set_config_opts_per_file(namespace_obj.label, namespace_obj.label, 
                                 _file)
예제 #3
0
                                   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)


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()
예제 #4
0
파일: plugin.py 프로젝트: derks/cement
        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)
    
                           
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()
예제 #5
0
        label='root',
        version=version,
        config=get_default_config(),
        banner=banner,
        provider=config['app_module']
        )
    define_namespace('root', namespace)
    namespaces['root'].config.update(config)
    
    root_mod = __import__("%s.controllers.root" % \
                          namespaces['root'].config['app_module'], 
                          globals(), locals(), ['root'])
    namespaces['root'].controller = getattr(root_mod, 'RootController')
        
    for config_file in namespaces['root'].config['config_files']:
        set_config_opts_per_file('root', 'root', config_file)

    validate_config(namespaces['root'].config)
    
    # hardcoded hacks
    if '--quiet' in sys.argv:
        namespaces['root'].config['log_to_console'] = False
        sys.stdout = buf_stdout
        sys.stderr = buf_stderr
    if '--json' in sys.argv:
        sys.stdout = buf_stdout
        sys.stderr = buf_stderr
        namespaces['root'].config['output_handler_override'] = 'json'
        namespaces['root'].config['show_plugin_load'] = False
    # debug trumps everything
    if '--debug' in sys.argv: