示例#1
0
    def run(self, names, services_service, application_service=None):
        names = [name.split('/') for name in (names or [])]

        def extract_infos(spec, ancestors=()):
            infos = {}

            for f, args in spec:
                name, config_spec, children = f(*args)
                fullname = ancestors + (name, )

                if self.match_service(names, fullname):
                    infos[name] = config_spec

                info = extract_infos(children, fullname)
                if info:
                    infos[name] = dict(config_spec, **info)

            return infos

        spec = extract_infos(
            services_service.walk1('services', 'nagare.services', self.config
                                   or {}))
        if not spec:
            print('<empty>')
            return 1

        print('Configuration specification')
        print('---------------------------')

        spec = config_from_dict(spec)
        spec.display(4,
                     filter_parameter=lambda param:
                     (param == '___many___') or (not param.startswith('_')))

        return 0
示例#2
0
    def create(self):
        config = self.plugin_config.pop('_initial_config')
        global_config = config.pop('_global_config', {})
        config = {self.SELECTOR: self.selector, self.name: config}

        super(Application, self).load_plugins(self.name,
                                              config_from_dict(config),
                                              global_config, True)

        return self.service
    def _create_services(self, config, config_filename):
        mandatory_config = {
            'application': {
                'name': 'cli'
            },
            'publisher': {
                'type': 'cli'
            },
            'reloader': {
                'activated': 'off'
            }
        }
        config.merge(config_from_dict(mandatory_config))

        return super(App, self)._create_services(config, config_filename)
示例#4
0
    def _run(self, command_names, next_method=None, config_filename=None, **arguments):
        if self.WITH_CONFIG_FILENAME:
            has_user_data_file, user_data_file = self.get_user_data_file()

            config = config_from_file(user_data_file) if has_user_data_file else config_from_dict({})
            config.merge(config_from_file(config_filename))
        else:
            config = None

        services = self._create_services(config, config_filename)

        publisher = services.get('publisher')
        if self.WITH_STARTED_SERVICES and publisher:
            services(publisher.create_app)

        return services((next_method or self.run), **arguments)
示例#5
0
    def run(self, names, not_modified, modified, application_service,
            services_service):
        names = [name.split('/') for name in (names or [])]

        if modified:

            def extract_infos(config, ancestors=()):
                infos = {}

                for k, v in config.items():
                    fullname = ancestors + (k, )

                    if self.match_service(names, fullname):
                        infos[k] = v

                    if isinstance(v, dict):
                        info = extract_infos(v, fullname)
                        if info:
                            infos[k] = info

                return infos

            config = extract_infos(self.raw_config)
        else:

            def extract_infos(config, ancestors=()):
                infos = {}

                for f, (entry, name, cls, plugin, children) in config:
                    if plugin is None:
                        continue

                    children = list(children)
                    children_names = set(child[1][1] for child in children)
                    fullname = ancestors + (name, )

                    if (plugin is not None) and self.match_service(
                            names, fullname):
                        infos[name] = {
                            children_name: config
                            for children_name, config in
                            plugin.plugin_config.items()
                            if children_name not in children_names
                        }

                    info = extract_infos(children, fullname)
                    if info:
                        config = {
                            children_name: config
                            for children_name, config in
                            plugin.plugin_config.items()
                            if children_name not in children_names
                        }
                        infos[name] = dict(config, **info)

                return infos

            config = extract_infos(
                services_service.walk2('services',
                                       services_service.ENTRY_POINTS))
            if not_modified:
                config = self.compare(self.raw_config, config)

        if not config:
            print('<empty>')
            return 1

        print('Configuration')
        print('-------------')

        config_from_dict(config).display(4,
                                         filter_parameter=lambda param:
                                         (param == '___many___') or
                                         (not param.startswith('_')))

        return 0