Esempio n. 1
0
    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
        config = DEFAULT_CONFIG
        config.update(self.config)
        renderer = TexRenderer(
                config['template'],
                config['datadir'],
                config['lang'],
                )
        config.update(self.config)
        config.update(renderer.get_variables())

        config['authwords'] = authors.compile_authwords(config['authwords'])

        self.config = config
        # Configuration set

        self.contentlist = content.process_content(
                self.config.get('content', []),
                self.config,
                )
        self.config['render_content'] = content.render_content
        self.config['titleprefixkeys'] = ["after", "sep", "ignore"]
        self.config['content'] = self.contentlist
        self.config['filename'] = output.name[:-4]

        renderer.render_tex(output, self.config)
Esempio n. 2
0
    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 = self._raw_config.copy()
        renderer = TexBookRenderer(
            self._config['book']['template'],
            self._config['_datadir'],
            self._config['book']['lang'],
            self._config['book']['encoding'],
            )

        try:
            self._config['_template'] = renderer.get_all_variables(self._config.get('template', {}))
        except errors.SchemaError as exception:
            exception.message = "The songbook file '{}' is not valid\n{}".format(
                self.basename, exception.message)
            raise exception

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

        # Loading custom plugins
        self._config['_content_plugins'] = files.load_plugins(
            datadirs=self._config['_datadir'],
            root_modules=['content'],
            keyword='CONTENT_PLUGINS',
            )
        self._config['_song_plugins'] = files.load_plugins(
            datadirs=self._config['_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]

        self._config['_bookoptions'] = iter_bookoptions(self._config)

        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.")
Esempio n. 3
0
    def compile_keywords(self):
        """Turn keywords (self.keywords) into regular expressions."""
        if self.indextype == "TITLE":
            if 'prefix' in self.keywords:
                for prefix in self.keywords['prefix']:
                    self.prefix_patterns.append(re.compile(
                        r"^({prefix})(\b|\\)(\s*.*)$".format(prefix=prefix)
                        ))

        if self.indextype == "AUTHOR":
            self.authwords = authors.compile_authwords(self.keywords)
Esempio n. 4
0
    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 = self._raw_config.copy()
        renderer = TexBookRenderer(
            self._config['book']['template'],
            self._config['_datadir'],
            self._config['book']['lang'],
            self._config['book']['encoding'],
        )

        try:
            self._config['_template'] = renderer.get_all_variables(
                self._config.get('template', {}))
        except errors.SchemaError as exception:
            exception.message = "The songbook file '{}' is not valid\n{}".format(
                self.basename, exception.message)
            raise exception

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

        # 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]

        # Processing special options
        self._config['_bookoptions'] = iter_bookoptions(self._config)
        self._config['chords']['_notenames'] = self._get_chord_names(
            self._config['chords']['notation'])

        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.")
Esempio n. 5
0
    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
        tex_config = self._raw_config.copy()
        renderer = TexBookRenderer(
            tex_config['book']['template'],
            tex_config['_datadir'],
            tex_config['book']['lang'],
            tex_config['book']['encoding'],
            )

        try:
            tex_config['_template'] = renderer.get_all_variables(tex_config.get('template', {}))
        except errors.SchemaError as exception:
            exception.message = "The songbook file '{}' is not valid\n{}".format(
                self.basename, exception.message)
            raise exception

        tex_config['_compiled_authwords'] = authors.compile_authwords(
            copy.deepcopy(tex_config['authors'])
            )

        # Configuration set
        tex_config['render'] = content.render
        tex_config['_langs'], tex_config['content'] = self.get_content_items()
        tex_config['filename'] = output.name[:-4]

        # Processing special options
        tex_config['_bookoptions'] = iter_bookoptions(tex_config)
        tex_config['chords']['_notenames'] = self._get_chord_names(
            tex_config['chords']['notation']
            )

        renderer.render_tex(output, tex_config)

        # Get all errors, and maybe exit program
        self._errors.extend(renderer.errors)
        if tex_config['_error'] == "failonbook":
            if self.has_errors():
                raise errors.SongbookError("Some songs contain errors. Stopping as requested.")
Esempio n. 6
0
    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.")
Esempio n. 7
0
    (
        "Anonyme (1967)",
        [],
    ),
    (
        "Lucky Luke et Jolly Jumper",
        [
            ("Luke", "Lucky"),
            ("Jumper", "Jolly"),
        ],
    ),
]

AUTHWORDS = authors.compile_authwords({
    "after": ["by"],
    "ignore": ["anonymous", "Anonyme", "anonyme"],
    "separators": ['and', 'et'],
    })

class TestAutors(unittest.TestCase):
    """Test of author parsing."""

    def test_split_author_names(self):
        """Test of :func:`patacrep.authors.split_author_names` function."""
        for argument, expected in SPLIT_AUTHORS_DATA:
            with self.subTest(argument=argument, expected=expected):
                self.assertEqual(authors.split_author_names(argument), expected)

    def test_processauthors(self):
        """Test of :func:`patacrep.authors.processauthors` function."""
        for argument, expected in PROCESS_AUTHORS_DATA:
Esempio n. 8
0
    (
        "Anonyme (1967)",
        [],
    ),
    (
        "Lucky Luke et Jolly Jumper",
        [
            ("Luke", "Lucky"),
            ("Jumper", "Jolly"),
        ],
    ),
]

AUTHWORDS = authors.compile_authwords({
    "after": ["by"],
    "ignore": ["anonymous", "Anonyme", "anonyme"],
    "separators": ['and', 'et'],
})


class TestAutors(unittest.TestCase):
    """Test of author parsing."""
    def test_split_author_names(self):
        """Test of :func:`patacrep.authors.split_author_names` function."""
        for argument, expected in SPLIT_AUTHORS_DATA:
            with self.subTest(argument=argument, expected=expected):
                self.assertEqual(authors.split_author_names(argument),
                                 expected)

    def test_processauthors(self):
        """Test of :func:`patacrep.authors.processauthors` function."""