~gary-lasker/software-center/launcher-integration-lp761851

« back to all changes in this revision

Viewing changes to softwarecenter/backend/reviews/rnr.py

  • Committer: Gary Lasker
  • Date: 2012-01-19 16:39:15 UTC
  • mfrom: (2566.1.113 trunk)
  • Revision ID: gary.lasker@canonical.com-20120119163915-lrgq5cdg6rttdn29
merge with trunk and fix conflicts to get 5.1.6 and lots of recent speedup/bug fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
65
65
 
66
66
    # reviews
67
67
    def get_reviews(self, translated_app, callback, page=1, 
68
 
                    language=None, sort=0):
 
68
                    language=None, sort=0, relaxed=False):
69
69
        """ public api, triggers fetching a review and calls callback
70
70
            when its ready
71
71
        """
77
77
        if language is None:
78
78
            language = self.language
79
79
        # gather args for the helper
80
 
        try:
81
 
            origin = self.cache.get_origin(app.pkgname)
82
 
        except:
83
 
            # this can happen if e.g. the app has multiple origins, this
84
 
            # will be handled later
85
 
            origin = None
86
 
        # special case for not-enabled PPAs
87
 
        if not origin and self.db:
88
 
            details = app.get_details(self.db)
89
 
            ppa = details.ppaname
90
 
            if ppa:
91
 
                origin = "lp-ppa-%s" % ppa.replace("/", "-")
92
 
        # if there is no origin, there is nothing to do
93
 
        if not origin:
94
 
            callback(app, [])
95
 
            return
96
 
        distroseries = self.distro.get_codename()
 
80
        if relaxed:
 
81
            origin = 'any'
 
82
            distroseries = 'any'
 
83
        else:
 
84
            try:
 
85
                origin = self.cache.get_origin(app.pkgname)
 
86
            except:
 
87
                # this can happen if e.g. the app has multiple origins, this
 
88
                # will be handled later
 
89
                origin = None
 
90
            # special case for not-enabled PPAs
 
91
            if not origin and self.db:
 
92
                details = app.get_details(self.db)
 
93
                ppa = details.ppaname
 
94
                if ppa:
 
95
                    origin = "lp-ppa-%s" % ppa.replace("/", "-")
 
96
            # if there is no origin, there is nothing to do
 
97
            if not origin:
 
98
                callback(app, [])
 
99
                return
 
100
            distroseries = self.distro.get_codename()
97
101
        # run the command and add watcher
98
102
        cmd = [os.path.join(softwarecenter.paths.datadir, PistonHelpers.GET_REVIEWS),
99
103
               "--language", language, 
128
132
        except OSError:
129
133
            days_delta = 0
130
134
        LOG.debug("refresh with days_delta: %s" % days_delta)
 
135
        # FIXME: the server currently has bug (#757695) so we
 
136
        #        can not turn this on just yet and need to use
 
137
        #        the old "catch-all" review-stats for now
131
138
        #origin = "any"
132
139
        #distroseries = self.distro.get_codename()
133
 
        cmd = [os.path.join(
134
 
                softwarecenter.paths.datadir, PistonHelpers.GET_REVIEW_STATS),
135
 
               # FIXME: the server currently has bug (#757695) so we
136
 
               #        can not turn this on just yet and need to use
137
 
               #        the old "catch-all" review-stats for now
138
 
               #"--origin", origin, 
139
 
               #"--distroseries", distroseries, 
140
 
              ]
 
140
        spawn_helper = SpawnHelper()
 
141
        spawn_helper.connect("data-available", self._on_review_stats_data, callback)
141
142
        if days_delta:
142
 
            cmd += ["--days-delta", str(days_delta)]
143
 
        spawn_helper = SpawnHelper()
144
 
        spawn_helper.connect("data-available", self._on_review_stats_data, callback)
145
 
        spawn_helper.run(cmd)
146
 
 
 
143
            spawn_helper.run_generic_piston_helper(
 
144
                "RatingsAndReviewsAPI", "review_stats", days=days_delta)
 
145
        else:
 
146
            spawn_helper.run_generic_piston_helper(
 
147
                "RatingsAndReviewsAPI", "review_stats")
 
148
                                                              
147
149
    def _on_review_stats_data(self, spawn_helper, piston_review_stats, callback):
148
150
        """ process stdout from the helper """
149
151
        review_stats = self.REVIEW_STATS_CACHE