From 3c1582bdf989e49bfd62826363beb2cc076fdef8 Mon Sep 17 00:00:00 2001 From: Louis Date: Sat, 9 Mar 2013 01:57:33 +0100 Subject: [PATCH] =?UTF-8?q?Correction=20:=20Tri=20des=20chansons=20en=20pr?= =?UTF-8?q?enant=20compte=20des=20pr=C3=A9fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- songbook.py | 24 +++++++++++++++++++++--- templates/minimal.tmpl | 5 ++++- templates/patacrep.tmpl | 5 ++++- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/songbook.py b/songbook.py index f443947b..aeb404ee 100755 --- a/songbook.py +++ b/songbook.py @@ -49,7 +49,17 @@ def makeCoverCache(library): def matchRegexp(reg, iterable): return [ m.group(1) for m in (reg.match(l) for l in iterable) if m ] -def songslist(library, songs): +def unprefixed(title, prefixes): + """Remove the first prefix of the list in the beginning of title (if any). + """ + for prefix in prefixes: + match = re.compile(r"^(%s)\b\s*(.*)$" % prefix).match(title) + if match: + return match.group(2) + return title + + +def songslist(library, songs, prefixes): song_objects = [] for s in songs: path = library + 'songs/' + s @@ -64,7 +74,7 @@ def songslist(library, songs): album = '' 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(unprefixed(x.title, prefixes))) song_objects = sorted(song_objects, key=lambda x: locale.strxfrm(x.album)) song_objects = sorted(song_objects, key=lambda x: locale.strxfrm(x.artist)) @@ -121,6 +131,8 @@ def makeTexFile(sb, library, output): # default value template = "patacrep.tmpl" songs = [] + titleprefixwords = "" + prefixes = [] # parse the songbook data if "template" in sb: @@ -129,6 +141,12 @@ def makeTexFile(sb, library, output): if "songs" in sb: songs = sb["songs"] del sb["songs"] + if "titleprefixwords" in sb: + prefixes = sb["titleprefixwords"] + for prefix in sb["titleprefixwords"]: + titleprefixwords += "\\titleprefixword{%s}\n" % prefix + sb["titleprefixwords"] = titleprefixwords + parameters = parseTemplate("templates/"+template) @@ -151,7 +169,7 @@ def makeTexFile(sb, library, output): songs = map(lambda x: x[len(library) + 6:], glob.glob(library + 'songs/*/*.sg')) if len(songs) > 0: - out.write(formatDefinition('songslist', songslist(library, songs))) + out.write(formatDefinition('songslist', songslist(library, songs, prefixes))) out.write('\\makeatother\n') # output template diff --git a/templates/minimal.tmpl b/templates/minimal.tmpl index 3bdcd58a..770641e6 100644 --- a/templates/minimal.tmpl +++ b/templates/minimal.tmpl @@ -29,7 +29,8 @@ %%: {"name":"lang", "description":"Language", "default":"english"}, %%: {"name":"instruments", "description":"Instruments", "type":"flag", "values":["guitar","ukulele"], "join":",", "mandatory":true, "default":["guitar"]}, %%: {"name":"bookoptions", "description":"Options", "type":"flag", "values":["diagram","importantdiagramonly","lilypond","pictures","tabs","repeatchords","onesongperpage"], "join":",", "mandatory":true, "default":["pictures"]}, -%%: {"name":"mainfontsize", "description":"Font Size", "type":"font", "default":"10"} +%%: {"name":"mainfontsize", "description":"Font Size", "type":"font", "default":"10"}, +%%: {"name":"titleprefixwords", "description":"Ignore some words in the beginning of song titles"} %%:] %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % begin document @@ -49,6 +50,8 @@ \fi% } +\gettitleprefixwords + \nosongnumbers \pagestyle{empty} diff --git a/templates/patacrep.tmpl b/templates/patacrep.tmpl index 9b78917b..9ca68eae 100644 --- a/templates/patacrep.tmpl +++ b/templates/patacrep.tmpl @@ -42,7 +42,8 @@ %%: {"name":"mainfontsize", "description":"Font Size", "type":"font", "default":"10"}, %%: {"name":"songnumberbgcolor", "description":"Number Shade", "type":"color", "default":"#D1E4AE"}, %%: {"name":"notebgcolor", "description":"Note Shade", "type":"color", "default":"#D1E4AE"}, -%%: {"name":"indexbgcolor", "description":"Index Shade", "type":"color", "default":"#D1E4AE"} +%%: {"name":"indexbgcolor", "description":"Index Shade", "type":"color", "default":"#D1E4AE"}, +%%: {"name":"titleprefixwords", "description":"Ignore some words in the beginning of song titles"} %%:] %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % begin document @@ -84,6 +85,8 @@ \renewcommand{\notebgcolor}{NoteBgColor} \renewcommand{\idxbgcolor}{IndexBgColor} +\gettitleprefixwords + \pagestyle{empty} \begin{document}