Browse Source

use recursive find method to get song and cover files

With this, the songs hierarchy in the library can be different from songs/author/song.sg
remotes/origin/HEAD
spalax 11 years ago
committed by Romain Goffe
parent
commit
b0ae14852e
  1. 9
      songbook.py
  2. 0
      utils/__init__.py
  3. 5
      utils/resize-cover.py
  4. 4
      utils/rules.py
  5. 5
      utils/songbook-gtab.py
  6. 13
      utils/utils.py

9
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\\{)(.(?<!\\}]))+')
reArtist = re.compile('(?<=by=)(.(?<![,\\]\\}]))+')
reAlbum = re.compile('(?<=album=)(.(?<![,\\]\\}]))+')
@ -41,7 +42,7 @@ def makeCoverCache(library):
os.makedirs(cachePath)
# copy pictures file into the cache directory
covers = glob.glob(library + 'songs/*/*.jpg')
covers = recursiveFind(os.path.join(library, 'songs'), '*.jpg')
for cover in covers:
coverPath = os.path.join(cachePath, os.path.basename(cover))
shutil.copy(cover, coverPath)
@ -148,7 +149,7 @@ def makeTexFile(sb, library, output):
out.write(formatDefinition(name, toValue(parameters[name],value)))
# output songslist
if songs == "all":
songs = map(lambda x: x[len(library) + 6:], glob.glob(library + 'songs/*/*.sg'))
songs = map(lambda x: x[len(library) + 6:], recursiveFind(os.path.join(library, 'songs'), '*.sg'))
if len(songs) > 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"])

0
utils/__init__.py

5
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)

4
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:

5
utils/songbook-gtab.py

@ -2,9 +2,9 @@
#
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,8 +26,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):
result = gtabPattern.match(line)

13
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
Loading…
Cancel
Save