From e49ba0551449a2f34affabc02886144bc3ebcef1 Mon Sep 17 00:00:00 2001 From: Oliverpool Date: Fri, 18 Sep 2015 17:21:04 +0200 Subject: [PATCH] Yield datadirs --- patacrep/songs/__init__.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/patacrep/songs/__init__.py b/patacrep/songs/__init__.py index 6fd03582..b59883be 100644 --- a/patacrep/songs/__init__.py +++ b/patacrep/songs/__init__.py @@ -195,22 +195,19 @@ class Song: raise NotImplementedError() 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']: fullpath = os.path.join(directory, subdir) if os.path.isdir(fullpath): - directories.append(fullpath) - return directories + yield fullpath def search_file(self, filename, extensions=None, directories=None): """Search for a file name. :param str filename: The name, as provided in the chordpro file (with or without extension). :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. Returns None if nothing found. @@ -221,9 +218,8 @@ class Song: directories = [] songdir = os.path.dirname(self.fullpath) - directories.insert(0, songdir) - for directory in directories: + for directory in [songdir] + list(directories): for extension in extensions: fullpath = os.path.join(directory, filename + extension) if os.path.isfile(fullpath):