From 1f6801b54bf3c3bc7ac368524aa44d6b9f56b9da Mon Sep 17 00:00:00 2001 From: Louis Date: Thu, 22 Oct 2015 00:15:01 +0200 Subject: [PATCH] Sub-datadir (img and score) must be explicitely set --- examples/datadir2/{img => scores}/datadir2.ly | 0 examples/{img => scores}/datadir.ly | 0 examples/songs/subdir/datadir.sg | 6 ++--- examples/songs/subdir/datadir2.sg | 6 ++--- patacrep/data/templates/patacrep.tex | 2 +- patacrep/data/templates/songs.tex | 2 +- patacrep/songs/__init__.py | 2 +- patacrep/songs/chordpro/__init__.py | 25 ++++++++++++++----- 8 files changed, 28 insertions(+), 15 deletions(-) rename examples/datadir2/{img => scores}/datadir2.ly (100%) rename examples/{img => scores}/datadir.ly (100%) diff --git a/examples/datadir2/img/datadir2.ly b/examples/datadir2/scores/datadir2.ly similarity index 100% rename from examples/datadir2/img/datadir2.ly rename to examples/datadir2/scores/datadir2.ly diff --git a/examples/img/datadir.ly b/examples/scores/datadir.ly similarity index 100% rename from examples/img/datadir.ly rename to examples/scores/datadir.ly diff --git a/examples/songs/subdir/datadir.sg b/examples/songs/subdir/datadir.sg index 18e92c3d..933e208b 100644 --- a/examples/songs/subdir/datadir.sg +++ b/examples/songs/subdir/datadir.sg @@ -1,10 +1,10 @@ \beginsong{Image included from datadir\\\LaTeX} - [cov={datadir}] + [cov={img/datadir}] \cover - \lilypond{datadir.ly} + \lilypond{scores/datadir.ly} - \image{datadir} + \image{img/datadir} \endsong diff --git a/examples/songs/subdir/datadir2.sg b/examples/songs/subdir/datadir2.sg index f5bad860..6a805725 100644 --- a/examples/songs/subdir/datadir2.sg +++ b/examples/songs/subdir/datadir2.sg @@ -1,10 +1,10 @@ \beginsong{Image included from a different datadir\\\LaTeX} - [cov={datadir2}] + [cov={img/datadir2}] \cover - \lilypond{datadir2.ly} + \lilypond{scores/datadir2.ly} - \image{datadir2} + \image{img/datadir2} \endsong diff --git a/patacrep/data/templates/patacrep.tex b/patacrep/data/templates/patacrep.tex index 96367078..50dacf5e 100644 --- a/patacrep/data/templates/patacrep.tex +++ b/patacrep/data/templates/patacrep.tex @@ -34,7 +34,7 @@ }, "picture": {"description": {"english": "Cover picture", "french": "Image de couverture"}, "type": "file", - "default": {"default": "treble_a"} + "default": {"default": "img/treble_a"} }, "picturecopyright": {"description": {"english": "Copyright for the cover picture", "french": "Copyright pour l'image de couverture"}, "default": {"default": "Dbolton \\url{http://commons.wikimedia.org/wiki/User:Dbolton}"} diff --git a/patacrep/data/templates/songs.tex b/patacrep/data/templates/songs.tex index 957e610e..741b5d39 100644 --- a/patacrep/data/templates/songs.tex +++ b/patacrep/data/templates/songs.tex @@ -89,7 +89,7 @@ \usepackage{graphicx} \graphicspath{ % (* for dir in datadir *) - {(( path2posix(dir) ))/img/} % + {(( path2posix(dir) ))/} % (* endfor *) } diff --git a/patacrep/songs/__init__.py b/patacrep/songs/__init__.py index e8a91fa3..129c8045 100644 --- a/patacrep/songs/__init__.py +++ b/patacrep/songs/__init__.py @@ -263,7 +263,7 @@ class Song: return self.search_file( filename, ['', '.ly'], - datadirs=self.get_datadirs('img'), + datadirs=self.get_datadirs('scores'), ) def unprefixed_title(title, prefixes): diff --git a/patacrep/songs/chordpro/__init__.py b/patacrep/songs/chordpro/__init__.py index c5b80888..c46a0880 100644 --- a/patacrep/songs/chordpro/__init__.py +++ b/patacrep/songs/chordpro/__init__.py @@ -93,16 +93,29 @@ class Chordpro2LatexSong(ChordproSong): output_language = "latex" def search_file(self, filename, extensions=None, *, datadirs=None): + _datadir, filename, _extension = self.search_datadir_file( + filename, + extensions, + datadirs, + ) + return filename + + def search_partition(self, filename): try: - _datadir, filename, _extension = self.search_datadir_file( - filename, - extensions, - datadirs, + return os.path.join("scores", super().search_partition(filename)) + except FileNotFoundError: + LOGGER.warning( + "Song '%s' (datadir '%s'): Score '%s' not found.", + self.subpath, self.datadir, filename, ) - return filename + return None + + def search_image(self, filename): + try: + return os.path.join("img", super().search_image(filename)) except FileNotFoundError: LOGGER.warning( - "Song '%s' (datadir '%s'): File '%s' not found.", + "Song '%s' (datadir '%s'): Image '%s' not found.", self.subpath, self.datadir, filename, ) return None