Example #1
0
def filepath_constructor(loader, node):
    path = loader.construct_python_str(node)
    fp = filepath.FilePath(util.expand_filepath(path))

    # add a marker to dump the configuration
    fp.origpath = path
    return fp
Example #2
0
def pipedpath_constructor(loader, node):
    path = loader.construct_python_str(node)
    original_path = path
    package = piped
    
    # the path may be an empty string, which should be the root piped package path.
    if path:
        paths = path.split(os.path.sep)

        for i in range(1, len(paths)+1):
            package_name = '.'.join(['piped'] + paths[:i])

            try:
                any = reflect.namedAny(package_name)
            except (AttributeError, reflect.ObjectNotFound) as e:
                # AttributeErrors may occur if we look a file that has the
                # same prefix as an existing module or package
                break

            # we don't want to start looking into modules:
            if not is_package(any):
                break
            package = any

            # update the remaining path
            path = os.path.sep.join(paths[i:])

    root = filepath.FilePath(package.__file__).parent()
    fp = root.preauthChild(util.expand_filepath(path))

    # add markers for dumping the configuration
    fp.origpath = original_path
    fp.pipedpath = True
    return fp
Example #3
0
    def __init__(
        self,
        path,
        defaultType="text/html",
        ignoredExts=(),
        registry=None,
        allowExt=0,
        namespace=None,
        preprocessors=None,
        **kwargs
    ):
        static.File.__init__(
            self,
            util.expand_filepath(path),
            defaultType=defaultType,
            ignoredExts=ignoredExts,
            registry=registry,
            allowExt=allowExt,
            **kwargs
        )

        self.namespace = dict(self=self)
        self.namespace.update(namespace or dict())
        self.preprocessor_definitions = preprocessors or dict()

        self.preprocessors = list()
        for lambda_definition in self.preprocessor_definitions.values():
            func = util.create_lambda_function(lambda_definition, **self.namespace)
            self.preprocessors.append(func)
Example #4
0
    def load_from_file(self, filename):
        """ Load the configuration by parsing the data in the given file.

        For an overview of how configuration is loaded, see :doc:`/topic/configuration`
        """
        filename = util.expand_filepath(filename)
        log.debug('Loading configuration from: %s'%filename)
        self._fail_if_configuration_file_does_not_exist(filename)

        base_config = yaml.load(open(filename))
        complete_config = self._load_config(base_config, [filename])
        self._resolve_aliases(complete_config)

        self._config = complete_config

        log.debug('Loaded configuration: '+pformat(complete_config))
Example #5
0
    def _load_includes(self, current_config, include_paths, visited_files):
        """ Recursively handles includes of other configuration-files. """
        for include_path_or_filepath in include_paths:
            include_path = util.expand_filepath(include_path_or_filepath)

            if include_path in visited_files:
                _warn_because_file_is_loaded_multiple_times(include_path, visited_files)

            visited_files.append(include_path)

            self._fail_if_configuration_file_does_not_exist(include_path)

            try:
                included_config = yaml.load(open(include_path))
                included_config = self._load_config(included_config, visited_files)
                current_config = util.merge_dicts(included_config, current_config, replace_primitives=True)
            except exceptions.ConfigurationError:
                raise
            except Exception, why:
                raise exceptions.ConfigurationError('Error in configuration file %s: %s'%(include_path, why))
Example #6
0
    def __init__(self, provider, process_name, executable, restart=False, restart_wait=1, args=None, path=None, stdout=None, stderr=None, stdin=None):
        self.process_name = process_name
        self.executable = executable
        self.restart = restart
        self.restart_wait = restart_wait
        self.args = args or list()

        self.path = None
        if path:
            self.path = util.expand_filepath(path)

        stdout_config = stdout or dict()
        stdout_protocol_name = stdout_config.pop('protocol', self.default_output_protocol_name)

        stderr_config = stderr or dict()
        stderr_protocol_name = stderr_config.pop('protocol', self.default_output_protocol_name)

        stdin_config = stdin or dict()
        stdin_protocol_name = stdin_config.pop('protocol', self.default_input_protocol_name)

        self.stdout_protocol = IProcessOutputProtocol(reflect.namedAny(stdout_protocol_name)(self, 'stdout', **stdout_config))
        self.stderr_protocol = IProcessOutputProtocol(reflect.namedAny(stderr_protocol_name)(self, 'stderr', **stderr_config))
        self.stdin_protocol = IProcessInputProtocol(reflect.namedAny(stdin_protocol_name)(self, **stdin_config))
Example #7
0
 def _get_filepath_for_persisted_context(self, context_name):
     kind = self.persisted_contexts[context_name].get('kind', 'json')
     file = self.persisted_contexts[context_name].get('file', '%s.%s' % (context_name, kind))
     return util.ensure_filepath(util.expand_filepath(file))
Example #8
0
 def _get_concatenated_lines(self):
     buf = list()
     for fp in self.file_paths:
         file = open(util.expand_filepath(fp))
         buf.extend(file.readlines())
     return buf