home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.5)
-
- from util import isiterable, groupby, do, dictreverse
- from util.xml_tag import tag
- from logging import getLogger
- log = getLogger('blistsort')
- info = log.info
- from util.observe import Observable
- from functools import wraps
- from common import profile, pref
- from traceback import print_exc
- from contacts.Group import DGroup, GroupTypes, merge_groups, Group
- from contacts.Contact import Contact
- from contacts.metacontacts import MetaContact
- from common import prefprop
- from common.protocolmeta import protocols
- from util.primitives import oset
-
- def grouping():
- s = pref('buddylist.sortby', 'none none').startswith
- if not s('*status'):
- pass
- return s('*service')
-
-
- class SpecialGroup(DGroup):
- _renderer = 'DGroup'
-
- def groupkey(self):
- return self.__class__.__name__ + '_' + DGroup.groupkey(self)
-
-
- def renamable(self):
- pass
-
-
- STATUS_ORDER = [
- 'available',
- 'away',
- 'idle',
- 'mobile',
- 'offline',
- 'unknown']
- STATUS_ORDER_INDEXES = dict((lambda .0: for i in .0:
- (STATUS_ORDER[i], i))(xrange(len(STATUS_ORDER))))
-
- def issortable(obj):
- JabberContact = JabberContact
- import jabber.JabberContact
- if not isinstance(obj, (MetaContact, JabberContact)):
- pass
- return isiterable(obj)
-
-
- def grp_order(obj):
- order = profile.blist.order['groups']
-
- try:
- return order.index(obj.groupkey())
- except ValueError:
- order.append(obj.groupkey())
- return len(order) - 1
-
-
-
- def by_name(obj):
- if isinstance(obj, GroupTypes):
- return grp_order(obj)
-
- return obj.alias.lower()
-
-
- def by_status(obj):
- if isinstance(obj, GroupTypes):
- if grouping():
- order = profile.blist.order['groups']
-
- try:
- return order.index(obj.groupkey())
- except ValueError:
- if isinstance(obj, SpecialGroup):
-
- try:
- stats = oset()
- for status in STATUS_ORDER:
- stats.add(SpecialGroup(status).groupkey())
-
- stats.difference_update(order)
- for status in stats:
- order.append(status)
-
- if obj.groupkey() not in stats:
- order.append(obj.groupkey())
-
- return by_status(obj)
- except ValueError:
- order.append(obj.groupkey())
- return len(order) - 1
- except:
- None<EXCEPTION MATCH>ValueError
-
-
- None<EXCEPTION MATCH>ValueError
- order.append(obj.groupkey())
- return len(order) - 1
- except Exception:
- e = None
- print obj.name.lower()
- raise e
- except:
- None<EXCEPTION MATCH>ValueError
-
-
- None<EXCEPTION MATCH>ValueError
- return grp_order(obj)
-
- status = obj.status_orb
-
- try:
- if status == 'unknown':
- status = 'offline'
-
- return (STATUS_ORDER.index(status), _(status.title()))
- except:
- import sys
- print >>sys.stderr, 'ERROR STATUS:', status
- raise
-
-
-
- def by_log(obj):
- if isinstance(obj, GroupTypes):
- return grp_order(obj)
-
-
- try:
- return -(obj.log_size)
- except AttributeError:
- return 1
-
-
-
- def by_service(obj):
- if isinstance(obj, GroupTypes):
- return grp_order(obj)
-
- if hasattr(obj, 'protocols') and hasattr(obj, 'first_online'):
- return protocols[obj.first_online.service]['name']
-
-
- try:
- return protocols[obj.service]['name']
- except AttributeError:
- return None
-
-
-
- def no_sorting(obj):
- pass
-
- sortfuncs = dict(name = (by_name, ('alias',)), status = (by_status, ('status', 'idle', 'away', 'mobile', 'online')), log = (by_log, ('log_size',)), service = (by_service, ('protocol',)), none = (None, ()))
- sortnames = dictreverse(sortfuncs)
-
- class BuddyListSorter(Observable):
- MAX_SORTERS = 2
-
- def __init__(self):
- Observable.__init__(self)
- self.sorters = [
- (None, ()),
- (None, ())]
- self.view = []
- self.needed_attrs = [
- 'status']
- self.hide_group_titles = False
- self.make_groups = False
- self.attr_observers = []
-
-
- def getsortnames(self):
- if not [ sortnames.get(s) for s in self.sorters ]:
- pass
- return [
- 'none']
-
-
- def sort_buddylist(self, L):
- if not pref('buddylist.sorting', True):
- return None
-
- if self.make_groups:
- self.group(L)
-
- self.sort(L)
-
-
- def sortby(self, sorters_str):
- log.info('sortby got %r', sorters_str)
-
- try:
- sorters_str = sorters_str.split()
- sorters = []
- allattrs = []
- for i, sorter in enumerate(sorters_str):
- if i == 0:
- if sorter.startswith('*'):
- sorter = sorter[1:]
- self.make_groups = True
- else:
- self.make_groups = False
-
- (func, attrs) = sortfuncs[sorter]
- sorters.append((func, attrs))
- allattrs += attrs
-
- self.sorters = sorters
- self.needed_attrs = list(set(allattrs))
- self.rebuild()
- except:
- print_exc()
- return self.sortby('none none')
-
-
-
- def allow_group_ordering(self):
- if grouping():
- pass
- return not (sortfuncs['status'] in self.sorters)
-
- allow_group_ordering = property(allow_group_ordering)
-
- def group(self, L):
- funcs = [
- self.sorters[0][0]]
-
- keyfunc = lambda x: (tuple,)((lambda .0: for f in .0:
- None if f is not None else 0)(funcs))
-
- L[:] = [ SpecialGroup(unicode(key[-1]), getattr(grp, 'protocols', []), getattr(grp, 'ids', []), list(grp)) for key, grp in groupby(self.flatten(L), keyfunc) ]
- if self.sorters[0][0] is by_status:
- for group in filter((lambda x: isinstance(x, GroupTypes)), L):
- group._show_offline_count = False
- group.name = eval(group.name)[1]
- if group.name == 'away':
- group.away = True
- continue
- []
- if group.name == 'online':
- group.online = True
- continue
- []
- group.online = False
-
-
- return L
-
-
- def user_ordering(self):
- ns = sortfuncs['none']
- if not self.sorters == [] and self.sorters == [
- ns] and self.sorters == [
- ns,
- ns]:
- pass
- return not pref('buddylist.sorting', True)
-
- user_ordering = property(user_ordering)
- sortby_val = prefprop('buddylist.sortby')
-
- def sortstatus(self):
- return self.sortby_val.startswith('*status')
-
- sortstatus = property(sortstatus)
- showoffline = prefprop('buddylist.show_offline')
- hidegroups = prefprop('buddylist.hide_offline_groups')
- groupoff = prefprop('buddylist.group_offline')
-
- def do_group_offline(self):
- if self.groupoff and not (self.sortstatus):
- pass
- return self.showoffline
-
- do_group_offline = property(do_group_offline)
-
- def hideoffline(self):
- if (self.sortstatus or not (self.showoffline)) and not (self.sortstatus):
- pass
- return self.hidegroups
-
- hideoffline = property(hideoffline)
-
- def sort(self, L):
- funcs = []([], [ x[0] for x in self.sorters ])
- L.sort(key = keyfunc)
- for obj in L:
- if issortable(obj):
- self.sort(obj)
- continue
- None if funcs and (None, ()) != funcs[0] else filter
-
-
-
- def flatten(self, L):
- i = 0
- size = len(L)
- while i < size:
- if isinstance(L[i], GroupTypes):
- L[i:i + 1] = L[i]
- size = len(L)
- continue
- i += 1
- return L
-
-
- def gui_toggle_grouping(self, v = None):
- self.make_groups = None if v is None else bool(v)
- self.rebuild()
-
-
- def make_xml(self, root = None):
- if root is None:
- root = self.view
-
- t = tag(type(root).__name__, name = getattr(root, 'name', 'unknown'))
- if isiterable(root):
- for thing in root:
- t(self.make_xml(thing))
-
-
- return t._to_xml()
-
-
- def rebuild(self):
- profile = profile
- import common
- profile.blist.rebuild()
-
-
-
- def sort_by_status_and_proto():
-
- def by_status(obj):
-
- try:
- return (dict(online = 0, idle = 1, away = 2, NA = 3, offline = 4).get(obj.status.lower(), 3), obj.status.lower())
- except:
-
- try:
- return None if obj.online else (4, 'offline')
- return (4, 'offline')
-
-
-
-
- def by_name(obj):
- return obj.name.lower()
-
- return ((by_status, ('status',), True), (by_name, ('name',)))
-
- if __name__ == '__main__':
- from tests.testapp import testapp
- app = testapp('../../')
- import digsbyprofile
- names = ('dotsyntax1', 'digsby04')
- accts = filter((lambda x: x.name in names), digsbyprofile.profile.account_manager.accounts)
- do((lambda .0: for acct in .0:
- acct())(accts))
- sorter = BuddyListSorter()
- do((lambda .0: for a in .0:
- sorter.add_buddylist(a.connection, a.connection.root_group))(accts))
- sorter.add_filter(*filter_offline())
- do((lambda .0: for a in .0:
- sorter.add_sorter(*a))(sort_by_status_and_proto()))
- from wx.py.PyWrap import wrap
- wrap(app)
- do((lambda .0: for acct in .0:
- acct())(accts))
-
-