Browse Source

Possibilité d'ajouter à la chaîne de compilation une commande personnalisée

Cette commande personnalisée apparait comme `--steps "%commande arg1 arg2"`.
pull/20/head
Louis 10 years ago
parent
commit
5ebe179b8d
  1. 15
      songbook
  2. 6
      songbook_core/build.py
  3. 17
      songbook_core/errors.py

15
songbook

@ -21,10 +21,15 @@ from songbook_core import errors
class ParseStepsAction(argparse.Action):
"""Argparse action to split a string into a list."""
def __call__(self, __parser, namespace, values, __option_string=None):
if not getattr(namespace, self.dest):
setattr(namespace, self.dest, [])
setattr(
namespace,
self.dest,
[value.strip() for value in values[0].split(',')],
(
getattr(namespace, self.dest)
+ [value.strip() for value in values[0].split(',')]
),
)
def argument_parser(args):
@ -52,9 +57,13 @@ def argument_parser(args):
"tex" produce .tex file from templates;
"pdf" compile .tex file;
"sbx" compile index files;
"clean" remove temporary files.
"clean" remove temporary files;
any string beginning with '%%' (in this case, it will be run
in a shell). Several steps (excepted the custom shell
command) can be combinend in one --steps argument, as a
comma separated string.
""".format(steps=','.join(DEFAULT_STEPS))),
default=DEFAULT_STEPS,
default=None,
)
options = parser.parse_args(args)

6
songbook_core/build.py

@ -208,6 +208,12 @@ def buildsongbook(
elif step == 'clean':
# Cleaning
clean(basename)
elif step.startswith("%"):
# Shell command
command = step[1:]
exit_code = subprocess.call(command, shell=True)
if exit_code:
raise errors.StepCommandError(command, exit_code)
else:
# Unknown step name
raise errors.UnknownStep(step)

17
songbook_core/errors.py

@ -18,11 +18,22 @@ class LatexCompilationError(SongbookError):
self.basename = basename
def __str__(self):
return (
"""Error while pdfLaTeX compilation of "{basename}.tex"
(see {basename}.log for more information)."""
return ("""Error while pdfLaTeX compilation of "{basename}.tex" """
"""(see {basename}.log for more information)."""
).format(basename=self.basename)
class StepCommandError(SongbookError):
"""Error during LaTeX compilation."""
def __init__(self, command, code):
super(StepCommandError, self).__init__()
self.command = command
self.code = code
def __str__(self):
return ("""Error while running custom command "{command}": got return"""
" code {code}.").format(command=self.command, code=self.code)
class CleaningError(SongbookError):
"""Error during cleaning of LaTeX auxiliary files."""

Loading…
Cancel
Save