Exemple #1
0
    def content(self):
        injectors = querySubscriptions(self, IContainerInjector)
        for injector in injectors:
            interface_filter = getattr(injector, '__interfaces__', [])
            if interface_filter and not any(
                    map(lambda i: i.providedBy(self), interface_filter)):
                continue

            for k, v in injector.inject().items():
                if k not in self._items:
                    v.__parent__ = self
                    self._items[k] = v

        items = dict(**self._items)

        extenders = querySubscriptions(self, IContainerExtender)
        for extender in extenders:
            interface_filter = getattr(extender, '__interfaces__', [])
            if interface_filter and not any(
                    map(lambda i: i.providedBy(self), interface_filter)):
                continue

            children = extender.extend()
            for v in children.values():
                v.__parent__ = self
                v.__transient__ = True
                v.inherit_permissions = True
            items.update(children)

        return items
    def content(self):
        injectors = querySubscriptions(self, IContainerInjector)
        for injector in injectors:
            interface_filter = getattr(injector, '__interfaces__', [])
            if interface_filter and not any(map(lambda i: i.providedBy(self), interface_filter)):
                continue

            for k, v in injector.inject().items():
                if k not in self._items:
                    v.__parent__ = self
                    self._items[k] = v

        items = dict(**self._items)

        extenders = querySubscriptions(self, IContainerExtender)
        for extender in extenders:
            interface_filter = getattr(extender, '__interfaces__', [])
            if interface_filter and not any(map(lambda i: i.providedBy(self), interface_filter)):
                continue

            children = extender.extend()
            for v in children.values():
                v.__parent__ = self
                v.__transient__ = True
                v.inherit_permissions = True
            items.update(children)

        return items
Exemple #3
0
    def update(self, config_filenames=NO_DEFAULT):
        if config_filenames is self.NO_DEFAULT:
            conf_requirements = [
                i for i in querySubscriptions(object(),
                                              IRequiredConfigurationFiles)
                if type(i) not in _loaded_config_requirements
            ]

            config_filenames = []
            for i in [i.config_file_names() for i in conf_requirements]:
                config_filenames.extend(i)

            for i in conf_requirements:
                _loaded_config_requirements.append(type(i))

            # user override must be last
            config_filenames.append('~/.opennode-oms.conf')

        # XXX: it would be nice to be able to print out these via some cmdline switch to omsd
        # print "Reading config files", ', '.join(config_filenames)
        self.read([os.path.expanduser(i) for i in config_filenames])

        with closing(StringIO()) as s:
            _cmdline_override.write(s)
            self.readfp(StringIO(s.getvalue()))
def complete(protocol, buf, pos, **kwargs):
    """Bash like dummy completion, not great like zsh completion.
    Problems: completion in the middle of a word will screw it (like bash)
    """

    line = ''.join(buf)
    lead, rest = line[0:pos], line[pos:]

    tokens = lead.lstrip().split(' ')

    partial = tokens[-1]  # word to be completed

    context, tokenized_args = yield protocol.parse_line(lead.rstrip(partial).lstrip())

    parser = yield context.contextual_arg_parser(tokenized_args, partial=True)
    parsed_args = yield parser.parse_args(tokenized_args)

    # TODO: This isn't enough. We need a relaxed tokenizer.
    # Ignore leading quote when searching for completions.
    if partial.startswith('"'):
        partial = partial[1:]

    completers = querySubscriptions(context, ICompleter)

    all_completions = []
    for completer in completers:
        completions = yield completer.complete(partial, parsed_args, parser, protocol=protocol, **kwargs)
        if completions:
            all_completions.extend(completions)

    defer.returnValue((partial, rest, all_completions))
Exemple #5
0
def get_config():
    global _config
    if not _config:
        # ensure that our config file subscription adapter has been grokked
        # this is tricky because we need a configuration object at the very
        # beginning of the startup sequence
        if not querySubscriptions(object(), IRequiredConfigurationFiles):
            grok('opennode.oms.config')

        _config = OmsConfig()
    return _config
def get_config():
    global _config
    if not _config:
        # ensure that our config file subscription adapter has been grokked
        # this is tricky because we need a configuration object at the very
        # beginning of the startup sequence
        if not querySubscriptions(object(), IRequiredConfigurationFiles):
            grok('opennode.oms.config')

        _config = OmsConfig()
    return _config
    def update(self, config_filenames=NO_DEFAULT):
        if config_filenames is self.NO_DEFAULT:
            conf_requirements = [i for i in querySubscriptions(object(), IRequiredConfigurationFiles)
                                 if type(i) not in _loaded_config_requirements]

            config_filenames = []
            for i in [i.config_file_names() for i in conf_requirements]:
                config_filenames.extend(i)

            for i in conf_requirements:
                _loaded_config_requirements.append(type(i))

            # user override must be last
            config_filenames.append('~/.opennode-oms.conf')

        # XXX: it would be nice to be able to print out these via some cmdline switch to omsd
        # print "Reading config files", ', '.join(config_filenames)
        self.read([os.path.expanduser(i) for i in config_filenames])

        with closing(StringIO()) as s:
            _cmdline_override.write(s)
            self.readfp(StringIO(s.getvalue()))
Exemple #8
0
def context_from_method(fun, args, kwargs):
    """Currently works only for methods by assuming that the first
    argument is `self`. Unfortunately we cannot know the dynamic binding
    for the method because the @transact decorator is invoked at class
    definition time.

    If `self` is already a persistent object with a context attached, then that context
    is returned, otherwise it searches for matching IContextExtractor subscription adpaters.

    """

    that = args[0] if args else None

    context = get_peristent_context(that)

    if that:
        extractors = querySubscriptions(that, IContextExtractor)
        if extractors:
            for i in extractors:
                context.update(i.get_context())

    return context
Exemple #9
0
def complete(protocol, buf, pos, **kwargs):
    """Bash like dummy completion, not great like zsh completion.
    Problems: completion in the middle of a word will screw it (like bash)
    """

    line = ''.join(buf)
    lead, rest = line[0:pos], line[pos:]

    tokens = lead.lstrip().split(' ')

    partial = tokens[-1]  # word to be completed

    context, tokenized_args = yield protocol.parse_line(
        lead.rstrip(partial).lstrip())

    parser = yield context.contextual_arg_parser(tokenized_args, partial=True)
    parsed_args = yield parser.parse_args(tokenized_args)

    # TODO: This isn't enough. We need a relaxed tokenizer.
    # Ignore leading quote when searching for completions.
    if partial.startswith('"'):
        partial = partial[1:]

    completers = querySubscriptions(context, ICompleter)

    all_completions = []
    for completer in completers:
        completions = yield completer.complete(partial,
                                               parsed_args,
                                               parser,
                                               protocol=protocol,
                                               **kwargs)
        if completions:
            all_completions.extend(completions)

    defer.returnValue((partial, rest, all_completions))
Exemple #10
0
 def content(self):
     actions = querySubscriptions(self.__parent__, ICommand)
     return dict((action._name, Command(action._name, self, action.cmd)) for action in actions
                 if any(i.providedBy(action) for i in getattr(action, '__interfaces__', [])) or
                 not getattr(action, '__interfaces__', []))
Exemple #11
0
 def start_daemons(self):
     for i in querySubscriptions(self, IProcess):
         log.msg('Starting %s' % i, system='proc')
         self.spawn(i)
Exemple #12
0
 def lookup(self, obj):
     """We use IConsumer registered in the global registry as
     subscription adapters.
     """
     return querySubscriptions(obj, IConsumer)
Exemple #13
0
 def start_daemons(self):
     for i in querySubscriptions(self, IProcess):
         log.msg('Starting %s' % i, system='proc')
         self.spawn(i)