Exemple #1
0
    def load_files(self, files, filename_as_namespace=False):
        """
        load files which contains yaml configuration entries.and merge it by current ConfigManager instance

        :param files: files to load and merge into existing configuration instance
        :type files: list

        :param filename_as_namespace: when loading files, use the filename as a namespace. default: false.
        :type filename_as_namespace: bool

        """
        files = [f.strip() for f in files.split(';')] if isinstance(files, basestring) else files
        for f in files:
            if not os.path.exists(f):
                if self.missing_file_behavior == ERROR:
                    raise ConfigFileNotFoundError(f)
                elif self.missing_file_behavior == WARNING:
                    warnings.warn('File not found: %s' % f)
                continue

            if filename_as_namespace:
                assert f.endswith(
                    self.default_extension), 'Invalid configuration filename.expected: ns1.ns2.*%s' % self.default_extension
                namespace = os.path.splitext(os.path.split(f)[1])[0]
                if namespace == self.root_file_name:
                    node = self
                else:
                    node = self._ensure_namespaces(*namespace.split('.'))
            else:
                node = self

            loaded_yaml = load_yaml(f, self.context, encoding=self.encoding)
            if loaded_yaml:
                node.merge(loaded_yaml)
Exemple #2
0
    def load_files(self, files, filename_as_namespace=False):
        """
        load files which contains yaml configuration entries.and merge it by current ConfigManager instance

        :param files: files to load and merge into existing configuration instance
        :type files: list

        :param filename_as_namespace: when loading files, use the filename as a namespace. default: false.
        :type filename_as_namespace: bool

        """
        files = [f.strip() for f in files.split(';')] if isinstance(
            files, basestring) else files
        for f in files:
            if not os.path.exists(f):
                if self.missing_file_behavior == ERROR:
                    raise ConfigFileNotFoundError(f)
                elif self.missing_file_behavior == WARNING:
                    warnings.warn('File not found: %s' % f)
                continue

            if filename_as_namespace:
                assert f.endswith(self.default_extension), \
                    'Invalid configuration filename.expected: ns1.ns2.*%s' % self.default_extension
                namespace = os.path.splitext(os.path.split(f)[1])[0]
                if namespace == self.root_file_name:
                    node = self
                else:
                    node = self._ensure_namespaces(*namespace.split('.'))
            else:
                node = self

            loaded_yaml = load_yaml(f, self.context, encoding=self.encoding)
            if loaded_yaml:
                node.merge(loaded_yaml)
Exemple #3
0
 def _load_files(self, files, filename_as_namespace=False):
     """
     load files which contains yaml config entries.and merge it by current ConfigManager instance
     """
     for f in files:
         if not os.path.exists(f):
             continue
         if filename_as_namespace:
             assert f.endswith('.conf'), 'Invalid config filename.expected: ns1.ns2.*.conf'
             namespace = os.path.splitext(os.path.split(f)[1])[0]
             if namespace == 'root':
                 node = self
             else:
                 node = self._ensure_namespaces(*namespace.split('.'))
         else:
             node = self
         node.merge(load_yaml(f))
Exemple #4
0
 def load_files(self, files, filename_as_namespace=False):
     """
     load files which contains yaml config entries.and merge it by current ConfigManager instance
     """
     for f in files:
         if not os.path.exists(f):
             continue
         if filename_as_namespace:
             assert f.endswith(self.default_extension), (
                 "Invalid config filename.expected: ns1.ns2.*%s" % self.default_extension
             )
             namespace = os.path.splitext(os.path.split(f)[1])[0]
             if namespace == self.root_file_name:
                 node = self
             else:
                 node = self._ensure_namespaces(*namespace.split("."))
         else:
             node = self
         node.merge(load_yaml(f))
Exemple #5
0
 def _load_files(self, files, filename_as_namespace=False):
     """
     load files which contains yaml config entries.and merge it by current ConfigManager instance
     """
     for f in files:
         if not os.path.exists(f):
             continue
         if filename_as_namespace:
             assert f.endswith(
                 '.conf'
             ), 'Invalid config filename.expected: ns1.ns2.*.conf'
             namespace = os.path.splitext(os.path.split(f)[1])[0]
             if namespace == 'root':
                 node = self
             else:
                 node = self._ensure_namespaces(*namespace.split('.'))
         else:
             node = self
         node.merge(load_yaml(f))
         self.__filenames.append(f)