From 2b4a213086c9313fff59e031d435326fe2bb144b Mon Sep 17 00:00:00 2001 From: Louis Date: Fri, 8 Mar 2013 22:51:38 +0100 Subject: [PATCH] =?UTF-8?q?Correction=20bug=20:=20trouver=20r=C3=A9cursive?= =?UTF-8?q?ment=20les=20fichiers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- songbook.py | 9 +++++---- utils/__init__.py | 0 utils/resize-cover.py | 5 +++-- utils/rules.py | 4 +++- utils/songbook-gtab.py | 5 +++-- utils/utils.py | 13 +++++++++++++ 6 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 utils/__init__.py create mode 100644 utils/utils.py diff --git a/songbook.py b/songbook.py index f443947b..41b4b3df 100755 --- a/songbook.py +++ b/songbook.py @@ -4,7 +4,6 @@ import getopt, sys import os.path -import glob import re import json import locale @@ -12,6 +11,8 @@ import shutil import locale import platform +from utils.utils import recursiveFind + reTitle = re.compile('(?<=beginsong\\{)(.(? 0: out.write(formatDefinition('songslist', songslist(library, songs))) @@ -184,7 +185,7 @@ def makeDepend(sb, library, output): # check for deps (in sb data) deps = []; if sb["songs"] == "all": - deps += glob.glob(library + 'songs/*/*.sg') + deps += recursiveFind(os.path.join(library, 'songs'), '*.sg') else: deps += map(lambda x: library + "songs/" + x, sb["songs"]) diff --git a/utils/__init__.py b/utils/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/utils/resize-cover.py b/utils/resize-cover.py index c7f9daf3..21964487 100755 --- a/utils/resize-cover.py +++ b/utils/resize-cover.py @@ -6,10 +6,11 @@ #Description: Resize all covers to 128,128 thumbnails import Image -import glob + +from utils.utils import recursiveFind # Process song files -covers = glob.glob('songs/*/*.jpg') +covers = recursiveFind(os.path.join(library, 'songs'), '*.jpg') for filename in covers: source = Image.open(filename) diff --git a/utils/rules.py b/utils/rules.py index b1dfbb11..52b6e0b3 100755 --- a/utils/rules.py +++ b/utils/rules.py @@ -8,6 +8,8 @@ import logging import locale re.LOCALE +from utils.utils import recursiveFind + # the dictionary has target_word:replacement_word pairs word_dic = { ##: oe inclusion @@ -236,7 +238,7 @@ def main(): usage() sys.exit(2) - songfiles = glob.glob('songs/*/*.sg') + songfiles = recursiveFind(os.path.join(library, 'songs'), '*.sg') loglevel = "warning" for option, arg in opts: diff --git a/utils/songbook-gtab.py b/utils/songbook-gtab.py index 3a67355c..c89411e8 100755 --- a/utils/songbook-gtab.py +++ b/utils/songbook-gtab.py @@ -2,10 +2,11 @@ # import sys -import glob import re from optparse import OptionParser +from utils.utils import recursiveFind + # Pattern set to ignore latex command in title prefix gtabPattern = re.compile(r"\\gtab\{(.*)\}\{(.*)\}"); @@ -26,7 +27,7 @@ def main(): chords = dict() positions = dict() - songfiles = glob.glob('songs/*/*.sg') + songfiles = recursiveFind(os.path.join(library, 'songs'), '*.sg') for file in songfiles: for line in open(file): diff --git a/utils/utils.py b/utils/utils.py new file mode 100644 index 00000000..576c66b2 --- /dev/null +++ b/utils/utils.py @@ -0,0 +1,13 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# + +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