From 474cb72c35bdfbeeb46f6d06e0c0f5e6e72c8eab Mon Sep 17 00:00:00 2001 From: Romain Goffe Date: Sun, 11 Sep 2011 18:54:55 +0200 Subject: [PATCH] fix typos; add replace cases; handle spaces in strings --- songbook.py | 4 ++-- title_sort.py | 22 +++++++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/songbook.py b/songbook.py index 3cec5929..f4a09cf6 100755 --- a/songbook.py +++ b/songbook.py @@ -8,7 +8,7 @@ import glob import re import json import locale -import titlesort +import title_sort def matchRegexp(reg, iterable): return [ m.group(1) for m in (reg.match(l) for l in iterable) if m ] @@ -96,8 +96,8 @@ def makeTexFile(sb, output): # output songslist if songs == "all": songs = map(lambda x: x[6:], glob.glob('songs/*/*.sg')) - songs.sort(key=title_sort.sortkey) + songs.sort(key=title_sort.sortkey) if len(songs) > 0: out.write(formatDefinition('songslist', songslist(songs))) out.write('\\makeatother\n') diff --git a/title_sort.py b/title_sort.py index af4743e8..344b02bb 100644 --- a/title_sort.py +++ b/title_sort.py @@ -7,10 +7,22 @@ import locale iecPattern = re.compile(r"\IeC {\\(.*?)}") replacePattern = { '`A': 'À', - 'oe ': 'œ', + '`a': 'à', + '^a': 'â', + 'oe': 'œ', "'e" : 'é', + "`e" : 'è', + "^e" : 'ê', + '"e' : 'ë', + "'E" : 'É', + "`E" : 'È', "'o" : 'ó', - "c C" : 'ç', + "^o" : 'ô', + r'"\i' : 'i', + r'^\i' : 'i', + '"u' : 'ü', + "c C" : 'Ç', + "c c" : 'ç', } def sortkey(value): @@ -22,8 +34,8 @@ def sortkey(value): ''' def repl(match): try: - return replacePattern[match.group(1)] + return replacePattern[match.group(1).strip()] except KeyError: - warnings.warn("Error, no match to replace %s in %s. You should add it in the coresponding table in title_solt.py" % (match.group(0), match.group(1))) + warnings.warn("Error, no match to replace %s in %s. You should add it in the coresponding table in title_sort.py" % (match.group(0), match.group(1))) - return locale.strxfrm(iecPattern.sub(repl, value)) + return locale.strxfrm(iecPattern.sub(repl, value).replace(' ', 'A'))