def update_from_software_center_agent(db, cache, ignore_cache=False,
include_sca_qa=False):
""" update index based on the software-center-agent data """
def _available_cb(sca, available):
# print "available: ", available
LOG.debug("available: '%s'" % available)
sca.available = available
sca.good_data = True
loop.quit()
def _error_cb(sca, error):
LOG.warn("error: %s" % error)
sca.available = []
sca.good_data = False
loop.quit()
# use the anonymous interface to s-c-agent, scales much better and is
# much cache friendlier
from softwarecenter.backend.scagent import SoftwareCenterAgent
# FIXME: honor ignore_etag here somehow with the new piston based API
sca = SoftwareCenterAgent(ignore_cache)
sca.connect("available", _available_cb)
sca.connect("error", _error_cb)
sca.available = None
if include_sca_qa:
sca.query_available_qa()
else:
sca.query_available()
# create event loop and run it until data is available
# (the _available_cb and _error_cb will quit it)
context = GObject.main_context_default()
loop = GObject.MainLoop(context)
loop.run()
# process data
for entry in sca.available:
# process events
while context.pending():
context.iteration()
try:
# now the normal parser
parser = SCAApplicationParser(entry)
index_app_info_from_parser(parser, db, cache)
except Exception as e:
LOG.warning("error processing: %s " % e)
# return true if we have updated entries (this can also be an empty list)
# but only if we did not got a error from the agent
return sca.good_data
评论列表
文章目录