~osomon/software-center/qml

« back to all changes in this revision

Viewing changes to softwarecenter/db/application.py

  • Committer: Olivier Tilloy
  • Date: 2011-11-03 16:42:37 UTC
  • mfrom: (1773.49.652 software-center)
  • Revision ID: olivier@tilloy.net-20111103164237-xhkcn96dmh1gu8a3
Merged the latest changes from trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
import re
23
23
 
24
24
from gettext import gettext as _
25
 
from softwarecenter.backend.channel import ChannelsManager
 
25
from softwarecenter.backend.channel import is_channel_available
26
26
from softwarecenter.distro import get_distro
27
27
from softwarecenter.enums import PkgStates, XapianValues, Icons
28
28
 
29
29
from softwarecenter.paths import (APP_INSTALL_CHANNELS_PATH,
30
30
                                  SOFTWARE_CENTER_ICON_CACHE_DIR,
31
31
                                  )
32
 
from softwarecenter.utils import version_compare
 
32
from softwarecenter.utils import utf8, split_icon_ext
33
33
 
34
34
LOG = logging.getLogger(__name__)
35
35
 
48
48
        # defaults
49
49
        self.pkgname = pkgname.replace("$kernel", os.uname()[2])
50
50
        if appname:
51
 
            self.appname = unicode(appname)
 
51
            self.appname = utf8(appname)
52
52
        else:
53
53
            self.appname = ''
54
54
        # the request can take additional "request" data like apturl
65
65
        """Show user visible name"""
66
66
        if self.appname:
67
67
            return self.appname
68
 
        return self.pkgname.capitalize()
 
68
        return self.pkgname
69
69
    @property
70
70
    def popcon(self):
71
71
        return self._popcon
116
116
    def __cmp__(self, other):
117
117
        return self.apps_cmp(self, other)
118
118
    def __str__(self):
119
 
        return "%s,%s" % (self.appname, self.pkgname)
 
119
        return utf8("%s,%s") % (utf8(self.appname), utf8(self.pkgname))
120
120
    def __repr__(self):
121
121
        return "[Application: appname=%s pkgname=%s]" % (self.appname, self.pkgname)
122
122
    @staticmethod
144
144
            a xapian.Document or from a db.application.Application object
145
145
        """
146
146
        if not doc and not application:
147
 
            raise ValueError, "Need either document or application"
 
147
            raise ValueError("Need either document or application")
148
148
        self._db = db
149
149
        self._db.connect("reopen", self._on_db_reopen)
150
150
        self._cache = self._db._aptcache
196
196
                    not channel_matches and 
197
197
                    not section_matches):
198
198
                    self._error = _("Not found")
199
 
                    self._error_not_found = _(u"There isn\u2019t a software package called \u201c%s\u201D in your current software sources.") % self.pkgname
 
199
                    self._error_not_found = utf8(_(u"There isn\u2019t a software package called \u201c%s\u201D in your current software sources.")) % utf8(self.pkgname)
200
200
 
201
201
    def same_app(self, other):
202
202
        return self.pkgname == other.pkgname
296
296
        # this may have changed since we inited the appdetails
297
297
        elif self.pkg_state == PkgStates.NOT_FOUND:
298
298
            self._error =  _("Not found")
299
 
            self._error_not_found = _(u"There isn\u2019t a software package called \u201c%s\u201D in your current software sources.") % self.pkgname
 
299
            self._error_not_found = utf8(_(u"There isn\u2019t a software package called \u201c%s\u201D in your current software sources.")) % utf8(self.pkgname)
300
300
            return self._error_not_found
301
301
 
302
302
    @property
304
304
        if self.pkg_state == PkgStates.NOT_FOUND:
305
305
            return Icons.MISSING_PKG
306
306
        if self._doc:
307
 
            return os.path.splitext(self._db.get_iconname(self._doc))[0]
 
307
            return split_icon_ext(self._db.get_iconname(self._doc))
308
308
        if not self.summary:
309
309
            return Icons.MISSING_PKG
310
310
            
336
336
 
337
337
    @property
338
338
    def license(self):
339
 
        return self._distro.get_license_text(self.component)
 
339
        xapian_license = None
 
340
        if self._doc:
 
341
            xapian_license = self._doc.get_value(XapianValues.LICENSE)
 
342
        if xapian_license:
 
343
            # try to i18n this, the server side does not yet support
 
344
            # translations, but fortunately for the most common ones
 
345
            # like "Properitary" we have translations in s-c
 
346
            return _(xapian_license)
 
347
        else:
 
348
            return self._distro.get_license_text(self.component)
340
349
 
341
350
    @property
342
351
    def maintenance_status(self):
423
432
                    return PkgStates.NEEDS_SOURCE
424
433
                else:
425
434
                    self._error =  _("Not found")
426
 
                    self._error_not_found = _(u"There isn\u2019t a software package called \u201c%s\u201D in your current software sources.") % self.pkgname
 
435
                    self._error_not_found = utf8(_(u"There isn\u2019t a software package called \u201c%s\u201D in your current software sources.")) % utf8(self.pkgname)
427
436
                    return PkgStates.NOT_FOUND
428
437
            else:
429
438
                if self.price:
437
446
                        if component and self._unavailable_component(component_to_check=component):
438
447
                            return PkgStates.NEEDS_SOURCE
439
448
                self._error =  _("Not found")
440
 
                self._error_not_found = _(u"There isn\u2019t a software package called \u201c%s\u201D in your current software sources.") % self.pkgname
 
449
                self._error_not_found = utf8(_(u"There isn\u2019t a software package called \u201c%s\u201D in your current software sources.")) % utf8(self.pkgname)
441
450
                return PkgStates.NOT_FOUND
442
451
        return PkgStates.UNKNOWN
443
452
 
504
513
                minver_matches = re.findall(r'minver=[a-z,0-9,-,+,.,~]*', self._app.request)
505
514
                if minver_matches and self.version:
506
515
                    minver = minver_matches[0][7:]
 
516
                    from softwarecenter.utils import version_compare
507
517
                    if version_compare(minver, self.version) > 0:
508
518
                        return _("Version %s or later not available.") % minver
509
519
        # can we enable a source
534
544
    def website(self):
535
545
        if self._pkg:
536
546
            return self._pkg.website
 
547
    
 
548
    @property
 
549
    def license_key(self):
 
550
        if self._doc:
 
551
            return self._doc.get_value(XapianValues.LICENSE_KEY)
 
552
 
 
553
    @property
 
554
    def license_key_path(self):
 
555
        if self._doc:
 
556
            return self._doc.get_value(XapianValues.LICENSE_KEY_PATH)
537
557
 
538
558
    def _unavailable_channel(self):
539
559
        """ Check if the given doc refers to a channel that is currently not enabled """
540
 
        return not ChannelsManager.channel_available(self.channelname)
 
560
        return not is_channel_available(self.channelname)
541
561
 
542
562
    def _unavailable_component(self, component_to_check=None):
543
563
        """ Check if the given doc refers to a component that is currently not enabled """