From 2b8876d82496bbb9c141f17d22aa00012ff8e400 Mon Sep 17 00:00:00 2001 From: Alexandre Dupas Date: Tue, 11 Aug 2009 15:44:44 +0200 Subject: [PATCH] Support Debian stable python version 2.5 (at least) Support str.format() (new in 2.6) as well as % (modulo) operator for string formatting. This enhances the compatibility of the script with earlier version of python (such as python 2.5 which is the current Debian's python interpreter). --- songbook-volume.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/songbook-volume.py b/songbook-volume.py index b6a4c28f..abaa4c14 100755 --- a/songbook-volume.py +++ b/songbook-volume.py @@ -11,11 +11,20 @@ def formatSongsDatabase( file, songs ): 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())) + if sys.hexversion >= 0x20600000: + # use string format introduced in python 2.6 + 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())) + else: + # use old formating strategy + for dirname in dir: + sdb.write(' {%(imagedir)s/},\n' % {'imagedir':dirname}) + sdb.write('}\n') + for song in songs: + sdb.write('\input{%(songfile)s}\n' % {'songfile':song.strip()}) sdb.close();