From 2e12374e27b543b23309b2f8a0c4b848bc3bc5fd Mon Sep 17 00:00:00 2001 From: Louis Date: Tue, 17 Jun 2014 09:59:47 +0200 Subject: [PATCH] Ajout d'un message en cas de clef de tri incorrecte --- songbook_core/content/sorted.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/songbook_core/content/sorted.py b/songbook_core/content/sorted.py index e7283f09..4873cb3c 100644 --- a/songbook_core/content/sorted.py +++ b/songbook_core/content/sorted.py @@ -8,10 +8,14 @@ to a songbook. """ import locale +import logging +import os from songbook_core.content import ContentError from songbook_core.content.song import OnlySongsError, process_songs +LOGGER = logging.getLogger(__name__) + DEFAULT_SORT = ['by', 'album', '@title'] def normalize_string(string): @@ -49,7 +53,16 @@ def key_generator(sort): elif key == "by": field = song.authors else: - field = song.args.get(key, "") + try: + field = song.args[key] + except KeyError: + LOGGER.debug( + "Ignoring non-existent key '{}' for song {}.".format( + key, + os.path.relpath(song.path), + ) + ) + field = "" songkey.append(normalize_field(field)) return songkey return ordered_song_keys