Пример #1
0
    def post_submit_profile(self, db):
        """ This will post the users profile to the recommender server
            and also generate the UUID for the user if that is not
            there yet
        """
        recommender_uuid = self.recommender_uuid
        if not recommender_uuid:
            # generate a new uuid, but do not save it yet, this will
            # be done later in _on_submit_profile_data
            recommender_uuid = get_uuid()
        installed_pkglist = [app.pkgname
                             for app in get_installed_apps_list(db)]
        profile = self._generate_submit_profile_data(recommender_uuid,
                                                     installed_pkglist)

        # compare profiles to see if there has been a change, and if there
        # has, do the profile update
        current_recommender_profile_id = self._calc_profile_id(profile)
        if current_recommender_profile_id != self.recommender_profile_id:
            LOG.info("Submitting recommendations profile to the server")
            self._set_recommender_profile_id(current_recommender_profile_id)
            # build the command and upload the profile
            spawner = SpawnHelper()
            spawner.parent_xid = self.xid
            spawner.needs_auth = True
            spawner.connect("data-available", self._on_submit_profile_data,
                            recommender_uuid)
            spawner.connect(
                "error", lambda spawner, err: self.emit("error", err))
            spawner.run_generic_piston_helper(
                "SoftwareCenterRecommenderAPI",
                "submit_profile",
                data=profile)
Пример #2
0
 def query_exhibits(self):
     spawner = SpawnHelper()
     spawner.parent_xid = self.xid
     spawner.ignore_cache = self.ignore_cache
     spawner.connect("data-available", self._on_exhibits_data_available)
     spawner.connect("error", lambda spawner, err: self.emit("error", err))
     spawner.run_generic_piston_helper(
         "SoftwareCenterAgentAPI", "exhibits",
         lang=get_language(), series=self.distro.get_codename())
Пример #3
0
 def query_server_status(self):
     # build the command
     spawner = SpawnHelper()
     spawner.parent_xid = self.xid
     spawner.needs_auth = True
     spawner.connect("data-available", self._on_server_status_data)
     spawner.connect("error", lambda spawner, err: self.emit("error", err))
     spawner.run_generic_piston_helper(
         "SoftwareCenterRecommenderAPI", "server_status")
Пример #4
0
 def query_available_for_me(self):
     spawner = SpawnHelper()
     spawner.parent_xid = self.xid
     spawner.ignore_cache = self.ignore_cache
     spawner.connect("data-available", self._on_query_available_for_me_data)
     spawner.connect("error", lambda spawner, err: self.emit("error", err))
     spawner.needs_auth = True
     spawner.run_generic_piston_helper(
         "SoftwareCenterAgentAPI", "subscriptions_for_me",
         complete_only=True)
Пример #5
0
 def query_profile(self, pkgnames):
     # build the command
     spawner = SpawnHelper()
     spawner.parent_xid = self.xid
     spawner.needs_auth = True
     spawner.connect("data-available", self._on_profile_data)
     spawner.connect("error", lambda spawner, err: self.emit("error", err))
     spawner.run_generic_piston_helper(
         "SoftwareCenterRecommenderAPI",
         "profile",
         pkgnames=pkgnames)
Пример #6
0
 def query_profile(self, pkgnames):
     # build the command
     spawner = SpawnHelper()
     spawner.parent_xid = self.xid
     spawner.needs_auth = True
     spawner.connect("data-available", self._on_profile_data)
     spawner.connect("error", lambda spawner, err: self.emit("error", err))
     spawner.run_generic_piston_helper("SoftwareCenterRecommenderAPI", "profile", pkgnames=pkgnames)
Пример #7
0
 def query_recommend_top(self):
     # build the command
     spawner = SpawnHelper()
     spawner.parent_xid = self.xid
     spawner.connect("data-available", self._on_recommend_top_data)
     spawner.connect("error", lambda spawner, err: self.emit("error", err))
     spawner.run_generic_piston_helper(
         "SoftwareCenterRecommenderAPI", "recommend_top")
Пример #8
0
 def query_server_status(self):
     # build the command
     spawner = SpawnHelper()
     spawner.parent_xid = self.xid
     spawner.needs_auth = True
     spawner.connect("data-available", self._on_server_status_data)
     spawner.connect("error", lambda spawner, err: self.emit("error", err))
     spawner.run_generic_piston_helper("SoftwareCenterRecommenderAPI", "server_status")
Пример #9
0
 def post_submit_anon_profile(self, uuid, installed_packages, extra):
     # build the command
     spawner = SpawnHelper()
     spawner.parent_xid = self.xid
     spawner.needs_auth = True
     spawner.connect("data-available", self._on_submit_anon_profile_data)
     spawner.connect("error", lambda spawner, err: self.emit("error", err))
     spawner.run_generic_piston_helper(
         "SoftwareCenterRecommenderAPI",
         "submit_anon_profile",
         uuid=uuid,
         installed_packages=installed_packages,
         extra=extra)
Пример #10
0
 def query_recommend_top(self):
     # build the command
     spawner = SpawnHelper()
     spawner.parent_xid = self.xid
     spawner.connect("data-available", self._on_recommend_top_data)
     spawner.connect("error", lambda spawner, err: self.emit("error", err))
     spawner.run_generic_piston_helper("SoftwareCenterRecommenderAPI", "recommend_top")
Пример #11
0
 def query_available_for_me(self, oauth_token, openid_identifier):
     cmd = self.HELPER_CMD[:]
     cmd.append("subscriptions_for_me")
     spawner = SpawnHelper()
     spawner.connect("data-available", self._on_query_available_for_me_data)
     spawner.connect("error", lambda spawner, err: self.emit("error", err))
     spawner.run(cmd)
Пример #12
0
 def whoami(self):
     """ trigger request for the getting account information, this
         will also verify if the current token is valid and if not
         trigger a cleanup/re-authenticate
     """
     LOG.debug("whoami called")
     spawner = SpawnHelper()
     spawner.connect("data-available", self._on_whoami_data)
     spawner.connect("error", lambda spawner, err: self.emit("error", err))
     spawner.needs_auth = True
     spawner.run_generic_piston_helper("UbuntuSsoAPI", "whoami")
Пример #13
0
 def query_exhibits(self):
     cmd = self.HELPER_CMD[:]
     cmd.append("exhibits")
     cmd.append(get_language())
     spawner = SpawnHelper()
     spawner.connect("data-available", self._on_exhibits_data_available)
     spawner.connect("error", lambda spawner, err: self.emit("error", err))
     spawner.run(cmd)
Пример #14
0
 def spawn_report_abuse_ui(self, review_id, parent_xid, datadir, callback):
     """ this spawns the UI for reporting a review as inappropriate
         and adds the review-id to the internal hide list. once the
         operation is complete it will call callback with the updated
         review list
     """
     cmd = [os.path.join(datadir, RNRApps.REPORT_REVIEW), 
            "--review-id", review_id,
            "--parent-xid", "%s" % parent_xid,
            "--datadir", datadir,
           ]
     spawn_helper = SpawnHelper("json")
     spawn_helper.connect("exited", 
                          self._on_report_abuse_finished, 
                          review_id, callback)
     spawn_helper.run(cmd)
Пример #15
0
 def _retrieve_votes_from_server(self):
     LOG.debug("_retrieve_votes_from_server started")
     user = get_person_from_config()
     
     if not user:
         LOG.warn("Could not get usefulness from server, no username in config file")
         return False
     
     # run the command and add watcher
     cmd = [os.path.join(
             softwarecenter.paths.datadir, PistonHelpers.GET_USEFUL_VOTES),
            "--username", user, 
           ]
     spawn_helper = SpawnHelper()
     spawn_helper.connect("data-available", self._on_usefulness_data)
     spawn_helper.run(cmd)
Пример #16
0
 def query_available_for_me(self, oauth_token, openid_identifier):
     cmd = self.HELPER_CMD[:]
     cmd.append("subscriptions_for_me")
     spawner = SpawnHelper()
     spawner.connect("data-available", self._on_query_available_for_me_data)
     spawner.connect("error", lambda spawner, err: self.emit("error", err))
     spawner.run(cmd)
Пример #17
0
 def whoami(self):
     """ trigger request for getting the account information, this
         will also verify if the current token is valid and if not,
         trigger a cleanup/re-authenticate
     """
     LOG.debug("whoami called")
     spawner = SpawnHelper()
     spawner.connect("data-available", self._on_whoami_data)
     spawner.connect("error", lambda spawner, err: self.emit("error", err))
     spawner.needs_auth = True
     spawner.run_generic_piston_helper("UbuntuSsoAPI", "whoami")
Пример #18
0
 def query_exhibits(self):
     cmd = self.HELPER_CMD[:]
     cmd.append("exhibits")
     cmd.append(get_language())
     spawner = SpawnHelper()
     spawner.connect("data-available", self._on_exhibits_data_available)
     spawner.connect("error", lambda spawner, err: self.emit("error", err))
     spawner.run(cmd)
Пример #19
0
 def spawn_write_new_review_ui(self, translated_app, version, iconname, 
                               origin, parent_xid, datadir, callback):
     """ this spawns the UI for writing a new review and
         adds it automatically to the reviews DB """
     app = translated_app.get_untranslated_app(self.db)
     cmd = [os.path.join(datadir, RNRApps.SUBMIT_REVIEW), 
            "--pkgname", app.pkgname,
            "--iconname", iconname,
            "--parent-xid", "%s" % parent_xid,
            "--version", version,
            "--origin", origin,
            "--datadir", datadir,
            ]
     if app.appname:
         # needs to be (utf8 encoded) str, otherwise call fails
         cmd += ["--appname", utf8(app.appname)]
     spawn_helper = SpawnHelper(format="json")
     spawn_helper.connect(
         "data-available", self._on_submit_review_data, app, callback)
     spawn_helper.run(cmd)
Пример #20
0
 def get_reviews(self, translated_app, callback, page=1, language=None):
     """ public api, triggers fetching a review and calls callback
         when its ready
     """
     # its fine to use the translated appname here, we only submit the
     # pkgname to the server
     app = translated_app
     self._update_rnrclient_offline_state()
     if language is None:
         language = self.language
     # gather args for the helper
     try:
         origin = self.cache.get_origin(app.pkgname)
     except:
         # this can happen if e.g. the app has multiple origins, this
         # will be handled later
         origin = None
     # special case for not-enabled PPAs
     if not origin and self.db:
         details = app.get_details(self.db)
         ppa = details.ppaname
         if ppa:
             origin = "lp-ppa-%s" % ppa.replace("/", "-")
     # if there is no origin, there is nothing to do
     if not origin:
         callback(app, [])
         return
     distroseries = self.distro.get_codename()
     # run the command and add watcher
     cmd = [os.path.join(softwarecenter.paths.datadir, PistonHelpers.GET_REVIEWS),
            "--language", language, 
            "--origin", origin, 
            "--distroseries", distroseries, 
            "--pkgname", str(app.pkgname), # ensure its str, not unicode
            "--page", str(page),
           ]
     spawn_helper = SpawnHelper()
     spawn_helper.connect(
         "data-available", self._on_reviews_helper_data, app, callback)
     spawn_helper.run(cmd)
Пример #21
0
 def post_submit_profile(self, db):
     """ This will post the users profile to the recommender server
         and also generate the UUID for the user if that is not 
         there yet
     """
     # if we have not already set a recommender UUID, now is the time
     # to do it
     if not self.recommender_uuid:
         self.recommender_uuid = get_uuid()
     installed_pkglist = [app.pkgname for app in get_installed_apps_list(db)]
     data = self._generate_submit_profile_data(self.recommender_uuid, installed_pkglist)
     # build the command
     spawner = SpawnHelper()
     spawner.parent_xid = self.xid
     spawner.needs_auth = True
     spawner.connect("data-available", self._on_submit_profile_data)
     spawner.connect("error", lambda spawner, err: self.emit("error", err))
     spawner.run_generic_piston_helper("SoftwareCenterRecommenderAPI", "submit_profile", data=data)
Пример #22
0
 def spawn_delete_review_ui(self, review_id, parent_xid, datadir, callback):
     cmd = [os.path.join(datadir, RNRApps.DELETE_REVIEW), 
            "--review-id", "%s" % review_id,
            "--parent-xid", "%s" % parent_xid,
            "--datadir", datadir,
           ]
     spawn_helper = SpawnHelper(format="none")
     spawn_helper.connect("exited", 
                          self._on_delete_review_finished, 
                          review_id, callback)
     spawn_helper.connect("error", self._on_delete_review_error,
                          review_id, callback)
     spawn_helper.run(cmd)
Пример #23
0
 def refresh_review_stats(self, callback):
     """ public api, refresh the available statistics """
     try:
         mtime = os.path.getmtime(self.REVIEW_STATS_CACHE_FILE)
         days_delta = int((time.time() - mtime) // (24*60*60))
         days_delta += 1
     except OSError:
         days_delta = 0
     LOG.debug("refresh with days_delta: %s" % days_delta)
     #origin = "any"
     #distroseries = self.distro.get_codename()
     cmd = [os.path.join(
             softwarecenter.paths.datadir, PistonHelpers.GET_REVIEW_STATS),
            # FIXME: the server currently has bug (#757695) so we
            #        can not turn this on just yet and need to use
            #        the old "catch-all" review-stats for now
            #"--origin", origin, 
            #"--distroseries", distroseries, 
           ]
     if days_delta:
         cmd += ["--days-delta", str(days_delta)]
     spawn_helper = SpawnHelper()
     spawn_helper.connect("data-available", self._on_review_stats_data, callback)
     spawn_helper.run(cmd)
Пример #24
0
 def spawn_submit_usefulness_ui(self, review_id, is_useful, parent_xid, datadir, callback):
     cmd = [os.path.join(datadir, RNRApps.SUBMIT_USEFULNESS), 
            "--review-id", "%s" % review_id,
            "--is-useful", "%s" % int(is_useful),
            "--parent-xid", "%s" % parent_xid,
            "--datadir", datadir,
           ]
     spawn_helper = SpawnHelper(format="none")
     spawn_helper.connect("exited", 
                          self._on_submit_usefulness_finished, 
                          review_id, is_useful, callback)
     spawn_helper.connect("error",
                          self._on_submit_usefulness_error,
                          review_id, callback)
     spawn_helper.run(cmd)
Пример #25
0
 def spawn_modify_review_ui(self, parent_xid, iconname, datadir, review_id, callback):
     """ this spawns the UI for writing a new review and
         adds it automatically to the reviews DB """
     cmd = [os.path.join(datadir, RNRApps.MODIFY_REVIEW), 
            "--parent-xid", "%s" % parent_xid,
            "--iconname", iconname,
            "--datadir", "%s" % datadir,
            "--review-id", "%s" % review_id,
            ]
     spawn_helper = SpawnHelper(format="json")
     spawn_helper.connect("data-available", 
                          self._on_modify_review_finished, 
                          review_id, callback)
     spawn_helper.connect("error", self._on_modify_review_error,
                          review_id, callback)
     spawn_helper.run(cmd)
Пример #26
0
 def _query_available(self, series_name, arch_tag, for_qa):
     language = get_language()
     if not series_name:
         series_name = self.distro.get_codename()
     if not arch_tag:
         arch_tag = get_current_arch()
     # build the command
     cmd = self.HELPER_CMD[:]
     if for_qa:
         cmd.append("available_apps_qa")
     else:
         cmd.append("available_apps")
     cmd += [language,
             series_name,
             arch_tag,
             ]
     spawner = SpawnHelper()
     spawner.connect("data-available", self._on_query_available_data)
     spawner.connect("error", lambda spawner, err: self.emit("error", err))
     spawner.run(cmd)
Пример #27
0
 def _query_available(self, series_name, arch_tag, for_qa):
     language = get_language()
     if not series_name:
         series_name = self.distro.get_codename()
     if not arch_tag:
         arch_tag = get_current_arch()
     # build the command
     cmd = self.HELPER_CMD[:]
     if for_qa:
         cmd.append("available_apps_qa")
     else:
         cmd.append("available_apps")
     cmd += [language,
             series_name,
             arch_tag,
             ]
     spawner = SpawnHelper()
     spawner.connect("data-available", self._on_query_available_data)
     spawner.connect("error", lambda spawner, err: self.emit("error", err))
     spawner.run(cmd)
Пример #28
0
 def query_available_for_me(self):
     spawner = SpawnHelper()
     spawner.parent_xid = self.xid
     spawner.ignore_cache = self.ignore_cache
     spawner.connect("data-available", self._on_query_available_for_me_data)
     spawner.connect("error", lambda spawner, err: self.emit("error", err))
     spawner.needs_auth = True
     spawner.run_generic_piston_helper("SoftwareCenterAgentAPI",
                                       "subscriptions_for_me",
                                       complete_only=True)
Пример #29
0
 def _query_available(self, series_name, arch_tag, for_qa):
     if not series_name:
         series_name = self.distro.get_codename()
     if not arch_tag:
         arch_tag = get_current_arch()
     # build the command
     spawner = SpawnHelper()
     spawner.parent_xid = self.xid
     spawner.ignore_cache = self.ignore_cache
     spawner.connect("data-available", self._on_query_available_data)
     spawner.connect("error", lambda spawner, err: self.emit("error", err))
     if for_qa:
         spawner.needs_auth = True
         spawner.run_generic_piston_helper("SoftwareCenterAgentAPI",
                                           "available_apps_qa",
                                           lang=get_language(),
                                           series=series_name,
                                           arch=arch_tag)
     else:
         spawner.run_generic_piston_helper("SoftwareCenterAgentAPI",
                                           "available_apps",
                                           lang=get_language(),
                                           series=series_name,
                                           arch=arch_tag)
Пример #30
0
 def _query_available(self, series_name, arch_tag, for_qa):
     if not series_name:
         series_name = self.distro.get_codename()
     if not arch_tag:
         arch_tag = get_current_arch()
     # build the command
     spawner = SpawnHelper()
     spawner.parent_xid = self.xid
     spawner.ignore_cache = self.ignore_cache
     spawner.connect("data-available", self._on_query_available_data)
     spawner.connect("error", lambda spawner, err: self.emit("error", err))
     if for_qa:
         spawner.needs_auth = True
         spawner.run_generic_piston_helper(
             "SoftwareCenterAgentAPI",
             "available_apps_qa",
             lang=get_language(),
             series=series_name,
             arch=arch_tag)
     else:
         spawner.run_generic_piston_helper(
             "SoftwareCenterAgentAPI",
             "available_apps",
             lang=get_language(),
             series=series_name,
             arch=arch_tag)