Esempio n. 1
0
 def __init__(self, db, backend, icons):
     GObject.GObject.__init__(self)
     self._globalise_instance()
     self.db = db
     self.backend = backend
     self.distro = get_distro()
     self.icons = icons
     # its ok to use the sync version here to get the token, this is
     # very quick
     helper = UbuntuSSO()
     self.oauth_token = helper.find_oauth_token_sync()
Esempio n. 2
0
def update_from_software_center_agent(db,
                                      cache,
                                      ignore_cache=False,
                                      include_sca_qa=False):
    """Update the index based on the software-center-agent data."""
    def _available_cb(sca, available):
        LOG.debug("update_from_software_center_agent: available: %r",
                  available)
        sca.available = available
        sca.good_data = True
        loop.quit()

    def _available_for_me_cb(sca, available_for_me):
        LOG.debug("update_from_software_center_agent: available_for_me: %r",
                  available_for_me)
        sca.available_for_me = available_for_me
        loop.quit()

    def _error_cb(sca, error):
        LOG.warn("update_from_software_center_agent: error: %r", error)
        sca.good_data = False
        loop.quit()

    context = GLib.main_context_default()
    loop = GLib.MainLoop(context)

    sca = SoftwareCenterAgent(ignore_cache)
    sca.connect("available", _available_cb)
    sca.connect("available-for-me", _available_for_me_cb)
    sca.connect("error", _error_cb)
    sca.available = []
    sca.available_for_me = []

    # query what is available for me first
    available_for_me_pkgnames = set()
    # this will ensure we do not trigger a login dialog
    helper = UbuntuSSO()
    token = helper.find_oauth_token_sync()
    if token:
        sca.query_available_for_me(no_relogin=True)
        loop.run()
        for item in sca.available_for_me:
            try:
                parser = SCAPurchasedApplicationParser(item)
                parser.index_app_info(db, cache)
                available_for_me_pkgnames.add(item.application["package_name"])
            except:
                LOG.exception("error processing: %r", item)

    # ... now query all that is available
    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)
    loop.run()

    # process data
    for entry in sca.available:

        # do not add stuff here that's already purchased to avoid duplication
        if entry.package_name in available_for_me_pkgnames:
            continue

        # process events
        while context.pending():
            context.iteration()
        try:
            # now the normal parser
            parser = SCAApplicationParser(entry)
            parser.index_app_info(db, cache)
        except:
            LOG.exception(
                "update_from_software_center_agent: "
                "error processing %r:", entry.name)

    # 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
Esempio n. 3
0
def update_from_software_center_agent(db, cache, ignore_cache=False,
                                      include_sca_qa=False):
    """Update the index based on the software-center-agent data."""

    def _available_cb(sca, available):
        LOG.debug("update_from_software_center_agent: available: %r",
                  available)
        sca.available = available
        sca.good_data = True
        loop.quit()

    def _available_for_me_cb(sca, available_for_me):
        LOG.debug("update_from_software_center_agent: available_for_me: %r",
                  available_for_me)
        sca.available_for_me = available_for_me
        loop.quit()

    def _error_cb(sca, error):
        LOG.warn("update_from_software_center_agent: error: %r", error)
        sca.good_data = False
        loop.quit()

    context = GLib.main_context_default()
    loop = GLib.MainLoop(context)

    sca = SoftwareCenterAgent(ignore_cache)
    sca.connect("available", _available_cb)
    sca.connect("available-for-me", _available_for_me_cb)
    sca.connect("error", _error_cb)
    sca.available = []
    sca.available_for_me = []

    # query what is available for me first
    available_for_me_pkgnames = set()
    # this will ensure we do not trigger a login dialog
    helper = UbuntuSSO()
    token = helper.find_oauth_token_sync()
    if token:
        sca.query_available_for_me(no_relogin=True)
        loop.run()
        for item in sca.available_for_me:
            try:
                parser = SCAPurchasedApplicationParser(item)
                parser.index_app_info(db, cache)
                available_for_me_pkgnames.add(item.application["package_name"])
            except:
                LOG.exception("error processing: %r", item)

    # ... now query all that is available
    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)
    loop.run()

    # process data
    for entry in sca.available:

        # do not add stuff here that's already purchased to avoid duplication
        if entry.package_name in available_for_me_pkgnames:
            continue

        # process events
        while context.pending():
            context.iteration()
        try:
            # now the normal parser
            parser = SCAApplicationParser(entry)
            parser.index_app_info(db, cache)
        except:
            LOG.exception("update_from_software_center_agent: "
                          "error processing %r:", entry.name)

    # 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
Esempio n. 4
0
        LOG.setLevel(logging.DEBUG)

    if args.ignore_cache:
        cachedir = None
    else:
        cachedir = os.path.join(SOFTWARE_CENTER_CACHE_DIR, "piston-helper")

    # check what we need to call
    klass = globals()[args.klass]
    func = args.function
    kwargs = json.loads(args.kwargs or '{}')

    softwarecenter.paths.datadir = args.datadir

    if args.needs_auth:
        helper = UbuntuSSO(args.parent_xid)
        token = helper.get_oauth_token_and_verify_sync(
            no_relogin=args.no_relogin)
        # if we don't have a token, error here
        if not token:
            # it may happen that the parent is closed already so the pipe
            # is gone, that is ok as we exit anyway
            try:
                sys.stderr.write("ERROR: can not obtain a oauth token\n")
            except IOError:
                pass
            sys.exit(1)

        auth = piston_mini_client.auth.OAuthAuthorizer(
            token["token"], token["token_secret"], token["consumer_key"],
            token["consumer_secret"])
Esempio n. 5
0
        LOG.setLevel(logging.DEBUG)

    if args.ignore_cache:
        cachedir = None
    else:
        cachedir = os.path.join(SOFTWARE_CENTER_CACHE_DIR, "piston-helper")
        
    # check what we need to call
    klass = globals()[args.klass]
    func = args.function
    kwargs = json.loads(args.kwargs or '{}')

    softwarecenter.paths.datadir = args.datadir

    if args.needs_auth:
        helper = UbuntuSSO(args.parent_xid)
        token = helper.get_oauth_token_and_verify_sync(
            no_relogin=args.no_relogin)
        # if we don't have a token, error here
        if not token:
            # it may happen that the parent is closed already so the pipe
            # is gone, that is ok as we exit anyway
            try:
                sys.stderr.write("ERROR: can not obtain a oauth token\n")
            except IOError:
                pass
            sys.exit(1)

        auth = piston_mini_client.auth.OAuthAuthorizer(
            token["token"], token["token_secret"],
            token["consumer_key"], token["consumer_secret"])