示例#1
0
文件: build.py 项目: tintou/patacrep
    def write_tex(self, output):
        """Build the '.tex' file corresponding to self.

        Arguments:
        - output: a file object, in which the file will be written.
        """
        # Updating configuration
        self._config = DEFAULT_CONFIG.copy()
        self._config.update(self._raw_config)
        renderer = TexBookRenderer(
            self._config["template"], self._config["datadir"], self._config["lang"], self._config["encoding"]
        )
        self._config.update(renderer.get_variables())
        self._config.update(self._raw_config)

        self._config["_compiled_authwords"] = authors.compile_authwords(copy.deepcopy(self._config["authwords"]))

        # Loading custom plugins
        self._config["_content_plugins"] = files.load_plugins(
            datadirs=self._config.get("datadir", []), root_modules=["content"], keyword="CONTENT_PLUGINS"
        )
        self._config["_song_plugins"] = files.load_plugins(
            datadirs=self._config.get("datadir", []), root_modules=["songs"], keyword="SONG_RENDERERS"
        )["tsg"]

        # Configuration set
        self._config["render"] = content.render
        self._config["content"] = content.process_content(self._config.get("content", []), self._config)
        self._config["filename"] = output.name[:-4]

        renderer.render_tex(output, self._config)

        # Get all errors, and maybe exit program
        self._errors.extend(renderer.errors)
        if self.config["_error"] == "failonbook":
            if self.has_errors():
                raise errors.SongbookError("Some songs contain errors. Stopping as requested.")