本文整理汇总了Python中softwarecenter.backend.recagent.RecommenderAgent.query_recommend_me方法的典型用法代码示例。如果您正苦于以下问题:Python RecommenderAgent.query_recommend_me方法的具体用法?Python RecommenderAgent.query_recommend_me怎么用?Python RecommenderAgent.query_recommend_me使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类softwarecenter.backend.recagent.RecommenderAgent
的用法示例。
在下文中一共展示了RecommenderAgent.query_recommend_me方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: disabled_test_recagent_query_recommend_me
# 需要导入模块: from softwarecenter.backend.recagent import RecommenderAgent [as 别名]
# 或者: from softwarecenter.backend.recagent.RecommenderAgent import query_recommend_me [as 别名]
def disabled_test_recagent_query_recommend_me(self):
# NOTE: This requires a working recommender host that is reachable
recommender_agent = RecommenderAgent()
recommender_agent.connect("recommend-me", self.on_query_done)
recommender_agent.connect("error", self.on_query_error)
recommender_agent.query_recommend_me()
self.loop.run()
self.assertFalse(self.error)
示例2: RecommendedForYouCategory
# 需要导入模块: from softwarecenter.backend.recagent import RecommenderAgent [as 别名]
# 或者: from softwarecenter.backend.recagent.RecommenderAgent import query_recommend_me [as 别名]
class RecommendedForYouCategory(Category):
__gsignals__ = {
"needs-refresh": (GObject.SIGNAL_RUN_LAST,
GObject.TYPE_NONE,
(),
),
"recommender-agent-error": (GObject.SIGNAL_RUN_LAST,
GObject.TYPE_NONE,
(GObject.TYPE_STRING,),
),
}
def __init__(self, db, subcategory=None):
self.db = db
self.subcategory = subcategory
if subcategory:
# this is the set of recommendations for a given subcategory
cat_title = u"Recommended For You in %s" % (
subcategory.untranslated_name)
tr_title = utf8(_("Recommended For You in %s")) % utf8(
subcategory.name)
else:
# this is the full set of recommendations for e.g. the lobby view
cat_title = u"Recommended For You"
tr_title = _("Recommended For You")
super(RecommendedForYouCategory, self).__init__(
cat_title,
tr_title,
None,
xapian.Query(),
flags=['available-only', 'not-installed-only'],
item_limit=60)
self.recommender_agent = RecommenderAgent()
self.recommender_agent.connect(
"recommend-me", self._recommend_me_result)
self.recommender_agent.connect(
"error", self._recommender_agent_error)
self.recommender_agent.query_recommend_me()
def _recommend_me_result(self, recommender_agent, result_list):
pkgs = []
for item in result_list['data']:
pkgs.append(item['package_name'])
if self.subcategory:
self.query = xapian.Query(xapian.Query.OP_AND,
self.db.get_query_for_pkgnames(pkgs),
self.subcategory.query)
else:
self.query = self.db.get_query_for_pkgnames(pkgs)
self.emit("needs-refresh")
def _recommender_agent_error(self, recommender_agent, msg):
LOG.warn("Error while accessing the recommender service: %s"
% msg)
self.emit("recommender-agent-error", msg)
示例3: RecommendedForYouCategory
# 需要导入模块: from softwarecenter.backend.recagent import RecommenderAgent [as 别名]
# 或者: from softwarecenter.backend.recagent.RecommenderAgent import query_recommend_me [as 别名]
class RecommendedForYouCategory(Category):
__gsignals__ = {
"needs-refresh" : (GObject.SIGNAL_RUN_LAST,
GObject.TYPE_NONE,
(),
),
"recommender-agent-error" : (GObject.SIGNAL_RUN_LAST,
GObject.TYPE_NONE,
(GObject.TYPE_STRING,),
),
}
def __init__(self):
super(RecommendedForYouCategory, self).__init__(
u"Recommended for You", _("Recommended for You"), None,
xapian.Query(),flags=['available-only', 'not-installed-only'],
item_limit=60)
self.recommender_agent = RecommenderAgent()
self.recommender_agent.connect(
"recommend-me", self._recommend_me_result)
self.recommender_agent.connect(
"error", self._recommender_agent_error)
self.recommender_agent.query_recommend_me()
def _recommend_me_result(self, recommender_agent, result_list):
pkgs = []
for item in result_list['data']:
pkgs.append(item['package_name'])
self.query = get_query_for_pkgnames(pkgs)
self.emit("needs-refresh")
def _recommender_agent_error(self, recommender_agent, msg):
LOG.warn("Error while accessing the recommender service: %s"
% msg)
self.emit("recommender-agent-error", msg)
示例4: RealTestRecommenderAgent
# 需要导入模块: from softwarecenter.backend.recagent import RecommenderAgent [as 别名]
# 或者: from softwarecenter.backend.recagent.RecommenderAgent import query_recommend_me [as 别名]
class RealTestRecommenderAgent(unittest.TestCase):
""" tests the recommender agent """
@unittest.skipIf(os.getuid() == 0,
"this is not supported running as root")
def setUp(self):
self.loop = GLib.MainLoop(GLib.main_context_default())
self.error = False
if "SOFTWARE_CENTER_RECOMMENDER_HOST" in os.environ:
orig_host = os.environ.get("SOFTWARE_CENTER_RECOMMENDER_HOST")
self.addCleanup(os.environ.__setitem__,
"SOFTWARE_CENTER_RECOMMENDER_HOST", orig_host)
else:
self.addCleanup(os.environ.pop, "SOFTWARE_CENTER_RECOMMENDER_HOST")
server = "https://rec.staging.ubuntu.com"
os.environ["SOFTWARE_CENTER_RECOMMENDER_HOST"] = server
# most tests need it
self.recommender_agent = RecommenderAgent()
self.recommender_agent.connect("error", self.on_query_error)
def on_query_done(self, recagent, data):
#print "query done, data: '%s'" % data
self.loop.quit()
self.error = False
self.error_msg = ""
def on_query_error(self, recagent, error):
#print "query error received: ", error
self.loop.quit()
self.error = True
self.error_msg = error
def assertServerReturnsWithNoError(self):
self.loop.run()
self.assertFalse(self.error, "got error: '%s'" % self.error_msg)
def test_recagent_query_server_status(self):
self.recommender_agent.connect("server-status", self.on_query_done)
self.recommender_agent.query_server_status()
self.assertServerReturnsWithNoError()
@unittest.skip("server returns 401")
def test_recagent_post_submit_profile(self):
# NOTE: This requires a working recommender host that is reachable
db = get_test_db()
self.recommender_agent.connect(
"submit-profile-finished", self.on_query_done)
self.recommender_agent.post_submit_profile(db)
self.assertServerReturnsWithNoError()
#print mock_request._post
@unittest.skip("server returns 401")
def test_recagent_query_submit_anon_profile(self):
self.recommender_agent.connect(
"submit-anon-profile-finished", self.on_query_done)
self.recommender_agent.post_submit_anon_profile(
uuid="xxxyyyzzz",
installed_packages=["pitivi", "fretsonfire"],
extra="")
self.assertServerReturnsWithNoError()
@unittest.skip("server returns 401")
def test_recagent_query_profile(self):
self.recommender_agent.connect("profile", self.on_query_done)
self.recommender_agent.query_profile(pkgnames=["pitivi", "fretsonfire"])
self.assertServerReturnsWithNoError()
@unittest.skip("server returns 401")
def test_recagent_query_recommend_me(self):
self.recommender_agent.connect("recommend-me", self.on_query_done)
self.recommender_agent.query_recommend_me()
self.assertServerReturnsWithNoError()
def test_recagent_query_recommend_app(self):
self.recommender_agent.connect("recommend-app", self.on_query_done)
self.recommender_agent.query_recommend_app("pitivi")
self.assertServerReturnsWithNoError()
def test_recagent_query_recommend_all_apps(self):
self.recommender_agent.connect("recommend-all-apps", self.on_query_done)
self.recommender_agent.query_recommend_all_apps()
self.assertServerReturnsWithNoError()
def test_recagent_query_recommend_top(self):
self.recommender_agent.connect("recommend-top", self.on_query_done)
self.recommender_agent.query_recommend_top()
self.assertServerReturnsWithNoError()
def test_recagent_query_error(self):
# NOTE: This tests the error condition itself! it simply forces an error
# 'cuz there definitely isn't a server here :)
fake_server = "https://test-no-server-here.staging.ubuntu.com"
os.environ["SOFTWARE_CENTER_RECOMMENDER_HOST"] = fake_server
recommender_agent = RecommenderAgent()
recommender_agent.connect("recommend-top", self.on_query_done)
recommender_agent.connect("error", self.on_query_error)
recommender_agent.query_recommend_top()
self.loop.run()
self.assertTrue(self.error)
#.........这里部分代码省略.........