Esempio n. 1
0
 def __init__(self, cwd='', allow_includes=True):
     self.cwd = cwd
     self.configs = {}
     self.is_dump = False
     self.allow_includes = allow_includes
     self.directives = {}
     self.parser = raw_parser.RawParser()
     self._init_directives()
Esempio n. 2
0
    def parse(self, file_path, root=None):
        LOG.debug("Parse file: {}".format(file_path))

        if not root:
            root = block.Root()

        try:
            parser = raw_parser.RawParser()
            parsed = parser.parse(file_path)
        except ParseException as e:
            LOG.error('Failed to parse config "{file}": {error}'.format(
                file=file_path, error=str(e)))
            return root

        if len(parsed) and parsed[0].getName() == 'file_delimiter':
            #  Were parse nginx dump
            LOG.info('Switched to parse nginx configuration dump.')
            root_filename = self._prepare_dump(parsed)
            self.is_dump = True
            self.cwd = os.path.dirname(root_filename)
            parsed = self.configs[root_filename]

        self.parse_block(parsed, root)
        return root