1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
# Copyright (C) 2009-2010 Canonical
#
# Authors:
# Michael Vogt
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; version 3.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import locale
class Application(object):
""" The central software item abstraction. it conaints a
pkgname that is always available and a optional appname
for packages with multiple applications
There is also a __cmp__ method and a name property
"""
def __init__(self, appname, pkgname, popcon=0):
self.appname = appname
self.pkgname = pkgname
self._popcon = popcon
@property
def name(self):
"""Show user visible name"""
if self.appname:
return self.appname
return self.pkgname
@property
def popcon(self):
return self._popcon
# special methods
def __hash__(self):
return ("%s:%s" % (self.appname, self.pkgname)).__hash__()
def __cmp__(self, other):
return self.apps_cmp(self, other)
def __str__(self):
return "%s,%s" % (self.appname, self.pkgname)
@staticmethod
def apps_cmp(x, y):
""" sort method for the applications """
# sort(key=locale.strxfrm) would be more efficient, but its
# currently broken, see http://bugs.python.org/issue2481
if x.appname and y.appname:
return locale.strcoll(x.appname, y.appname)
elif x.appname:
return locale.strcoll(x.appname, y.pkgname)
elif y.appname:
return locale.strcoll(x.pkgname, y.appname)
else:
return cmp(x.pkgname, y.pkgname)
|