Example #1
0
def main():
    """
    This is a simple mainline that runs all worker processes
    configured in the context yaml file given.
    """

    from melkman.context import Context

    if len(sys.argv) < 3:
        print_usage()
        sys.exit(0)
        
    command_name = sys.argv[1]
    yaml_file = sys.argv[-1]

    import logging
    log = logging.getLogger(__name__)
    logging.basicConfig(level=logging.INFO)
    context = Context.from_yaml(yaml_file)


    all_commands = AvailableCommands(context.component_manager)
    command = all_commands.lookup(command_name)
    
    if command is None:
        print_usage('unknown command: %s' % command_name)
        sys.exit(0)

    def user_trap(*args, **kw):
        cmd = all_commands.lookup('shell')(context, [])
    signal.signal(signal.SIGUSR1, user_trap)


    return command(context, sys.argv[2:-1])
Example #2
0
def test_context_bootstrap_plugins():
    from giblets import Component, implements
    from melkman.context import Context, IRunDuringBootstrap


    class FooComponent(Component):
        implements(IRunDuringBootstrap)

        did_bootstrap = 0
        
        def bootstrap(self, context, purge=False):
            FooComponent.did_bootstrap += 1

    config = {
        'plugins': [{'pattern': "test_context.FooComponent", "enabled": True}]
    }
    ctx = Context.from_dict(config, defaults=Context.from_yaml(test_yaml_file()).config)
    with ctx:
        ctx.bootstrap(purge=False)    
        assert FooComponent.did_bootstrap == 1
Example #3
0
def test_context_components():

    from giblets import Component, implements, ExtensionInterface, ExtensionPoint
    from melkman.context import Context, IContextConfigurable

    class IBaz(ExtensionInterface):
        pass

    class FooComponent(Component):
        implements(IContextConfigurable, IBaz)

        def set_context(self, context):
            self.context = context
            
    class BarComponent(Component):
        implements(IContextConfigurable, IBaz)

        def set_context(self, context):
            self.context = context

    class BazHolder(Component):
        bazoo = ExtensionPoint(IBaz)



    config = """
        {
        "plugins": [
            {"pattern": "test_context.FooComponent", "enabled": true},
            {"pattern": "test_context.BarComponent", "enabled": false},
            {"pattern": "test_context.BazHolder", "enabled": true}]
        }
    """
    
    ctx = Context.from_json(config)
    with ctx:
        bazer = BazHolder(ctx.component_manager)
    
        # check that only the enabled components came through
        assert len(bazer.bazoo) == 1
        assert isinstance(bazer.bazoo[0], FooComponent)

        # check that the component was configured with the context
        assert bazer.bazoo[0].context == ctx
Example #4
0
def fresh_context():
    ctx = Context.from_yaml(test_yaml_file())
    ctx.bootstrap(purge=True)
    return ctx
Example #5
0
from pylons import config
from melkman.context import Context

context = Context.from_yaml(config['melkman.yamlconfig'])