mirror of https://github.com/patacrep/patacrep.git
Louis
11 years ago
6 changed files with 78 additions and 38 deletions
@ -1,23 +0,0 @@ |
|||
def __cmp__(self, other): |
|||
if not isinstance(other, Song): |
|||
return NotImplemented |
|||
for key in self.sort: |
|||
if key == "@title": |
|||
self_key = self.normalized_titles |
|||
other_key = other.normalized_titles |
|||
elif key == "@path": |
|||
self_key = locale.strxfrm(self.path) |
|||
other_key = locale.strxfrm(other.path) |
|||
elif key == "by": |
|||
self_key = self.normalized_authors |
|||
other_key = other.normalized_authors |
|||
else: |
|||
self_key = locale.strxfrm(self.args.get(key, "")) |
|||
other_key = locale.strxfrm(other.args.get(key, "")) |
|||
|
|||
if self_key < other_key: |
|||
return -1 |
|||
elif self_key > other_key: |
|||
return 1 |
|||
return 0 |
|||
|
@ -0,0 +1,36 @@ |
|||
#!/usr/bin/env python |
|||
# -*- coding: utf-8 -*- |
|||
|
|||
import locale |
|||
|
|||
from songbook_core.content.song import OnlySongsError, process_songs |
|||
|
|||
DEFAULT_SORT = ['by', 'album', '@title'] |
|||
|
|||
def key_generator(sort): |
|||
def ordered_song_keys(song): |
|||
songkey = [] |
|||
for key in sort: |
|||
if key == "@title": |
|||
songkey.append(song.normalized_titles) |
|||
elif key == "@path": |
|||
songkey.append(locale.strxfrm(song.path)) |
|||
elif key == "by": |
|||
songkey.append(song.normalized_authors) |
|||
else: |
|||
songkey.append(locale.strxfrm(song.args.get(key, ""))) |
|||
return songkey |
|||
return ordered_song_keys |
|||
|
|||
def parse(keyword, config, argument, contentlist): |
|||
if argument: |
|||
sort = [key.strip() for key in argument.split(",")] |
|||
else: |
|||
sort = DEFAULT_SORT |
|||
try: |
|||
songlist = process_songs(contentlist, config) |
|||
except OnlySongsError as error: |
|||
raise ContentError(keyword, "Content list of this keyword can bo only songs (or content that result into songs), and the following are not:" + str(error.not_songs)) |
|||
return sorted(songlist, key=key_generator(sort)) |
|||
|
|||
CONTENT_PLUGINS = {'sorted': parse} |
Loading…
Reference in new issue