diff --git a/songbook_core/content/sorted.TODO b/songbook_core/content/sorted.TODO new file mode 100644 index 00000000..2fd4679f --- /dev/null +++ b/songbook_core/content/sorted.TODO @@ -0,0 +1,23 @@ + 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 + diff --git a/songbook_core/songs.py b/songbook_core/songs.py index 27e59194..e2222b85 100644 --- a/songbook_core/songs.py +++ b/songbook_core/songs.py @@ -14,8 +14,6 @@ from songbook_core.plastex import parsetex class Song(object): """Song management""" - #: Ordre de tri - sort = [] #: Dictionnaire des options pour le traitement des auteurs authwords = {"after": [], "ignore": [], "sep": []} @@ -48,30 +46,6 @@ class Song(object): def __repr__(self): return repr((self.titles, self.args, self.path)) - 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 - - def unprefixed_title(title, prefixes): """Remove the first prefix of the list in the beginning of title (if any). """