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

7
patacrep/songs/errors.py

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

Loading…
Cancel
Save