Browse Source

Fix indentation

original/refs/heads/split-songs
Alexandre Dupas 12 years ago
parent
commit
cb6ee6097d
  1. 86
      songbook.py

86
songbook.py

@ -16,13 +16,13 @@ reArtist = re.compile('(?<=by=)(.(?<![,\\]\\}]))+')
reAlbum = re.compile('(?<=album=)(.(?<![,\\]\\}]))+') reAlbum = re.compile('(?<=album=)(.(?<![,\\]\\}]))+')
class Song: class Song:
def __init__(self, title, artist, album, path): def __init__(self, title, artist, album, path):
self.title = title self.title = title
self.artist = artist self.artist = artist
self.album = album self.album = album
self.path = path self.path = path
def __repr__(self): def __repr__(self):
return repr((self.title, self.artist, self.album, self.path)) return repr((self.title, self.artist, self.album, self.path))
from xdg.BaseDirectory import * from xdg.BaseDirectory import *
@ -35,44 +35,44 @@ print 'xdg_cache_home: %s' % xdg_cache_home
songbook_cache_home = os.path.join(xdg_cache_home, 'songbook') songbook_cache_home = os.path.join(xdg_cache_home, 'songbook')
def makeCoverCache(cachePath): def makeCoverCache(cachePath):
''' '''
Copy all pictures found in the libraries into a unique cache Copy all pictures found in the libraries into a unique cache
folder. folder.
''' '''
# create the cache directory if it does not exist # create the cache directory if it does not exist
if not os.path.exists(cachePath): if not os.path.exists(cachePath):
os.makedirs(cachePath) os.makedirs(cachePath)
# copy pictures file into the cache directory # copy pictures file into the cache directory
covers = glob.glob('songs/*/*.jpg') covers = glob.glob('songs/*/*.jpg')
for cover in covers: for cover in covers:
coverPath = os.path.join(cachePath, os.path.basename(cover)) coverPath = os.path.join(cachePath, os.path.basename(cover))
shutil.copy(cover, coverPath) shutil.copy(cover, coverPath)
def matchRegexp(reg, iterable): def matchRegexp(reg, iterable):
return [ m.group(1) for m in (reg.match(l) for l in iterable) if m ] return [ m.group(1) for m in (reg.match(l) for l in iterable) if m ]
def songslist(songs): def songslist(songs):
song_objects = [] song_objects = []
for s in songs: for s in songs:
path = 'songs/'+s path = 'songs/'+s
with open(path, 'r+') as f: with open(path, 'r+') as f:
data = f.read() data = f.read()
title = reTitle.search(data).group(0) title = reTitle.search(data).group(0)
artist = reArtist.search(data.replace("{","")).group(0) artist = reArtist.search(data.replace("{","")).group(0)
match = reAlbum.search(data.replace("{","")) match = reAlbum.search(data.replace("{",""))
if match: if match:
album = match.group(0) album = match.group(0)
else: else:
album = '' album = ''
song_objects.append(Song(title, artist, album, path)) song_objects.append(Song(title, artist, album, path))
song_objects = sorted(song_objects, key=lambda x: locale.strxfrm(x.title)) song_objects = sorted(song_objects, key=lambda x: locale.strxfrm(x.title))
song_objects = sorted(song_objects, key=lambda x: locale.strxfrm(x.album)) song_objects = sorted(song_objects, key=lambda x: locale.strxfrm(x.album))
song_objects = sorted(song_objects, key=lambda x: locale.strxfrm(x.artist)) song_objects = sorted(song_objects, key=lambda x: locale.strxfrm(x.artist))
result = [ '\\input{{{0}}}'.format(song.path.replace("\\","/").strip()) for song in song_objects ] result = [ '\\input{{{0}}}'.format(song.path.replace("\\","/").strip()) for song in song_objects ]
return '\n'.join(result) return '\n'.join(result)
def parseTemplate(template): def parseTemplate(template):
embeddedJsonPattern = re.compile(r"^%%:") embeddedJsonPattern = re.compile(r"^%%:")
@ -151,7 +151,7 @@ def makeTexFile(sb, output):
out.write(formatDefinition(name, toValue(parameters[name],value))) out.write(formatDefinition(name, toValue(parameters[name],value)))
# output songslist # output songslist
if songs == "all": if songs == "all":
songs = map(lambda x: x[6:], glob.glob('songs/*/*.sg')) songs = map(lambda x: x[6:], glob.glob('songs/*/*.sg'))
if len(songs) > 0: if len(songs) > 0:
out.write(formatDefinition('songslist', songslist(songs))) out.write(formatDefinition('songslist', songslist(songs)))
@ -228,7 +228,7 @@ def main():
usage() usage()
sys.exit() sys.exit()
elif o in ("--cache"): elif o in ("--cache"):
cache = True cache = True
elif o in ("-s", "--songbook"): elif o in ("-s", "--songbook"):
songbook = a songbook = a
elif o in ("-d", "--depend"): elif o in ("-d", "--depend"):
@ -239,7 +239,7 @@ def main():
assert False, "unhandled option" assert False, "unhandled option"
if cache: if cache:
makeCoverCache(os.path.join(songbook_cache_home, 'images')) makeCoverCache(os.path.join(songbook_cache_home, 'images'))
elif songbook and output: elif songbook and output:
f = open(songbook) f = open(songbook)
sb = json.load(f) sb = json.load(f)

Loading…
Cancel
Save