def recalculate(): """Ask the mainloop to recalculate. If we're already recalculating, wait for that to finish and then do it again.""" global _recalculate _recalculate.trigger() _recalculate = tasks.Blocker('recalculate')
def prefs_main(): import preferences box = preferences.show_preferences(config) done = tasks.Blocker('close preferences') box.connect('destroy', lambda w: done.trigger()) yield done
# Copyright (C) 2009, Thomas Leonard # See the README file for details, or visit http://0install.net. from __future__ import print_function import os, sys from optparse import OptionParser from zeroinstall import _ from zeroinstall.injector import requirements from zeroinstall.injector.policy import Policy from zeroinstall.injector.config import load_config from zeroinstall.support import tasks _recalculate = tasks.Blocker('recalculate') def recalculate(): """Ask the mainloop to recalculate. If we're already recalculating, wait for that to finish and then do it again.""" global _recalculate _recalculate.trigger() _recalculate = tasks.Blocker('recalculate') def run_gui(args): parser = OptionParser(usage=_("usage: %prog [options] interface")) parser.add_option("", "--before", help=_("choose a version before this"),
def download_and_import_feed(self, feed_url, iface_cache = None): """Download the feed, download any required keys, confirm trust if needed and import. @param feed_url: the feed to be downloaded @type feed_url: str @param iface_cache: (deprecated) @type iface_cache: L{zeroinstall.injector.iface_cache.IfaceCache} | None @rtype: L{zeroinstall.support.tasks.Blocker}""" from .download import DownloadAborted assert iface_cache is None or iface_cache is self.config.iface_cache if not self.config.handler.dry_run: try: self.config.iface_cache.mark_as_checking(feed_url) except OSError as ex: retval = tasks.Blocker("mark_as_checking") retval.trigger(exception = (ex, None)) return retval logger.debug(_("download_and_import_feed %(url)s"), {'url': feed_url}) assert not os.path.isabs(feed_url) if feed_url.startswith('distribution:'): return self.get_packagekit_feed(feed_url) primary = self._download_and_import_feed(feed_url, use_mirror = False, timeout = 5) @tasks.named_async("monitor feed downloads for " + feed_url) def wait_for_downloads(primary): # Download just the upstream feed, unless it takes too long... timeout = primary.dl.timeout yield primary, timeout tasks.check(timeout) try: tasks.check(primary) if primary.happened: return # OK, primary succeeded! # OK, maybe it's just being slow... logger.info("Feed download from %s is taking a long time.", feed_url) primary_ex = None except NoTrustedKeys as ex: raise # Don't bother trying the mirror if we have a trust problem except ReplayAttack as ex: raise # Don't bother trying the mirror if we have a replay attack except DownloadAborted as ex: raise # Don't bother trying the mirror if the user cancelled except SafeException as ex: # Primary failed primary = None primary_ex = ex logger.warning(_("Feed download from %(url)s failed: %(exception)s"), {'url': feed_url, 'exception': ex}) # Start downloading from mirror... mirror = self._download_and_import_feed(feed_url, use_mirror = True) # Wait until both mirror and primary tasks are complete... while True: blockers = list(filter(None, [primary, mirror])) if not blockers: break yield blockers if primary: try: tasks.check(primary) if primary.happened: primary = None # No point carrying on with the mirror once the primary has succeeded if mirror: logger.info(_("Primary feed download succeeded; aborting mirror download for %s") % feed_url) mirror.dl.abort() except SafeException as ex: primary = None primary_ex = ex logger.info(_("Feed download from %(url)s failed; still trying mirror: %(exception)s"), {'url': feed_url, 'exception': ex}) if mirror: try: tasks.check(mirror) if mirror.happened: mirror = None if primary_ex: # We already warned; no need to raise an exception too, # as the mirror download succeeded. primary_ex = None except ReplayAttack as ex: logger.info(_("Version from mirror is older than cached version; ignoring it: %s"), ex) mirror = None primary_ex = None except SafeException as ex: logger.info(_("Mirror download failed: %s"), ex) mirror = None if primary_ex: raise primary_ex return wait_for_downloads(primary)