Browse Source

"File not found" errors are now stored into the list of songbook errors

pull/176/head
Louis 9 years ago
parent
commit
5c471af26d
  1. 15
      patacrep/songs/chordpro/__init__.py
  2. 7
      patacrep/songs/errors.py

15
patacrep/songs/chordpro/__init__.py

@ -11,6 +11,7 @@ import jinja2
from patacrep import encoding, files, pkg_datapath
from patacrep.songs import Song
from patacrep.songs.chordpro.syntax import parse_song
from patacrep.songs.errors import FileNotFound
from patacrep.templates import Renderer
from patacrep.latex import lang2babel, UnknownLanguage
from patacrep.files import path2posix
@ -113,20 +114,22 @@ class Chordpro2LatexSong(ChordproSong):
try:
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,
message = "Song '{}' (datadir '{}'): Score '{}' not found.".format(
self.subpath, self.datadir, filename
)
self.errors.append(FileNotFound(self, filename))
LOGGER.warning(message)
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'): Image '%s' not found.",
self.subpath, self.datadir, filename,
message = "Song '{}' (datadir '{}'): Image '{}' not found.".format(
self.subpath, self.datadir, filename
)
self.errors.append(FileNotFound(self, filename))
LOGGER.warning(message)
return None
def _jinja2_filters(self):

7
patacrep/songs/errors.py

@ -29,5 +29,8 @@ class SongSyntaxError(SongError):
else:
return "Song {}: {}".format(self.song, self.message)
# class FileError(SongError):
# type = "file"
class FileNotFound(SongError):
"""File not found error"""
def __init__(self, song, filename):
super().__init__(song, "File '{}' not found.".format(filename))

Loading…
Cancel
Save