diff --git a/songbook/build.py b/songbook/build.py index f4c16869..31263307 100644 --- a/songbook/build.py +++ b/songbook/build.py @@ -142,20 +142,18 @@ def makeTexFile(sb, library, output, core_dir): # output template commentPattern = re.compile(r"^\s*%") - f = open(template_dir+template) - content = [ line for line in f if not commentPattern.match(line) ] + with open(template_dir+template) as f: + content = [ line for line in f if not commentPattern.match(line) ] - for index, line in enumerate(content): - if re.compile("getLibraryImgDirectory").search(line): - line = line.replace("\\getLibraryImgDirectory", core_dir + "img/") - content[index] = line - if re.compile("getLibraryLilypondDirectory").search(line): - line = line.replace("\\getLibraryLilypondDirectory", core_dir + "lilypond/") - content[index] = line + for index, line in enumerate(content): + if re.compile("getLibraryImgDirectory").search(line): + line = line.replace("\\getLibraryImgDirectory", core_dir + "img/") + content[index] = line + if re.compile("getLibraryLilypondDirectory").search(line): + line = line.replace("\\getLibraryLilypondDirectory", core_dir + "lilypond/") + content[index] = line - f.close() out.write(''.join(content)) - out.close() def buildsongbook(sb, basename, library): @@ -172,7 +170,6 @@ def buildsongbook(sb, basename, library): CORE_DIR = MOD_DIR + '/../' texFile = basename + ".tex" - pdfFile = basename + ".pdf" # Make TeX file makeTexFile(sb, library, texFile, CORE_DIR) diff --git a/songbook/files.py b/songbook/files.py index d708bc49..f29bbd63 100644 --- a/songbook/files.py +++ b/songbook/files.py @@ -6,9 +6,9 @@ import fnmatch import os def recursiveFind(root_directory, pattern): - matches = [] - for root, dirnames, filenames in os.walk(root_directory): - for filename in fnmatch.filter(filenames, pattern): - matches.append(os.path.join(root, filename)) - return matches + matches = [] + for root, dirnames, filenames in os.walk(root_directory): + for filename in fnmatch.filter(filenames, pattern): + matches.append(os.path.join(root, filename)) + return matches