Browse Source

Merge pull request #156 from patacrep/data

Fix data location
pull/168/head
oliverpool 9 years ago
parent
commit
6c3d36b4eb
  1. 0
      patacrep/data/templates/songs/chordpro/chordpro/content_chord
  2. 0
      patacrep/data/templates/songs/chordpro/chordpro/content_chordlist
  3. 0
      patacrep/data/templates/songs/chordpro/chordpro/content_comment
  4. 0
      patacrep/data/templates/songs/chordpro/chordpro/content_define
  5. 0
      patacrep/data/templates/songs/chordpro/chordpro/content_endofline
  6. 0
      patacrep/data/templates/songs/chordpro/chordpro/content_error
  7. 0
      patacrep/data/templates/songs/chordpro/chordpro/content_guitar_comment
  8. 0
      patacrep/data/templates/songs/chordpro/chordpro/content_image
  9. 0
      patacrep/data/templates/songs/chordpro/chordpro/content_line
  10. 0
      patacrep/data/templates/songs/chordpro/chordpro/content_newline
  11. 0
      patacrep/data/templates/songs/chordpro/chordpro/content_partition
  12. 0
      patacrep/data/templates/songs/chordpro/chordpro/content_space
  13. 0
      patacrep/data/templates/songs/chordpro/chordpro/content_tablature
  14. 0
      patacrep/data/templates/songs/chordpro/chordpro/content_verse
  15. 0
      patacrep/data/templates/songs/chordpro/chordpro/content_word
  16. 0
      patacrep/data/templates/songs/chordpro/chordpro/song
  17. 0
      patacrep/data/templates/songs/chordpro/chordpro/song_body
  18. 0
      patacrep/data/templates/songs/chordpro/chordpro/song_header
  19. 0
      patacrep/data/templates/songs/chordpro/html/content_chord
  20. 0
      patacrep/data/templates/songs/chordpro/html/content_chordlist
  21. 0
      patacrep/data/templates/songs/chordpro/html/content_comment
  22. 0
      patacrep/data/templates/songs/chordpro/html/content_define
  23. 0
      patacrep/data/templates/songs/chordpro/html/content_define_list
  24. 0
      patacrep/data/templates/songs/chordpro/html/content_endofline
  25. 0
      patacrep/data/templates/songs/chordpro/html/content_error
  26. 0
      patacrep/data/templates/songs/chordpro/html/content_guitar_comment
  27. 0
      patacrep/data/templates/songs/chordpro/html/content_image
  28. 0
      patacrep/data/templates/songs/chordpro/html/content_line
  29. 0
      patacrep/data/templates/songs/chordpro/html/content_metadata_cover
  30. 0
      patacrep/data/templates/songs/chordpro/html/content_newline
  31. 0
      patacrep/data/templates/songs/chordpro/html/content_partition
  32. 0
      patacrep/data/templates/songs/chordpro/html/content_space
  33. 0
      patacrep/data/templates/songs/chordpro/html/content_tablature
  34. 0
      patacrep/data/templates/songs/chordpro/html/content_verse
  35. 0
      patacrep/data/templates/songs/chordpro/html/content_word
  36. 0
      patacrep/data/templates/songs/chordpro/html/song
  37. 0
      patacrep/data/templates/songs/chordpro/html/song_body
  38. 0
      patacrep/data/templates/songs/chordpro/html/song_header
  39. 0
      patacrep/data/templates/songs/chordpro/latex/content_chord
  40. 0
      patacrep/data/templates/songs/chordpro/latex/content_chordlist
  41. 0
      patacrep/data/templates/songs/chordpro/latex/content_comment
  42. 0
      patacrep/data/templates/songs/chordpro/latex/content_define
  43. 0
      patacrep/data/templates/songs/chordpro/latex/content_endofline
  44. 0
      patacrep/data/templates/songs/chordpro/latex/content_error
  45. 0
      patacrep/data/templates/songs/chordpro/latex/content_guitar_comment
  46. 0
      patacrep/data/templates/songs/chordpro/latex/content_image
  47. 0
      patacrep/data/templates/songs/chordpro/latex/content_line
  48. 0
      patacrep/data/templates/songs/chordpro/latex/content_newline
  49. 0
      patacrep/data/templates/songs/chordpro/latex/content_partition
  50. 0
      patacrep/data/templates/songs/chordpro/latex/content_space
  51. 0
      patacrep/data/templates/songs/chordpro/latex/content_tablature
  52. 0
      patacrep/data/templates/songs/chordpro/latex/content_verse
  53. 0
      patacrep/data/templates/songs/chordpro/latex/content_word
  54. 0
      patacrep/data/templates/songs/chordpro/latex/song
  55. 0
      patacrep/data/templates/songs/chordpro/latex/song_body
  56. 10
      patacrep/files.py
  57. 10
      patacrep/songs/__init__.py
  58. 11
      patacrep/songs/chordpro/__init__.py
  59. 13
      setup.py
  60. 3
      test/test_chordpro/test_parser.py

0
patacrep/data/ast_templates/chordpro/chordpro/content_chord → patacrep/data/templates/songs/chordpro/chordpro/content_chord

0
patacrep/data/ast_templates/chordpro/chordpro/content_chordlist → patacrep/data/templates/songs/chordpro/chordpro/content_chordlist

0
patacrep/data/ast_templates/chordpro/chordpro/content_comment → patacrep/data/templates/songs/chordpro/chordpro/content_comment

0
patacrep/data/ast_templates/chordpro/chordpro/content_define → patacrep/data/templates/songs/chordpro/chordpro/content_define

0
patacrep/data/ast_templates/chordpro/chordpro/content_endofline → patacrep/data/templates/songs/chordpro/chordpro/content_endofline

0
patacrep/data/ast_templates/chordpro/chordpro/content_error → patacrep/data/templates/songs/chordpro/chordpro/content_error

0
patacrep/data/ast_templates/chordpro/chordpro/content_guitar_comment → patacrep/data/templates/songs/chordpro/chordpro/content_guitar_comment

0
patacrep/data/ast_templates/chordpro/chordpro/content_image → patacrep/data/templates/songs/chordpro/chordpro/content_image

0
patacrep/data/ast_templates/chordpro/chordpro/content_line → patacrep/data/templates/songs/chordpro/chordpro/content_line

0
patacrep/data/ast_templates/chordpro/chordpro/content_newline → patacrep/data/templates/songs/chordpro/chordpro/content_newline

0
patacrep/data/ast_templates/chordpro/chordpro/content_partition → patacrep/data/templates/songs/chordpro/chordpro/content_partition

0
patacrep/data/ast_templates/chordpro/chordpro/content_space → patacrep/data/templates/songs/chordpro/chordpro/content_space

0
patacrep/data/ast_templates/chordpro/chordpro/content_tablature → patacrep/data/templates/songs/chordpro/chordpro/content_tablature

0
patacrep/data/ast_templates/chordpro/chordpro/content_verse → patacrep/data/templates/songs/chordpro/chordpro/content_verse

0
patacrep/data/ast_templates/chordpro/chordpro/content_word → patacrep/data/templates/songs/chordpro/chordpro/content_word

0
patacrep/data/ast_templates/chordpro/chordpro/song → patacrep/data/templates/songs/chordpro/chordpro/song

0
patacrep/data/ast_templates/chordpro/chordpro/song_body → patacrep/data/templates/songs/chordpro/chordpro/song_body

0
patacrep/data/ast_templates/chordpro/chordpro/song_header → patacrep/data/templates/songs/chordpro/chordpro/song_header

0
patacrep/data/ast_templates/chordpro/html/content_chord → patacrep/data/templates/songs/chordpro/html/content_chord

0
patacrep/data/ast_templates/chordpro/html/content_chordlist → patacrep/data/templates/songs/chordpro/html/content_chordlist

0
patacrep/data/ast_templates/chordpro/html/content_comment → patacrep/data/templates/songs/chordpro/html/content_comment

0
patacrep/data/ast_templates/chordpro/html/content_define → patacrep/data/templates/songs/chordpro/html/content_define

0
patacrep/data/ast_templates/chordpro/html/content_define_list → patacrep/data/templates/songs/chordpro/html/content_define_list

0
patacrep/data/ast_templates/chordpro/html/content_endofline → patacrep/data/templates/songs/chordpro/html/content_endofline

0
patacrep/data/ast_templates/chordpro/html/content_error → patacrep/data/templates/songs/chordpro/html/content_error

0
patacrep/data/ast_templates/chordpro/html/content_guitar_comment → patacrep/data/templates/songs/chordpro/html/content_guitar_comment

0
patacrep/data/ast_templates/chordpro/html/content_image → patacrep/data/templates/songs/chordpro/html/content_image

0
patacrep/data/ast_templates/chordpro/html/content_line → patacrep/data/templates/songs/chordpro/html/content_line

0
patacrep/data/ast_templates/chordpro/html/content_metadata_cover → patacrep/data/templates/songs/chordpro/html/content_metadata_cover

0
patacrep/data/ast_templates/chordpro/html/content_newline → patacrep/data/templates/songs/chordpro/html/content_newline

0
patacrep/data/ast_templates/chordpro/html/content_partition → patacrep/data/templates/songs/chordpro/html/content_partition

0
patacrep/data/ast_templates/chordpro/html/content_space → patacrep/data/templates/songs/chordpro/html/content_space

0
patacrep/data/ast_templates/chordpro/html/content_tablature → patacrep/data/templates/songs/chordpro/html/content_tablature

0
patacrep/data/ast_templates/chordpro/html/content_verse → patacrep/data/templates/songs/chordpro/html/content_verse

0
patacrep/data/ast_templates/chordpro/html/content_word → patacrep/data/templates/songs/chordpro/html/content_word

0
patacrep/data/ast_templates/chordpro/html/song → patacrep/data/templates/songs/chordpro/html/song

0
patacrep/data/ast_templates/chordpro/html/song_body → patacrep/data/templates/songs/chordpro/html/song_body

0
patacrep/data/ast_templates/chordpro/html/song_header → patacrep/data/templates/songs/chordpro/html/song_header

0
patacrep/data/ast_templates/chordpro/latex/content_chord → patacrep/data/templates/songs/chordpro/latex/content_chord

0
patacrep/data/ast_templates/chordpro/latex/content_chordlist → patacrep/data/templates/songs/chordpro/latex/content_chordlist

0
patacrep/data/ast_templates/chordpro/latex/content_comment → patacrep/data/templates/songs/chordpro/latex/content_comment

0
patacrep/data/ast_templates/chordpro/latex/content_define → patacrep/data/templates/songs/chordpro/latex/content_define

0
patacrep/data/ast_templates/chordpro/latex/content_endofline → patacrep/data/templates/songs/chordpro/latex/content_endofline

0
patacrep/data/ast_templates/chordpro/latex/content_error → patacrep/data/templates/songs/chordpro/latex/content_error

0
patacrep/data/ast_templates/chordpro/latex/content_guitar_comment → patacrep/data/templates/songs/chordpro/latex/content_guitar_comment

0
patacrep/data/ast_templates/chordpro/latex/content_image → patacrep/data/templates/songs/chordpro/latex/content_image

0
patacrep/data/ast_templates/chordpro/latex/content_line → patacrep/data/templates/songs/chordpro/latex/content_line

0
patacrep/data/ast_templates/chordpro/latex/content_newline → patacrep/data/templates/songs/chordpro/latex/content_newline

0
patacrep/data/ast_templates/chordpro/latex/content_partition → patacrep/data/templates/songs/chordpro/latex/content_partition

0
patacrep/data/ast_templates/chordpro/latex/content_space → patacrep/data/templates/songs/chordpro/latex/content_space

0
patacrep/data/ast_templates/chordpro/latex/content_tablature → patacrep/data/templates/songs/chordpro/latex/content_tablature

0
patacrep/data/ast_templates/chordpro/latex/content_verse → patacrep/data/templates/songs/chordpro/latex/content_verse

0
patacrep/data/ast_templates/chordpro/latex/content_word → patacrep/data/templates/songs/chordpro/latex/content_word

0
patacrep/data/ast_templates/chordpro/latex/song → patacrep/data/templates/songs/chordpro/latex/song

0
patacrep/data/ast_templates/chordpro/latex/song_body → patacrep/data/templates/songs/chordpro/latex/song_body

10
patacrep/files.py

@ -12,20 +12,24 @@ from patacrep import utils
LOGGER = logging.getLogger(__name__)
def recursive_find(root_directory, extensions):
def recursive_find(root_directory, extensions=None):
"""Recursively find files with the given extensions, from a root_directory.
Return a list of files matching those conditions.
Arguments:
- `extensions`: list of accepted extensions.
- `extensions`: list of accepted extensions (None means every file).
- `root_directory`: root directory of the search.
"""
if not os.path.isdir(root_directory):
return []
matches = []
pattern = re.compile(r'.*\.({})$'.format('|'.join(extensions)))
if extensions is None:
pattern = re.compile('.*')
else:
pattern = re.compile(r'.*\.({})$'.format('|'.join(extensions)))
with chdir(root_directory):
for root, __ignored, filenames in os.walk(os.curdir):
for filename in filenames:

10
patacrep/songs/__init__.py

@ -192,11 +192,11 @@ class Song:
"""
raise NotImplementedError()
def get_datadirs(self, subdir=None):
"""Return an iterator of existing datadirs (with eventually a subdir)
def iter_datadirs(self, *subpath):
"""Return an iterator of existing datadirs (with an optionnal subpath)
"""
for directory in self.config['datadir']:
fullpath = os.path.join(directory, subdir)
fullpath = os.path.join(directory, *subpath)
if os.path.isdir(fullpath):
yield fullpath
@ -255,7 +255,7 @@ class Song:
return self.search_file(
filename,
['', '.jpg', '.png'],
datadirs=self.get_datadirs('img'),
datadirs=self.iter_datadirs('img'),
)
def search_partition(self, filename):
@ -263,7 +263,7 @@ class Song:
return self.search_file(
filename,
['', '.ly'],
datadirs=self.get_datadirs('scores'),
datadirs=self.iter_datadirs('scores'),
)
def unprefixed_title(title, prefixes):

11
patacrep/songs/chordpro/__init__.py

@ -48,14 +48,9 @@ class ChordproSong(Song):
"content": self.cached['song'].content,
}
jinjaenv = Environment(loader=ChoiceLoader([
FileSystemLoader(
self.get_datadirs(os.path.join("templates", self.output_language))
),
FileSystemLoader(
pkg_datapath('ast_templates', 'chordpro', self.output_language)
),
]))
jinjaenv = Environment(loader=FileSystemLoader(
self.iter_datadirs("templates", "songs", "chordpro", self.output_language)
))
jinjaenv.filters['search_image'] = self.search_image
jinjaenv.filters['search_partition'] = self.search_partition
jinjaenv.filters['lang2babel'] = lang2babel

13
setup.py

@ -4,10 +4,14 @@
$ python setup.py install
"""
from patacrep import __version__
from patacrep import __version__, __DATADIR__, files
from setuptools import setup, find_packages
# List the data files
data_files = files.recursive_find(__DATADIR__)
data_files = ["data/" + d for d in data_files]
setup(
name='patacrep',
version=__version__,
@ -21,12 +25,7 @@ setup(
"unidecode", "jinja2", "chardet", "ply",
],
setup_requires=["hgtools"],
package_data={'patacrep': [
'data/ast_templates/*/*/*',
'data/img/*',
'data/latex/*',
'data/templates/*',
]},
package_data={'patacrep': data_files},
entry_points={
'console_scripts': [
"songbook = patacrep.songbook.__main__:main",

3
test/test_chordpro/test_parser.py

@ -7,7 +7,7 @@ import os
import unittest
from pkg_resources import resource_filename
from patacrep import files
from patacrep import files, __DATADIR__
from patacrep.build import DEFAULT_CONFIG
from patacrep.encoding import open_read
@ -41,6 +41,7 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest):
if 'datadir' not in cls.config:
cls.config['datadir'] = []
cls.config['datadir'].append(resource_filename(__name__, 'datadir'))
cls.config['datadir'].append(__DATADIR__)
cls.song_plugins = files.load_plugins(
datadirs=cls.config['datadir'],

Loading…
Cancel
Save