From 495656add176c8e6f7b11c88fba53b6454a1cc21 Mon Sep 17 00:00:00 2001 From: Alexandre Dupas Date: Sat, 20 Jun 2009 13:04:10 +0200 Subject: [PATCH] Add a python script that allows to build different volume. --- songbook-volume.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 songbook-volume.py diff --git a/songbook-volume.py b/songbook-volume.py new file mode 100755 index 00000000..0863e36f --- /dev/null +++ b/songbook-volume.py @@ -0,0 +1,40 @@ +#!/usr/bin/python +# + +import os.path +import glob + +def formatSongsDatabase( file, songs ): + sdb = open( file, 'w' ) + + dir = ['img']+map(os.path.dirname, songs) + dir = set( dir ) + sdb.write('\graphicspath{\n') + for dirname in dir: + sdb.write(' {{{imagedir}/}},\n'.format(imagedir=dirname)) + sdb.write('}\n') + for song in songs: + sdb.write('\input{{{songfile}}}\n'.format(songfile=song.strip())) + sdb.close(); + + +def main(): + songfiles = glob.glob('songs/*/*.sg') + + songvolumes = glob.glob('songs-volume-*') + + for volume in songvolumes: + songs = [] + vol = open( volume ) + for song in vol: + s = song.strip() + songs.append( s ) + songfiles.remove( s ) + vol.close() + formatSongsDatabase( 'db_'+volume+'.sdb', songs ) + + formatSongsDatabase( 'songs.sdb', songfiles ) + + +if __name__ == '__main__': + main()