~ubuntu-branches/ubuntu/raring/software-center/raring-proposed

« back to all changes in this revision

Viewing changes to softwarecenter/db/application.py

  • Committer: Package Import Robot
  • Author(s): Michael Vogt
  • Date: 2012-10-11 15:33:05 UTC
  • mfrom: (195.1.18 quantal)
  • Revision ID: package-import@ubuntu.com-20121011153305-fm5ln7if3rpzts4n
Tags: 5.4.1.1
* lp:~mvo/software-center/reinstall-previous-purchase-token-fix:
  - fix reinstall previous purchases that have a system-wide
    license key LP: #1065481
* lp:~mvo/software-center/lp1060106:
  - Add missing gettext init for utils/update-software-center-agent
    (LP: #1060106)

Show diffs side-by-side

added added

removed removed

Lines of Context:
137
137
    def __str__(self):
138
138
        return utf8("%s,%s") % (utf8(self.appname), utf8(self.pkgname))
139
139
 
 
140
    def __unicode__(self):
 
141
        return "%s,%s" % (unicode(self.appname, "utf-8", "replace"),
 
142
                          unicode(self.pkgname, "utf-8", "replace"))
 
143
 
140
144
    def __repr__(self):
141
145
        return "[Application: appname=%s pkgname=%s]" % (self.appname,
142
146
            self.pkgname)
183
187
        # import here (intead of global) to avoid dbus dependency
184
188
        # in update-software-center (that imports application, but
185
189
        # never uses AppDetails) LP: #620011
186
 
        from softwarecenter.backend import get_install_backend
 
190
        from softwarecenter.backend.installbackend import get_install_backend
187
191
        self._backend = get_install_backend()
188
192
        # FIXME: why two error states ?
189
193
        self._error = None
257
261
        raise ValueError("pkg '%s' has not archive_suite '%s'" % (
258
262
                pkg, archive_suite))
259
263
 
 
264
    def as_dbus_property_dict(self):
 
265
        """ return all properties as a dict with name/value """
 
266
        import inspect
 
267
        properties = {}
 
268
        # FIXME: I whish there was a more generic way for this
 
269
        NOT_EXPOSE = set(["props", "pkg"])
 
270
        for name, value in inspect.getmembers(self):
 
271
            if name.startswith("_") or callable(value) or name in NOT_EXPOSE:
 
272
                continue
 
273
            # dbus does not like sets
 
274
            if isinstance(value, set):
 
275
                value = list(value)
 
276
            # make sure that the type can be encoded
 
277
            if not type(value) in [
 
278
                list, dict, tuple, basestring, int, float, bool, None]:
 
279
                value = "%s" % value
 
280
            # dbus does not like empty dicts/lists
 
281
            if isinstance(value, dict) or isinstance(value, list):
 
282
                if len(value) == 0:
 
283
                    value = ""
 
284
            # and set it
 
285
            properties[name] = value
 
286
        return properties
 
287
 
260
288
    @property
261
289
    def channelname(self):
262
290
        if self._doc:
290
318
 
291
319
    @property
292
320
    def component(self):
293
 
        """
294
 
        get the component (main, universe, ..)
295
 
 
296
 
        this uses the data from apt, if there is none it uses the
297
 
        data from the app-install-data files
 
321
        """Get the component (main, universe, ..).
 
322
 
 
323
        This uses the data from apt, if there is none it uses the
 
324
        data from the app-install-data files.
 
325
 
298
326
        """
299
327
        # try apt first
300
328
        if self._pkg:
387
415
        return self._history.get_installed_date(self.pkgname)
388
416
 
389
417
    @property
 
418
    def is_desktop_dependency(self):
 
419
        if self._pkg:
 
420
            depends = self._cache.get_packages_removed_on_remove(
 
421
                self._pkg)
 
422
            if "ubuntu-desktop" in depends:
 
423
                return True
 
424
        return False
 
425
 
 
426
    @property
390
427
    def purchase_date(self):
391
428
        if self._doc:
392
429
            return self._doc.get_value(XapianValues.PURCHASED_DATE)
510
547
                          u"current software sources.")) % utf8(self.pkgname)
511
548
                    return PkgStates.NOT_FOUND
512
549
            else:
513
 
                if self.price:
 
550
                if self.raw_price:
514
551
                    return PkgStates.NEEDS_PURCHASE
515
552
                if (self.purchase_date and
516
553
                    self._doc.get_value(XapianValues.ARCHIVE_DEB_LINE)):
546
583
        return PkgStates.UNKNOWN
547
584
 
548
585
    @property
 
586
    def currency(self):
 
587
        """ Get the currency for the price """
 
588
        if self._doc:
 
589
            return self._doc.get_value(XapianValues.CURRENCY)
 
590
 
 
591
    @property
 
592
    def raw_price(self):
 
593
        """ The raw price, useful for e.g. sort-by """
 
594
        if self._doc:
 
595
            return self._doc.get_value(XapianValues.PRICE)
 
596
        # the unity-lens expects a "" string here for "no-price"
 
597
        return ""
 
598
 
 
599
    @property
549
600
    def price(self):
550
 
        if self._doc:
551
 
            return self._doc.get_value(XapianValues.PRICE)
 
601
        """ The price and the currency ready to display to the user
 
602
            or "Free" is its a libre or gratis app
 
603
        """
 
604
        raw_price = self.raw_price
 
605
        if raw_price == '0.00':
 
606
            # TRANSLATORS: Free here means Gratis
 
607
            return _("Free")
 
608
        currency = self.currency
 
609
        if raw_price and currency:
 
610
            # FIXME:  need to determine the currency dynamically once we can
 
611
            #         get that info from the software-center-agent/payments
 
612
            #         service.
 
613
            # NOTE:  the currency string for this label is purposely not
 
614
            #        translatable when hardcoded, since it (currently)
 
615
            #        won't vary based on locale and as such we don't want
 
616
            #        it translated
 
617
            # FIXME: if we support different currencies eventually we need
 
618
            #        to format them here differently too, e.g.
 
619
            #        "US$ 1" but "1EUR"
 
620
            return "%s %s" % (currency, raw_price)
 
621
        # TRANSLATORS: Free here means Libre
 
622
        return _("Free")
552
623
 
553
624
    @property
554
625
    def supported_distros(self):
577
648
 
578
649
    @property
579
650
    def screenshot(self):
580
 
        """ return screenshot url """
 
651
        """Return the screenshot url."""
581
652
        # if there is a custom screenshot url provided, use that
582
653
        if self._doc:
583
654
            # we do support multiple screenshots in the database but
593
664
 
594
665
    @property
595
666
    def screenshots(self):
596
 
        """ return list of screenshots, this requies that
597
 
            "query_multiple_screenshos" was run before and emited the signal
 
667
        """Return a list of screenshots.
 
668
 
 
669
        Is required that "query_multiple_screenshos" was run before and emited
 
670
        the signal.
 
671
 
598
672
        """
599
673
        if not self._screenshot_list:
600
674
            return [{
604
678
            }]
605
679
        return self._screenshot_list
606
680
 
 
681
    # used for the unity data provider only for now
 
682
    @property
 
683
    def size(self):
 
684
        """Return the size of the application without dependencies
 
685
 
 
686
        Note that this will return the download size if the app is
 
687
        not installed and the installed size if it is installed.
 
688
        """
 
689
        if self._pkg:
 
690
            if not self._pkg.installed:
 
691
                if self._app.archive_suite:
 
692
                    ver = self._get_version_for_archive_suite(
 
693
                        self._pkg, self._app.archive_suite)
 
694
                    if ver:
 
695
                        return ver.size
 
696
                return self._pkg.candidate.size
 
697
            else:
 
698
                return self._pkg.installed.size
 
699
 
607
700
    @property
608
701
    def tags(self):
609
 
        """ return a set() of tags """
 
702
        """Return a set() of tags."""
610
703
        terms = set()
611
704
        if self._doc:
612
705
            for term_iter in self._doc.termlist():
826
919
 
827
920
    @property
828
921
    def website(self):
 
922
        """This application's website (homepage)."""
 
923
        result = None
829
924
        if self._pkg:
830
 
            return self._pkg.website
 
925
            result = self._pkg.website
 
926
        elif self._doc:
 
927
            result = self._doc.get_value(XapianValues.WEBSITE)
 
928
        return result
831
929
 
832
930
    @property
833
931
    def supportsite(self):