Browse Source

Merge pull request #183 from patacrep/yaml_for_songbook

Yaml for songbook (WIP)
pull/188/head
Louis 9 years ago
parent
commit
c1a871b549
  1. 17
      examples/example-all.yaml.sb
  2. 5
      patacrep/__init__.py
  3. 3
      patacrep/content/__init__.py
  4. 3
      patacrep/content/song.py
  5. 8
      patacrep/index.py
  6. 6
      patacrep/songbook/__main__.py
  7. 5
      patacrep/songs/chordpro/__init__.py
  8. 3
      patacrep/songs/chordpro/syntax.py
  9. 5
      patacrep/templates.py
  10. 2
      setup.py
  11. 13
      test/test_songbook/datadir.sb
  12. 5
      test/test_songbook/languages.sb
  13. 7
      test/test_songbook/syntax.sb
  14. 7
      test/test_songbook/unicode.sb

17
examples/example-all.yaml.sb

@ -0,0 +1,17 @@
bookoptions:
- "diagram"
- "repeatchords"
- "lilypond"
- "pictures"
booktype: "chorded"
datadir: "."
template: "patacrep.tex"
lang: "fr"
encoding: "utf8"
authwords:
sep:
- "and"
- "et"
content:
-
- "sorted"

5
patacrep/__init__.py

@ -1,10 +1,11 @@
"""Global variables."""
from pkg_resources import resource_filename
import os
import sys
from pkg_resources import resource_filename
# Check Python version
import sys
if sys.version_info < (3, 3):
print("ERROR: Your Python version is too old. Please use a Python version > 3.3.")
sys.exit(1)

3
patacrep/content/__init__.py

@ -66,12 +66,13 @@ More documentation in the docstring of Content.
"""
import glob
import jinja2
import logging
import os
import re
import sys
import jinja2
from patacrep import files
from patacrep.errors import SongbookError

3
patacrep/content/song.py

@ -1,11 +1,12 @@
"""Plugin to include songs to the songbook."""
import glob
import jinja2
import logging
import os
import textwrap
import jinja2
from patacrep.content import process_content, ContentError, Content
from patacrep import files, errors

8
patacrep/index.py

@ -6,8 +6,8 @@ from a file generated by the latex compilation of the songbook (.sxd).
"""
import locale
import unidecode
import re
import unidecode
from patacrep import authors
from patacrep import encoding
@ -77,7 +77,7 @@ class Index(object):
def add_keyword(self, key, word):
"""Add 'word' to self.keywords[key]."""
if not key in self.keywords:
if key not in self.keywords:
self.keywords[key] = []
self.keywords[key].append(word)
@ -101,9 +101,9 @@ class Index(object):
similar method with processing.
"""
first = self.get_first_letter(key[0])
if not first in self.data:
if first not in self.data:
self.data[first] = dict()
if not key in self.data[first]:
if key not in self.data[first]:
self.data[first][key] = {
'sortingkey': [
unidecode.unidecode(tex2plain(item)).lower()

6
patacrep/songbook/__main__.py

@ -1,12 +1,12 @@
"""Command line tool to compile songbooks using the songbook library."""
import argparse
import json
import locale
import logging
import os.path
import textwrap
import sys
import yaml
from patacrep.build import SongbookBuilder, DEFAULT_STEPS
from patacrep.utils import yesno
@ -135,13 +135,13 @@ def main():
try:
with patacrep.encoding.open_read(songbook_path) as songbook_file:
songbook = json.load(songbook_file)
songbook = yaml.load(songbook_file)
if 'encoding' in songbook:
with patacrep.encoding.open_read(
songbook_path,
encoding=songbook['encoding']
) as songbook_file:
songbook = json.load(songbook_file)
songbook = yaml.load(songbook_file)
except Exception as error: # pylint: disable=broad-except
LOGGER.error(error)
LOGGER.error("Error while loading file '{}'.".format(songbook_path))

5
patacrep/songs/chordpro/__init__.py

@ -1,11 +1,12 @@
"""Chordpro parser"""
from jinja2 import Environment, FileSystemLoader, contextfunction, ChoiceLoader
import jinja2
import logging
import operator
import os
from jinja2 import Environment, FileSystemLoader, contextfunction, ChoiceLoader
import jinja2
from patacrep import encoding, files, pkg_datapath
from patacrep.songs import Song
from patacrep.songs.chordpro.syntax import parse_song

3
patacrep/songs/chordpro/syntax.py

@ -1,9 +1,10 @@
"""ChordPro parser"""
import logging
import ply.yacc as yacc
import re
import ply.yacc as yacc
from patacrep.songs.syntax import Parser
from patacrep.songs.chordpro import ast
from patacrep.songs.chordpro.lexer import tokens, ChordProLexer

5
patacrep/templates.py

@ -1,11 +1,12 @@
"""Template for .tex generation settings and utilities"""
import re
import json
from jinja2 import Environment, FileSystemLoader, ChoiceLoader, \
TemplateNotFound, nodes
from jinja2.ext import Extension
from jinja2.meta import find_referenced_templates as find_templates
import re
import json
from patacrep import errors, files
from patacrep.latex import lang2babel

2
setup.py

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

13
test/test_songbook/datadir.sb

@ -1,7 +1,6 @@
{
"bookoptions" : [
"pictures"
],
"datadir": ["datadir_datadir", "datadir_datadir2"],
"lang": "en"
}
bookoptions:
- pictures
datadir:
- datadir_datadir
- datadir_datadir2
lang: en

5
test/test_songbook/languages.sb

@ -1,3 +1,2 @@
{
"datadir": ["languages_datadir"]
}
datadir:
- languages_datadir

7
test/test_songbook/syntax.sb

@ -1,4 +1,3 @@
{
"datadir": ["syntax_datadir"],
"lang": "en"
}
datadir:
- syntax_datadir
lang: en

7
test/test_songbook/unicode.sb

@ -1,4 +1,3 @@
{
"datadir": ["unicode_datadir"],
"lang": "en"
}
datadir:
- unicode_datadir
lang: en

Loading…
Cancel
Save