Browse Source

Merge branch 'master' into latex_special

pull/213/head
Louis 8 years ago
parent
commit
a16cf5434a
  1. 4
      patacrep/authors.py
  2. 11
      patacrep/data/templates/songbook/default.tex
  3. 12
      patacrep/data/templates/songbook_model.yml
  4. 13
      patacrep/data/templates/styles/chords.sty
  5. 8
      patacrep/data/templates/styles/patacrep.sty
  6. 5
      patacrep/templates.py
  7. 77
      patacrep/tools/__main__.py
  8. 5
      patacrep/tools/cache/__main__.py
  9. 3
      patacrep/tools/convert/__main__.py
  10. 2
      setup.py
  11. 0
      test/test_book/.gitignore
  12. 0
      test/test_book/__init__.py
  13. 12
      test/test_book/content.tex.control
  14. 0
      test/test_book/content.yaml
  15. 0
      test/test_book/content_datadir/content/foo.tex
  16. 0
      test/test_book/content_datadir/content/inter.isg
  17. 0
      test/test_book/content_datadir/content/song.csg
  18. 0
      test/test_book/content_datadir/content/song.tsg
  19. 0
      test/test_book/content_datadir/songs/include.sbc
  20. 0
      test/test_book/content_datadir/songs/inter.isg
  21. 0
      test/test_book/content_datadir/songs/song.csg
  22. 0
      test/test_book/content_datadir/songs/song.tsg
  23. 12
      test/test_book/datadir.tex.control
  24. 0
      test/test_book/datadir.yaml
  25. 0
      test/test_book/datadir_datadir/img/datadir.png
  26. 0
      test/test_book/datadir_datadir/scores/datadir.ly
  27. 0
      test/test_book/datadir_datadir/songs/datadir.csg
  28. 0
      test/test_book/datadir_datadir/songs/datadir.tsg
  29. 0
      test/test_book/datadir_datadir/songs/datadir2.csg
  30. 0
      test/test_book/datadir_datadir/songs/datadir2.sg
  31. 0
      test/test_book/datadir_datadir/songs/relative.csg
  32. 0
      test/test_book/datadir_datadir/songs/relative.ly
  33. 0
      test/test_book/datadir_datadir/songs/relative.png
  34. 0
      test/test_book/datadir_datadir/songs/relative.tsg
  35. 0
      test/test_book/datadir_datadir/songs/subdir/subdir.csg
  36. 0
      test/test_book/datadir_datadir/songs/subdir/subdir.ly
  37. 0
      test/test_book/datadir_datadir/songs/subdir/subdir.png
  38. 0
      test/test_book/datadir_datadir/songs/subdir/subdir.tsg
  39. 0
      test/test_book/datadir_datadir2/img/datadir2.png
  40. 0
      test/test_book/datadir_datadir2/scores/datadir2.ly
  41. 12
      test/test_book/lang_default.tex.control
  42. 0
      test/test_book/lang_default.yaml
  43. 12
      test/test_book/lang_en.tex.control
  44. 0
      test/test_book/lang_en.yaml
  45. 12
      test/test_book/lang_fr.tex.control
  46. 0
      test/test_book/lang_fr.yaml
  47. 12
      test/test_book/languages.tex.control
  48. 0
      test/test_book/languages.yaml
  49. 0
      test/test_book/languages_datadir/songs/language.csg
  50. 0
      test/test_book/languages_datadir/songs/language_location.csg
  51. 0
      test/test_book/languages_datadir/songs/no_language.csg
  52. 0
      test/test_book/languages_datadir/songs/wrong_language.csg
  53. 0
      test/test_book/languages_datadir/songs/wrong_location.csg
  54. 12
      test/test_book/onthefly/content.onthefly.tex.control
  55. 0
      test/test_book/onthefly/content.onthefly.yaml
  56. 0
      test/test_book/special.yaml
  57. 0
      test/test_book/special_datadir/songs/special.csg
  58. 12
      test/test_book/syntax.tex.control
  59. 0
      test/test_book/syntax.yaml
  60. 0
      test/test_book/syntax_datadir/songs/musicnote.csg
  61. 0
      test/test_book/test_compilation.py
  62. 12
      test/test_book/unicode.tex.control
  63. 0
      test/test_book/unicode.yaml
  64. 0
      test/test_book/unicode_datadir/songs/nonbreak.csg

4
patacrep/authors.py

@ -17,11 +17,11 @@ def compile_authwords(authwords):
'ignore': authwords.get('ignore', []),
'after': [
re.compile(RE_AFTER.format(word))
for word in authwords.get('after')
for word in authwords.get('after', [])
],
'separators': [
re.compile(RE_SEPARATOR.format(word))
for word in ([" %s" % word for word in authwords['separators']] + [',', ';'])
for word in ([" %s" % word for word in authwords.get('separators', [])] + [',', ';'])
],
}

11
patacrep/data/templates/songbook/default.tex

@ -103,12 +103,11 @@ description:
(* block chords *)
% list of chords
\ifchorded
\ifdiagram
\phantomsection
\addcontentsline{toc}{section}{\chordlistname}
\chords
\fi
\ifdiagrampage
\phantomsection
\addcontentsline{toc}{section}{\chordlistname}
\chords
\fi
\setcounter{songnum}{1}%
(* endblock *)

12
patacrep/data/templates/songbook_model.yml

@ -27,7 +27,15 @@ schema:
type: //rec
required:
show: //bool
diagrampage: //bool
diagrampage:
type: //any
of:
- type: //str
value: "none"
- type: //str
value: "important"
- type: //str
value: "all"
repeatchords: //bool
lilypond: //bool
tablatures: //bool
@ -97,7 +105,7 @@ default:
chords:
show: yes
diagramreminder: important
diagrampage: yes
diagrampage: all
repeatchords: yes
lilypond: no
tablatures: no

13
patacrep/data/templates/styles/chords.sty

@ -24,7 +24,7 @@
\raisebox{2em}{\chordname{##1}} %
} %
% Placing boxes
\ifimportantdiagramonly%
\ifdiagrampagereduced%
\pl@cechord{#1}%
\hspace{\stretch{1}}%
\usebox{\@chordgroupbox@ii}%
@ -75,7 +75,17 @@
\newcommand{\chords}{
\ifdiagrampage
\begin{songs}{}
%important diagrams are hidden by \chordtabs
\renewcommand{\gtab}{\@ifstar
\gtab@Original%
\gtab@Original%
}
\renewcommand{\utab}{\@ifstar
\utab@Original%
\utab@Original%
}
%hide song number
\definecolor{SongNumberBgColor}{HTML}{FFFFFF}
\renewcommand{\snumbgcolor}{SongNumberBgColor}
@ -391,5 +401,6 @@
\fi
\end{songs}
\fi
}
\endinput

8
patacrep/data/templates/styles/patacrep.sty

@ -26,6 +26,14 @@
\newif{\iflilypondauto}
\DeclareOption{lilypond}{\lilypondautotrue\lilypondtrue}
% diagram: insert a page of diagrams before the songs
\newif{\ifdiagrampage}
\DeclareOption{diagrampage}{\diagrampagetrue}
% diagram: insert a page of the "important diagrams" before the songs
\newif{\ifdiagrampagereduced}
\DeclareOption{diagrampagereduced}{\diagrampagereducedtrue\diagrampagetrue}
% diagram: display chord diagrams at the beginning
\newif{\ifdiagram}
\DeclareOption{diagram}{\diagramtrue}

5
patacrep/templates.py

@ -296,4 +296,9 @@ def iter_bookoptions(config):
elif config['chords']['diagramreminder'] == "all":
yield 'diagram'
if config['chords']['diagrampage'] == "important":
yield 'diagrampagereduced'
elif config['chords']['diagrampage'] == "all":
yield 'diagrampage'
yield config['chords']['instrument']

77
patacrep/tools/__main__.py

@ -2,85 +2,26 @@
"""Command line client to :mod:`tools`"""
import argparse
import logging
import operator
import os
import pkgutil
import re
import sys
import argdispatch
import patacrep
# Logging configuration
logging.basicConfig(level=logging.INFO)
LOGGER = logging.getLogger("patatools")
def _execlp(program, args):
"""Call :func:`os.execlp`, adding `program` as the first argument to itself."""
return os.execlp(program, program, *args)
def _iter_subcommands():
"""Iterate over subcommands.
The objects returned are tuples of:
- the name of the command;
- its description;
- the function to call to execute the subcommand.
"""
subcommands = []
# Get python subcommands
path = [os.path.join(item, "patacrep", "tools") for item in sys.path]
prefix = "patacrep.tools."
module_re = re.compile(r'{}(?P<subcommand>[^\.]*)\.__main__'.format(prefix))
for module_loader, name, _ in pkgutil.walk_packages(path, prefix):
match = module_re.match(name)
if match:
module = module_loader.find_module(match.string).load_module()
if hasattr(module, "SUBCOMMAND_DESCRIPTION"):
subcommands.append(match.groupdict()['subcommand'])
yield (
match.groupdict()['subcommand'],
getattr(module, "SUBCOMMAND_DESCRIPTION"),
module.main,
)
class ArgumentParser(argparse.ArgumentParser):
"""Proxy class to circumvent an :mod:`argparse` bug.
Contrarily to what documented, the `argparse.REMAINDER
<https://docs.python.org/3/library/argparse.html#nargs>`_ `nargs` setting
does not include the remainder arguments if the first one begins with `-`.
This bug is reperted as `17050 <https://bugs.python.org/issue17050>`_. This
class can be deleted once this bug has been fixed.
"""
def parse_args(self, args=None, namespace=None):
if args is None:
args = sys.argv[1:]
subcommands = [command[0] for command in set(_iter_subcommands())]
if len(args) > 0:
if args[0] in subcommands:
args = [args[0], "--"] + args[1:]
value = super().parse_args(args, namespace)
if hasattr(value, 'remainder'):
value.remainder = value.remainder[1:]
return value
def commandline_parser():
"""Return a command line parser."""
parser = ArgumentParser(
parser = argdispatch.ArgumentParser(
prog="patatools",
description=(
"Miscellaneous tools for patacrep."
),
formatter_class=argparse.RawTextHelpFormatter,
formatter_class=argdispatch.RawTextHelpFormatter,
)
parser.add_argument(
@ -96,11 +37,7 @@ def commandline_parser():
)
subparsers.required = True
subparsers.dest = "subcommand"
for command, message, function in sorted(_iter_subcommands(), key=operator.itemgetter(0)):
sub1 = subparsers.add_parser(command, help=message, add_help=False)
sub1.add_argument('remainder', nargs=argparse.REMAINDER)
sub1.set_defaults(function=function)
subparsers.add_submodules("patacrep.tools")
return parser
@ -108,9 +45,7 @@ def main(args=None):
"""Main function"""
if args is None:
args = sys.argv
parser = commandline_parser()
args = parser.parse_args(args[1:])
args.function(["patatools-{}".format(args.subcommand)] + args.remainder)
commandline_parser().parse_args(args[1:])
if __name__ == "__main__":
main()

5
patacrep/tools/cache/__main__.py

@ -1,4 +1,4 @@
"""`patatools cache` command: cache manipulation."""
"""Perform operations on cache."""
import argparse
import logging
@ -11,7 +11,6 @@ from patacrep import errors
from patacrep.songbook import open_songbook
LOGGER = logging.getLogger("patatools.cache")
SUBCOMMAND_DESCRIPTION = "Perform operations on cache."
def filename(name):
"""Check that argument is an existing, readable file name.
@ -27,7 +26,7 @@ def commandline_parser():
parser = argparse.ArgumentParser(
prog="patatools cache",
description=SUBCOMMAND_DESCRIPTION,
description="Convert between song formats.",
formatter_class=argparse.RawTextHelpFormatter,
)

3
patacrep/tools/convert/__main__.py

@ -1,4 +1,4 @@
"""`patatools.convert` command: convert between song formats"""
"""Convert between song formats."""
import os
import logging
@ -10,7 +10,6 @@ from patacrep.utils import yesno
from patacrep.build import config_model
LOGGER = logging.getLogger("patatools.convert")
SUBCOMMAND_DESCRIPTION = "Convert between song formats"
def _usage():
return "patatools convert INPUTFORMAT OUTPUTFORMAT FILES"

2
setup.py

@ -34,7 +34,7 @@ setup(
packages=find_packages(exclude=["test*"]),
license="GPLv2 or any later version",
install_requires=[
"unidecode", "jinja2", "ply", "pyyaml",
"argdispatch", "unidecode", "jinja2", "ply", "pyyaml",
],
entry_points={
'console_scripts': [

0
test/test_songbook/.gitignore → test/test_book/.gitignore

0
test/test_songbook/__init__.py → test/test_book/__init__.py

12
test/test_songbook/content.tex.control → test/test_book/content.tex.control

@ -26,6 +26,7 @@
chorded,
pictures,
diagram,
diagrampage,
guitar,
]{patacrep}
@ -79,13 +80,12 @@ guitar,
\showindex{\authorindexname}{authidx}
% list of chords
\ifchorded
\ifdiagram
\phantomsection
\addcontentsline{toc}{section}{\chordlistname}
\chords
\fi
\ifdiagrampage
\phantomsection
\addcontentsline{toc}{section}{\chordlistname}
\chords
\fi
\setcounter{songnum}{1}%
\phantomsection
\addcontentsline{toc}{section}{\songlistname}

0
test/test_songbook/content.yaml → test/test_book/content.yaml

0
test/test_songbook/content_datadir/content/foo.tex → test/test_book/content_datadir/content/foo.tex

0
test/test_songbook/content_datadir/content/inter.isg → test/test_book/content_datadir/content/inter.isg

0
test/test_songbook/content_datadir/content/song.csg → test/test_book/content_datadir/content/song.csg

0
test/test_songbook/content_datadir/content/song.tsg → test/test_book/content_datadir/content/song.tsg

0
test/test_songbook/content_datadir/songs/include.sbc → test/test_book/content_datadir/songs/include.sbc

0
test/test_songbook/content_datadir/songs/inter.isg → test/test_book/content_datadir/songs/inter.isg

0
test/test_songbook/content_datadir/songs/song.csg → test/test_book/content_datadir/songs/song.csg

0
test/test_songbook/content_datadir/songs/song.tsg → test/test_book/content_datadir/songs/song.tsg

12
test/test_songbook/datadir.tex.control → test/test_book/datadir.tex.control

@ -28,6 +28,7 @@ chorded,
pictures,
repeatchords,
importantdiagramonly,
diagrampage,
guitar,
]{patacrep}
@ -82,13 +83,12 @@ guitar,
\showindex{\authorindexname}{authidx}
% list of chords
\ifchorded
\ifdiagram
\phantomsection
\addcontentsline{toc}{section}{\chordlistname}
\chords
\fi
\ifdiagrampage
\phantomsection
\addcontentsline{toc}{section}{\chordlistname}
\chords
\fi
\setcounter{songnum}{1}%
\phantomsection
\addcontentsline{toc}{section}{\songlistname}

0
test/test_songbook/datadir.yaml → test/test_book/datadir.yaml

0
test/test_songbook/datadir_datadir/img/datadir.png → test/test_book/datadir_datadir/img/datadir.png

Before

Width:  |  Height:  |  Size: 4.0 KiB

After

Width:  |  Height:  |  Size: 4.0 KiB

0
test/test_songbook/datadir_datadir/scores/datadir.ly → test/test_book/datadir_datadir/scores/datadir.ly

0
test/test_songbook/datadir_datadir/songs/datadir.csg → test/test_book/datadir_datadir/songs/datadir.csg

0
test/test_songbook/datadir_datadir/songs/datadir.tsg → test/test_book/datadir_datadir/songs/datadir.tsg

0
test/test_songbook/datadir_datadir/songs/datadir2.csg → test/test_book/datadir_datadir/songs/datadir2.csg

0
test/test_songbook/datadir_datadir/songs/datadir2.sg → test/test_book/datadir_datadir/songs/datadir2.sg

0
test/test_songbook/datadir_datadir/songs/relative.csg → test/test_book/datadir_datadir/songs/relative.csg

0
test/test_songbook/datadir_datadir/songs/relative.ly → test/test_book/datadir_datadir/songs/relative.ly

0
test/test_songbook/datadir_datadir/songs/relative.png → test/test_book/datadir_datadir/songs/relative.png

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

0
test/test_songbook/datadir_datadir/songs/relative.tsg → test/test_book/datadir_datadir/songs/relative.tsg

0
test/test_songbook/datadir_datadir/songs/subdir/subdir.csg → test/test_book/datadir_datadir/songs/subdir/subdir.csg

0
test/test_songbook/datadir_datadir/songs/subdir/subdir.ly → test/test_book/datadir_datadir/songs/subdir/subdir.ly

0
test/test_songbook/datadir_datadir/songs/subdir/subdir.png → test/test_book/datadir_datadir/songs/subdir/subdir.png

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

0
test/test_songbook/datadir_datadir/songs/subdir/subdir.tsg → test/test_book/datadir_datadir/songs/subdir/subdir.tsg

0
test/test_songbook/datadir_datadir2/img/datadir2.png → test/test_book/datadir_datadir2/img/datadir2.png

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

0
test/test_songbook/datadir_datadir2/scores/datadir2.ly → test/test_book/datadir_datadir2/scores/datadir2.ly

12
test/test_songbook/lang_default.tex.control → test/test_book/lang_default.tex.control

@ -26,6 +26,7 @@ chorded,
pictures,
repeatchords,
importantdiagramonly,
diagrampage,
guitar,
]{crepbook}
@ -113,13 +114,12 @@ guitar,
\showindex{\authorindexname}{authidx}
% list of chords
\ifchorded
\ifdiagram
\phantomsection
\addcontentsline{toc}{section}{\chordlistname}
\chords
\fi
\ifdiagrampage
\phantomsection
\addcontentsline{toc}{section}{\chordlistname}
\chords
\fi
\setcounter{songnum}{1}%
\phantomsection
\addcontentsline{toc}{section}{\songlistname}

0
test/test_songbook/lang_default.yaml → test/test_book/lang_default.yaml

12
test/test_songbook/lang_en.tex.control → test/test_book/lang_en.tex.control

@ -26,6 +26,7 @@ chorded,
pictures,
repeatchords,
importantdiagramonly,
diagrampage,
guitar,
]{crepbook}
@ -113,13 +114,12 @@ guitar,
\showindex{\authorindexname}{authidx}
% list of chords
\ifchorded
\ifdiagram
\phantomsection
\addcontentsline{toc}{section}{\chordlistname}
\chords
\fi
\ifdiagrampage
\phantomsection
\addcontentsline{toc}{section}{\chordlistname}
\chords
\fi
\setcounter{songnum}{1}%
\phantomsection
\addcontentsline{toc}{section}{\songlistname}

0
test/test_songbook/lang_en.yaml → test/test_book/lang_en.yaml

12
test/test_songbook/lang_fr.tex.control → test/test_book/lang_fr.tex.control

@ -26,6 +26,7 @@ chorded,
pictures,
repeatchords,
importantdiagramonly,
diagrampage,
guitar,
]{crepbook}
@ -113,13 +114,12 @@ guitar,
\showindex{\authorindexname}{authidx}
% list of chords
\ifchorded
\ifdiagram
\phantomsection
\addcontentsline{toc}{section}{\chordlistname}
\chords
\fi
\ifdiagrampage
\phantomsection
\addcontentsline{toc}{section}{\chordlistname}
\chords
\fi
\setcounter{songnum}{1}%
\phantomsection
\addcontentsline{toc}{section}{\songlistname}

0
test/test_songbook/lang_fr.yaml → test/test_book/lang_fr.yaml

12
test/test_songbook/languages.tex.control → test/test_book/languages.tex.control

@ -27,6 +27,7 @@ chorded,
pictures,
repeatchords,
importantdiagramonly,
diagrampage,
guitar,
]{patacrep}
@ -82,13 +83,12 @@ guitar,
\showindex{\authorindexname}{authidx}
% list of chords
\ifchorded
\ifdiagram
\phantomsection
\addcontentsline{toc}{section}{\chordlistname}
\chords
\fi
\ifdiagrampage
\phantomsection
\addcontentsline{toc}{section}{\chordlistname}
\chords
\fi
\setcounter{songnum}{1}%
\phantomsection
\addcontentsline{toc}{section}{\songlistname}

0
test/test_songbook/languages.yaml → test/test_book/languages.yaml

0
test/test_songbook/languages_datadir/songs/language.csg → test/test_book/languages_datadir/songs/language.csg

0
test/test_songbook/languages_datadir/songs/language_location.csg → test/test_book/languages_datadir/songs/language_location.csg

0
test/test_songbook/languages_datadir/songs/no_language.csg → test/test_book/languages_datadir/songs/no_language.csg

0
test/test_songbook/languages_datadir/songs/wrong_language.csg → test/test_book/languages_datadir/songs/wrong_language.csg

0
test/test_songbook/languages_datadir/songs/wrong_location.csg → test/test_book/languages_datadir/songs/wrong_location.csg

12
test/test_songbook/onthefly/content.onthefly.tex.control → test/test_book/onthefly/content.onthefly.tex.control

@ -25,6 +25,7 @@
chorded,
pictures,
diagram,
diagrampage,
guitar,
]{patacrep}
@ -77,13 +78,12 @@ guitar,
\showindex{\authorindexname}{authidx}
% list of chords
\ifchorded
\ifdiagram
\phantomsection
\addcontentsline{toc}{section}{\chordlistname}
\chords
\fi
\ifdiagrampage
\phantomsection
\addcontentsline{toc}{section}{\chordlistname}
\chords
\fi
\setcounter{songnum}{1}%
\phantomsection
\addcontentsline{toc}{section}{\songlistname}

0
test/test_songbook/onthefly/content.onthefly.yaml → test/test_book/onthefly/content.onthefly.yaml

0
test/test_songbook/special.yaml → test/test_book/special.yaml

0
test/test_songbook/special_datadir/songs/special.csg → test/test_book/special_datadir/songs/special.csg

12
test/test_songbook/syntax.tex.control → test/test_book/syntax.tex.control

@ -27,6 +27,7 @@ chorded,
pictures,
repeatchords,
importantdiagramonly,
diagrampage,
guitar,
]{patacrep}
@ -79,13 +80,12 @@ guitar,
\showindex{\authorindexname}{authidx}
% list of chords
\ifchorded
\ifdiagram
\phantomsection
\addcontentsline{toc}{section}{\chordlistname}
\chords
\fi
\ifdiagrampage
\phantomsection
\addcontentsline{toc}{section}{\chordlistname}
\chords
\fi
\setcounter{songnum}{1}%
\phantomsection
\addcontentsline{toc}{section}{\songlistname}

0
test/test_songbook/syntax.yaml → test/test_book/syntax.yaml

0
test/test_songbook/syntax_datadir/songs/musicnote.csg → test/test_book/syntax_datadir/songs/musicnote.csg

0
test/test_songbook/test_compilation.py → test/test_book/test_compilation.py

12
test/test_songbook/unicode.tex.control → test/test_book/unicode.tex.control

@ -27,6 +27,7 @@ chorded,
pictures,
repeatchords,
importantdiagramonly,
diagrampage,
guitar,
]{patacrep}
@ -79,13 +80,12 @@ guitar,
\showindex{\authorindexname}{authidx}
% list of chords
\ifchorded
\ifdiagram
\phantomsection
\addcontentsline{toc}{section}{\chordlistname}
\chords
\fi
\ifdiagrampage
\phantomsection
\addcontentsline{toc}{section}{\chordlistname}
\chords
\fi
\setcounter{songnum}{1}%
\phantomsection
\addcontentsline{toc}{section}{\songlistname}

0
test/test_songbook/unicode.yaml → test/test_book/unicode.yaml

0
test/test_songbook/unicode_datadir/songs/nonbreak.csg → test/test_book/unicode_datadir/songs/nonbreak.csg

Loading…
Cancel
Save