Exemplo n.º 1
0
def compare_rating(a1, a2):
    a1, a2 = a1.album, a2.album
    if a1 is None:
        return -1
    if a2 is None:
        return 1
    if not a1.title:
        return 1
    if not a2.title:
        return -1
    return (-cmp(a1("~#rating"), a2("~#rating")) or cmpa(a1.date, a2.date)
            or cmpa(a1.sort, a2.sort) or cmp(a1.key, a2.key))
Exemplo n.º 2
0
def compare_avgplaycount(a1, a2):
    a1, a2 = a1.album, a2.album
    if a1 is None:
        return -1
    if a2 is None:
        return 1
    if not a1.title:
        return 1
    if not a2.title:
        return -1
    return (-cmp(a1("~#playcount:avg"), a2("~#playcount:avg"))
            or cmpa(a1.date, a2.date) or cmpa(a1.sort, a2.sort)
            or cmp(a1.key, a2.key))
Exemplo n.º 3
0
def compare_avgplaycount(a1, a2):
    a1, a2 = a1.album, a2.album
    if a1 is None:
        return -1
    if a2 is None:
        return 1
    if not a1.title:
        return 1
    if not a2.title:
        return -1
    return (-cmp(a1("~#playcount:avg"), a2("~#playcount:avg")) or
            cmpa(a1.date, a2.date) or
            cmpa(a1.sort, a2.sort) or
            cmp(a1.key, a2.key))
Exemplo n.º 4
0
def compare_rating(a1, a2):
    a1, a2 = a1.album, a2.album
    if a1 is None:
        return -1
    if a2 is None:
        return 1
    if not a1.title:
        return 1
    if not a2.title:
        return -1
    return (-cmp(a1("~#rating"), a2("~#rating")) or
            cmpa(a1.date, a2.date) or
            cmpa(a1.sort, a2.sort) or
            cmp(a1.key, a2.key))
Exemplo n.º 5
0
        def cmp_rows(model, i1, i2, data):
            t1, t2 = model[i1][0], model[i2][0]
            pos1 = _ORDERING.get(t1, 0)
            pos2 = _ORDERING.get(t2, 0)
            if pos1 or pos2:
                return cmp(pos1, pos2)

            if not isinstance(t1, AlbumNode):
                return cmp(util.human_sort_key(t1), util.human_sort_key(t2))

            a1, a2 = t1.album, t2.album
            return (cmpa(a1.peoplesort, a2.peoplesort)
                    or cmpa(a1.date, a2.date) or cmpa(a1.sort, a2.sort)
                    or cmp(a1.key, a2.key))
Exemplo n.º 6
0
 def test__sort_on_value(self):
     m = ObjectStore()
     iterBob = m.append(row=["bob"])
     iterAlice = m.append(row=["alice"])
     m.append(row=["charlie"])
     result = ObjectStore._sort_on_value(m, iterAlice, iterBob, None)
     self.assertEqual(result, cmp("alice", "bob"))
Exemplo n.º 7
0
 def cmpa(a, b):
     """Like cmp but treats values that evaluate to false as inf"""
     if not a and b:
         return 1
     if not b and a:
         return -1
     return cmp(a, b)
Exemplo n.º 8
0
def cmpa(a, b):
    """Like cmp but treats values that evaluate to false as inf"""
    if not a and b:
        return 1
    if not b and a:
        return -1
    return cmp(a, b)
Exemplo n.º 9
0
def compare_artist(a1, a2):
    a1, a2 = a1.album, a2.album
    if a1 is None:
        return -1
    if a2 is None:
        return 1
    if not a1.title:
        return 1
    if not a2.title:
        return -1
    return (cmpa(a1.peoplesort, a2.peoplesort) or cmpa(a1.date, a2.date)
            or cmpa(a1.sort, a2.sort) or cmp(a1.key, a2.key))
Exemplo n.º 10
0
def compare_date(a1, a2):
    a1, a2 = a1.album, a2.album
    if a1 is None:
        return -1
    if a2 is None:
        return 1
    if not a1.title:
        return 1
    if not a2.title:
        return -1
    return (cmpa(a1.date, a2.date) or
            cmpa(a1.sort, a2.sort) or
            cmp(a1.key, a2.key))
Exemplo n.º 11
0
def compare_title(a1, a2):
    a1, a2 = a1.album, a2.album
    # All albums should stay at the top
    if a1 is None:
        return -1
    if a2 is None:
        return 1
    # Move albums without a title to the bottom
    if not a1.title:
        return 1
    if not a2.title:
        return -1
    return (cmpa(a1.sort, a2.sort) or cmp(a1.key, a2.key))
Exemplo n.º 12
0
def compare_title(a1, a2):
    a1, a2 = a1.album, a2.album
    # All albums should stay at the top
    if a1 is None:
        return -1
    if a2 is None:
        return 1
    # Move albums without a title to the bottom
    if not a1.title:
        return 1
    if not a2.title:
        return -1
    return (cmpa(a1.sort, a2.sort) or
            cmp(a1.key, a2.key))
Exemplo n.º 13
0
def compare_original_date(a1, a2):
    a1, a2 = a1.album, a2.album
    if a1 is None:
        return -1
    if a2 is None:
        return 1
    if not a1.title:
        return 1
    if not a2.title:
        return -1

    # Take the original date if it is set, or fall back to the regular date
    # otherewise.
    a1_date = a1.get("originaldate", a1.date)
    a2_date = a2.get("originaldate", a2.date)

    return (cmpa(a1_date, a2_date) or cmpa(a1.sort, a2.sort)
            or cmp(a1.key, a2.key))
Exemplo n.º 14
0
 def sort_func(model, iter_a, iter_b, data):
     a = model.get_value(iter_a, 0)
     b = model.get_value(iter_b, 0)
     return -cmp(a, b)
Exemplo n.º 15
0
 def sort_func(model, a, b, data):
     a = model.get_value(a)
     b = model.get_value(b)
     return cmp(a.name, b.name)
Exemplo n.º 16
0
 def sort_func(model, a, b, data):
     a = model.get_value(a)
     b = model.get_value(b)
     return cmp(a.name, b.name)
Exemplo n.º 17
0
 def _sort_on_value(m, a, b, data):
     """Sorts two items in an ObjectStore,
     suitable for passing to `set_default_sort_func`"""
     return cmp(m[a][0], m[b][0])
Exemplo n.º 18
0
 def _sort_on_value(m, a, b, data):
     """Sorts two items in an ObjectStore,
     suitable for passing to `set_default_sort_func`"""
     return cmp(m[a][0], m[b][0])