示例#1
0
文件: wrapper.py 项目: aioupload/dexy
    def parse_configs(self):
        """
        Look for document config files in current working tree and load them.
        Return an Abstract Syntax Tree with information about nodes to be
        processed.
        """
        parser_aliases = sorted(dexy.parser.Parser.plugins.keys())

        # collect all doc config files in project dir
        config_files = []
        for alias in parser_aliases:
            for filepath, fileinfo in self.filemap.iteritems():
                if fileinfo['dir'] == '.' or self.recurse or self.is_explicit_config(filepath):
                    if os.path.split(filepath)[1] == alias:
                        self.log.info("using config file '%s'" % filepath)
                        config_file_info = (fileinfo['ospath'], fileinfo['dir'], alias,)
                        config_files.append(config_file_info)

        # warn if we don't find any configs
        if len(config_files) == 0:
            msg = "didn't find any document config files (like %s)"
            self.printmsg(msg % (", ".join(parser_aliases)))

        # parse each config file and add to ast
        ast = dexy.parser.AbstractSyntaxTree(self)

        for config_file, dirname, alias in config_files:
            with open(config_file, "r") as f:
                config_text = f.read()
            parser = dexy.parser.Parser.create_instance(alias, self, ast)
            parser.parse(dirname, config_text)

        return ast
示例#2
0
 def load_doc_config(self):
     """
     Look for document config files in current working dir and load them.
     """
     parser_aliases = dexy.parser.Parser.aliases
     for k in parser_aliases.keys():
         if os.path.exists(k):
             self.log.debug("found doc config file '%s'" % k)
             parser = parser_aliases[k](self)
             with open(k, "r") as f:
                 parser.parse(f.read())
示例#3
0
文件: wrapper.py 项目: dexy/dexy
    def parse_configs(self):
        """
        Look for document config files in current working tree and load them.
        Return an Abstract Syntax Tree with information about nodes to be
        processed.
        """
        ast = dexy.parser.AbstractSyntaxTree(self)

        processed_configs = []

        for alias in self.parsers.split():
            parser = dexy.parser.Parser.create_instance(alias, self, ast)

            for filepath, fileinfo in self.filemap.items():
                if fileinfo[
                        'dir'] == '.' or self.recurse or self.is_explicit_config(
                            filepath):
                    if os.path.split(filepath)[1] == alias:
                        self.log.info("using config file '%s'" % filepath)

                        config_file = fileinfo['ospath']
                        dirname = fileinfo['dir']

                        with open(config_file, "r") as f:
                            config_text = f.read()

                        try:
                            processed_configs.append(filepath)
                            parser.parse(dirname, config_text)
                        except UserFeedback:
                            sys.stderr.write(
                                "Problem occurred while parsing %s\n" %
                                config_file)
                            raise

        if len(processed_configs) == 0:
            msg = "didn't find any document config files (like %s)"
            self.printmsg(msg % self.parsers)

        return ast
示例#4
0
    def parse_configs(self):
        """
        Look for document config files in current working tree and load them.
        Return an Abstract Syntax Tree with information about nodes to be
        processed.
        """
        parser_aliases = sorted(dexy.parser.Parser.plugins.keys())

        # collect all doc config files in project dir
        config_files = []
        for alias in parser_aliases:
            for filepath, fileinfo in self.filemap.iteritems():
                if fileinfo[
                        'dir'] == '.' or self.recurse or self.is_explicit_config(
                            filepath):
                    if os.path.split(filepath)[1] == alias:
                        self.log.info("using config file '%s'" % filepath)
                        config_file_info = (
                            fileinfo['ospath'],
                            fileinfo['dir'],
                            alias,
                        )
                        config_files.append(config_file_info)

        # warn if we don't find any configs
        if len(config_files) == 0:
            msg = "didn't find any document config files (like %s)"
            self.printmsg(msg % (", ".join(parser_aliases)))

        # parse each config file and add to ast
        ast = dexy.parser.AbstractSyntaxTree(self)

        for config_file, dirname, alias in config_files:
            with open(config_file, "r") as f:
                config_text = f.read()
            parser = dexy.parser.Parser.create_instance(alias, self, ast)
            parser.parse(dirname, config_text)

        return ast
示例#5
0
文件: wrapper.py 项目: GWhized/dexy
    def parse_configs(self):
        """
        Look for document config files in current working tree and load them.
        Return an Abstract Syntax Tree with information about nodes to be
        processed.
        """
        ast = dexy.parser.AbstractSyntaxTree(self)

        processed_configs = []

        for alias in self.parsers.split():
            parser = dexy.parser.Parser.create_instance(alias, self, ast)

            for filepath, fileinfo in self.filemap.iteritems():
                if fileinfo["dir"] == "." or self.recurse or self.is_explicit_config(filepath):
                    if os.path.split(filepath)[1] == alias:
                        self.log.info("using config file '%s'" % filepath)

                        config_file = fileinfo["ospath"]
                        dirname = fileinfo["dir"]

                        with open(config_file, "r") as f:
                            config_text = f.read()

                        try:
                            processed_configs.append(filepath)
                            parser.parse(dirname, config_text)
                        except UserFeedback:
                            sys.stderr.write("Problem occurred while parsing %s\n" % config_file)
                            raise

        if len(processed_configs) == 0:
            msg = "didn't find any document config files (like %s)"
            self.printmsg(msg % self.parsers)

        return ast