|
@ -194,28 +194,6 @@ class Song: |
|
|
""" |
|
|
""" |
|
|
raise NotImplementedError() |
|
|
raise NotImplementedError() |
|
|
|
|
|
|
|
|
def get_cover_fullpath(self, datadir, default=None): |
|
|
|
|
|
"""Return the fullpath of the cover file if found""" |
|
|
|
|
|
filename = str(self.data.get('cov', '')) |
|
|
|
|
|
if not filename: |
|
|
|
|
|
return default |
|
|
|
|
|
|
|
|
|
|
|
# Temporary hack: what should it contain exactly? |
|
|
|
|
|
config = { |
|
|
|
|
|
'datadir': datadir, |
|
|
|
|
|
'filename': '', |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
extensions = ['', '.jpg', '.png'] |
|
|
|
|
|
for extension in extensions: |
|
|
|
|
|
fullpath = search_image(filename + extension, self.fullpath, config) |
|
|
|
|
|
if fullpath: |
|
|
|
|
|
return fullpath |
|
|
|
|
|
|
|
|
|
|
|
# How to handle when the cover should have been there ? |
|
|
|
|
|
# raise FileNotFoundError() |
|
|
|
|
|
return default |
|
|
|
|
|
|
|
|
|
|
|
def get_datadirs(self, subdir=None): |
|
|
def get_datadirs(self, subdir=None): |
|
|
"""Return a list of existing datadirs (with eventually a subdir) |
|
|
"""Return a list of existing datadirs (with eventually a subdir) |
|
|
""" |
|
|
""" |
|
@ -258,6 +236,15 @@ class Song: |
|
|
filepath = self.search_file(filename, ['', '.jpg', '.png'], datadir_img) |
|
|
filepath = self.search_file(filename, ['', '.jpg', '.png'], datadir_img) |
|
|
return filepath if filepath else filename |
|
|
return filepath if filepath else filename |
|
|
|
|
|
|
|
|
|
|
|
@property |
|
|
|
|
|
def cover_filepath(self): |
|
|
|
|
|
"""Get the path to the cover file (or None if not found)""" |
|
|
|
|
|
filename = str(self.data.get('cov', '')) |
|
|
|
|
|
if not filename: |
|
|
|
|
|
return None |
|
|
|
|
|
datadir_img = self.get_datadirs('img') |
|
|
|
|
|
return self.search_file(filename, ['', '.jpg', '.png'], datadir_img) |
|
|
|
|
|
|
|
|
def search_partition(self, filename): |
|
|
def search_partition(self, filename): |
|
|
"""Search for a lilypond file""" |
|
|
"""Search for a lilypond file""" |
|
|
filepath = self.search_file(filename, ['', '.ly']) |
|
|
filepath = self.search_file(filename, ['', '.ly']) |
|
@ -271,39 +258,3 @@ def unprefixed_title(title, prefixes): |
|
|
if match: |
|
|
if match: |
|
|
return match.group(2) |
|
|
return match.group(2) |
|
|
return title |
|
|
return title |
|
|
|
|
|
|
|
|
def search_image(image, chordprofile, config, default=None): |
|
|
|
|
|
"""Return the file name of an image, so that LaTeX will find it. |
|
|
|
|
|
|
|
|
|
|
|
:param str image: The name, as provided in the chordpro file. |
|
|
|
|
|
:param str chordprofile: The name of the file including this image. |
|
|
|
|
|
:param dict config: Songbook configuration dictionary. |
|
|
|
|
|
|
|
|
|
|
|
The image can be: |
|
|
|
|
|
|
|
|
|
|
|
- in the same directory as the including song file; |
|
|
|
|
|
- in the same directory as the main LaTeX file; |
|
|
|
|
|
- in some of the `DATADIR/img` directories. |
|
|
|
|
|
|
|
|
|
|
|
If image is not found, the `image` argument is returned. |
|
|
|
|
|
""" |
|
|
|
|
|
# Image is in the same folder as its song |
|
|
|
|
|
texdir = os.path.dirname(chordprofile) |
|
|
|
|
|
if os.path.exists(os.path.join(texdir, image)): |
|
|
|
|
|
return os.path.join(texdir, image) |
|
|
|
|
|
|
|
|
|
|
|
# Image is in the same directory as the main tex file |
|
|
|
|
|
rootdir = os.path.dirname(os.path.join( |
|
|
|
|
|
os.getcwd(), |
|
|
|
|
|
config['filename'], |
|
|
|
|
|
)) |
|
|
|
|
|
if os.path.exists(os.path.join(rootdir, image)): |
|
|
|
|
|
return image |
|
|
|
|
|
|
|
|
|
|
|
# Image is in a datadir |
|
|
|
|
|
for directory in config['datadir']: |
|
|
|
|
|
if os.path.exists(os.path.join(directory, 'img', image)): |
|
|
|
|
|
return os.path.join(directory, 'img', image) |
|
|
|
|
|
|
|
|
|
|
|
# Could not find image |
|
|
|
|
|
return default |
|
|
|
|
|