示例#1
0
    def by_log_size(self):
        'Returns a list of MetaContacts and Contacts by log size.'

        sorter = blist.BuddyListSorter()
        sorter.addSorter(blist.ByGroup(False))
        sorter.addSorter(blist.ByOnline(True, False))
        sorter.setComparators([blist.LogSize])
        return remove_contacts_in_metacontacts(self.use_sorter(sorter))
示例#2
0
    def test_missing(self):
        '''
        Test missing counts.
        '''
        s = blist.BuddyListSorter()
        s.addSorter(blist.ByGroup(False, 2))
        s.addSorter(blist.ByService(True))
        s.addSorter(blist.ByOnline(True, True))
        cmps = [
            blist.CustomOrder, blist.Service, blist.UserOrdering,
            blist.UserOrdering
        ]
        s.setComparators(cmps)

        p = Protocol('digsby01', 'aim')
        p2 = Protocol('steve', 'digsby')

        def show(root_group):
            s.set_root(root_group)
            g = s._gather()
            try:
                print
                dump_elem_tree(g)
            finally:
                s._done_gather(g)

        root_group = Group(
            'root', p, 'root',
            RootGroup(
                'root1', p, 'root1',
                Group('aim group', p, 'aim group',
                      Buddy('abc', p, status='available'),
                      Buddy('abc', p, status='away'),
                      Buddy('def', p, status='offline'),
                      Buddy('def', p, status='offline'),
                      Buddy('ghi', p, status='away')),
                Buddy('12345', p, service='icq', status='offline'),
                Buddy('12345', p, service='aim', status='offline'),
                Buddy('fadjkls', p, status='mobile'),
                Group('group #2', p, 'group #2',
                      Buddy('wut', p, status='mobile')),
                RootGroup(
                    'root2', p2, 'root2',
                    Group(
                        'digsby group',
                        p2,
                        'digsby group',
                        Buddy('ninjadigsby', p2, status='away'),
                    ))))

        leakcheck(show, root_group)
示例#3
0
    def test_group_ownership(self):
        s = blist.BuddyListSorter()
        s.addSorter(blist.ByGroup(True))

        p = Protocol('aim', 'digsby01')
        s.set_root(
            Group('root', p, 'root',
                  Group('subgroup', p, 'root', Buddy('abc', p))))

        root = s._gather()
        assert root.name == 'root'
        subgroup = root[0]
        assert subgroup.name == 'subgroup'
        assert subgroup[0].name == 'abc'
        s._done_gather(root)
示例#4
0
    def test_filter_offline(self):
        s = blist.BuddyListSorter()
        s.addSorter(blist.ByGroup(True))
        s.addSorter(blist.ByMobile(True))
        s.addSorter(blist.ByOnline(False, False))

        s.setComparators([blist.Name])

        p = Protocol('aim', 'digsby01')

        s.set_root(
            Group('root', p, 'root', Buddy('abc', p, status='available'),
                  Buddy('def', p, status='offline')))

        root = s._gather()
        s._done_gather(root)
        del s
示例#5
0
    def foo():
        s = blist.BuddyListSorter()
        s.addSorter(blist.ByFakeRoot('Contacts'))
        s.addSorter(blist.ByGroup(True, 2))
        #        s.addSorter(blist.ByMobile(False))
        #        s.addSorter(blist.ByOnline(False))
        p = Protocol('aim', 'digsby01')
        root = Group(
            'root',
            p,
            'root',
            Group('root1', p, 'root1', Group('Contacts', p, 'subgroup'),
                  Buddy('abc', p)),
        )

        root_ref = ref(root)
        proto_ref = ref(p)
        sorter_ref = ref(s)

        s.set_root(root)

        gathered = s._gather()
        gathered_ref = ref(gathered)

        protocols, ids = gathered._protocol_ids
        #assert protocols == [p]
        #assert ids == ['root'], repr(ids)

        assert not sip.ispyowned(gathered)
        s._done_gather(gathered)
        del gathered
        del s
        del protocols, ids

        del p, root

        assert root_ref() is None
        assert proto_ref() is None

        assert sorter_ref() is None
        assert gathered_ref() is None
        '''
示例#6
0
    def test_group_counts(self):
        sorter = blist.BuddyListSorter()
        sorter.addSorter(blist.ByFakeRoot("Contacts"))
        sorter.addSorter(blist.ByGroup(True, 2))
        sorter.addSorter(blist.ByOnline(True, True))

        p = Protocol('aim', 'digsby01')
        sorter.set_root(
            Group(
                'root', p, 'root',
                Group('root1', p, 'root1', Buddy('abc', p), Buddy('def', p),
                      Group(
                          'Contacts',
                          p,
                          'Contacts',
                      ))))

        n = sorter._gather()
        try:
            # TODO: make 0 and 2 properties here.
            assert '0/2' in n[0].display_string
        finally:
            sorter._done_gather(n)
示例#7
0
    def _reconfig_sorter(self, rebuild = True):
        if not hasattr(self, '_rebuild_sorter_count'):
            self._rebuild_sorter_count = 0
        log.debug('rebuilding sorter %d', self._rebuild_sorter_count)
        self._rebuild_sorter_count += 1

        sorts = pref('buddylist.sortby')
        assert isinstance(sorts, basestring)
        sorts = sorts.split()

        search = getattr(self, '_search_by', '')

        s = self.new_sorter
        s.clearSorters()

        show_offline = pref('buddylist.show_offline')
        group_offline = pref('buddylist.group_offline')
        show_mobile = pref('buddylist.show_mobile')
        hide_offline_groups = pref('buddylist.hide_offline_groups')

        if search:
            # search by
            show_offline = True
            s.addSorter(blist.ByGroup(False, 2))
            s.addSorter(blist.BySearch(search, SEARCH_CONTACTS_GROUPNAME))
        else:
            if not sorts[0].startswith('*'):
                s.addSorter(blist.ByFakeRoot(pref('buddylist.fakeroot_name', default=_('Contacts'))))
            s.addSorter(blist.ByGroup(not sorts[0].startswith('*'), 2))


        #until status grouper can do it, always add a mobile filter.
        #mobile needs to happen before the status grouper (otherwise you may see a mobile group for now)
        if not search and not show_mobile:
            s.addSorter(blist.ByMobile(show_mobile))

        # Add any necessary groupers
        added_status_grouper = False
        if not search and sorts[0].startswith('*'):
            show_groups = True
            sorter = sorts[0][1:]
            grouper = self.Groupers.get(sorter)
            if grouper is not None:
                if sorter == 'status':
                    # pass showOffline flag to ByStatus grouper
                    args = (show_offline, )
                    added_status_grouper = True
                else:
                    args = ()

                grouper_obj = getattr(blist, grouper)(show_groups, *args)

                if sorter == 'service':
                    # Set group names on the ByService grouper
                    for service, protocolinfo in protocols.iteritems():
                        grouper_obj.setGroupName(service, protocolinfo['name'])

                s.addSorter(grouper_obj)

        # Comparators
        sorters = [blist.CustomOrder]

        if search:
            # move offline buddies to the bottom when searching, and sort alphabetically
            sorts = ['online', 'name']
        else:
            # If we're grouping offline buddies, or filtering them out,
            # and we didn't add a ByStatus grouper, then we need to add a simpler
            # ByOnline grouper that accomplish the same things.
            # And, btw, we're "always" grouping offline buddies, we need the counts.
            if not added_status_grouper:
                s.addSorter(blist.ByOnline(group_offline, show_offline))

        # Always sort by user order.
        if sorts[-1] != 'none':
            sorts.append('none')

        self.attrs = set(self.base_attrs)
        cmpnames = []
        for sort in sorts:
            if sort.startswith('*'):
                #continue
                sort = sort[1:]
            cmpname = self.Sorters[sort]
            cmpnames.append(cmpname)

            # make sure we rebuild when buddy attributes change that are important
            # to the sorter
            sort_attr = self.BuddySortAttrs.get(sort, None)
            if sort_attr is not None:
                self.attrs.add(sort_attr)

            sorters.append(getattr(blist, cmpname))

        log.debug('comparators are: %s', ', '.join(cmpnames))

        self.comparators = sorters
        s.setComparators(sorters)
        if pref('buddylist.hide_offline_dependant', False, bool):
            s.setPruneEmpty(not pref('buddylist.show_offline') and pref('buddylist.hide_offline_groups'))
        else:
            s.setPruneEmpty(pref('buddylist.hide_offline_groups'))

        if rebuild:
            self.rebuild_threaded()
示例#8
0
    def test_sorter_ownership(self):
        s = blist.BuddyListSorter()
        b = blist.ByGroup()
        s.addSorter(b)

        assert not sip.ispyowned(b)