Browse Source

Yield datadirs

pull/98/head
Oliverpool 9 years ago
parent
commit
e49ba05514
  1. 12
      patacrep/songs/__init__.py

12
patacrep/songs/__init__.py

@ -195,22 +195,19 @@ class Song:
raise NotImplementedError() raise NotImplementedError()
def get_datadirs(self, subdir=None): def get_datadirs(self, subdir=None):
"""Return a list of existing datadirs (with eventually a subdir) """Return an iterator of existing datadirs (with eventually a subdir)
""" """
directories = []
for directory in self.config['datadir']: for directory in self.config['datadir']:
fullpath = os.path.join(directory, subdir) fullpath = os.path.join(directory, subdir)
if os.path.isdir(fullpath): if os.path.isdir(fullpath):
directories.append(fullpath) yield fullpath
return directories
def search_file(self, filename, extensions=None, directories=None): def search_file(self, filename, extensions=None, directories=None):
"""Search for a file name. """Search for a file name.
:param str filename: The name, as provided in the chordpro file (with or without extension). :param str filename: The name, as provided in the chordpro file (with or without extension).
:param list extensions: Possible extensions (with '.') :param list extensions: Possible extensions (with '.')
:param list directories: Other directories where to search for the file :param iterator directories: Other directories where to search for the file
The directory where the Song file is stored is added to the list. The directory where the Song file is stored is added to the list.
Returns None if nothing found. Returns None if nothing found.
@ -221,9 +218,8 @@ class Song:
directories = [] directories = []
songdir = os.path.dirname(self.fullpath) songdir = os.path.dirname(self.fullpath)
directories.insert(0, songdir)
for directory in directories: for directory in [songdir] + list(directories):
for extension in extensions: for extension in extensions:
fullpath = os.path.join(directory, filename + extension) fullpath = os.path.join(directory, filename + extension)
if os.path.isfile(fullpath): if os.path.isfile(fullpath):

Loading…
Cancel
Save