From b18fb2ce56255035fe92c3af0dba1391235c5081 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Sat, 3 Dec 2011 14:17:27 +0000 Subject: [PATCH] Updated select.py and background.py to use new Driver API --- zeroinstall/cmd/select.py | 24 ++++++++++++------------ zeroinstall/injector/background.py | 30 +++++++++++++++--------------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/zeroinstall/cmd/select.py b/zeroinstall/cmd/select.py index bd5fa8d..291b53d 100644 --- a/zeroinstall/cmd/select.py +++ b/zeroinstall/cmd/select.py @@ -13,7 +13,7 @@ import logging from zeroinstall import _ from zeroinstall.cmd import UsageError from zeroinstall.injector import model, selections, requirements -from zeroinstall.injector.policy import Policy +from zeroinstall.injector.driver import Driver from zeroinstall.support import tasks syntax = "URI" @@ -64,7 +64,7 @@ def get_selections(config, options, iface_uri, select_only, download_only, test_ r = requirements.Requirements(iface_uri) r.parse_options(options) - policy = Policy(config = config, requirements = r) + driver = Driver(config = config, requirements = r) # Note that need_download() triggers a solve if options.refresh or options.gui: @@ -73,12 +73,12 @@ def get_selections(config, options, iface_uri, select_only, download_only, test_ else: if select_only: # --select-only: we only care that we've made a selection, not that we've cached the implementations - policy.need_download() - can_run_immediately = policy.ready + driver.need_download() + can_run_immediately = driver.solver.ready else: - can_run_immediately = not policy.need_download() + can_run_immediately = not driver.need_download() - stale_feeds = [feed for feed in policy.solver.feeds_used if + stale_feeds = [feed for feed in driver.solver.feeds_used if not os.path.isabs(feed) and # Ignore local feeds (note: file might be missing too) not feed.startswith('distribution:') and # Ignore (memory-only) PackageKit feeds iface_cache.is_stale(iface_cache.get_feed(feed), config.freshness)] @@ -88,14 +88,14 @@ def get_selections(config, options, iface_uri, select_only, download_only, test_ if can_run_immediately: if stale_feeds: - if policy.network_use == model.network_offline: + if config.network_use == model.network_offline: logging.debug(_("No doing background update because we are in off-line mode.")) else: # There are feeds we should update, but we can run without them. # Do the update in the background while the program is running. from zeroinstall.injector import background - background.spawn_background_update(policy, options.verbose > 0) - return policy.solver.selections + background.spawn_background_update(driver, options.verbose > 0) + return driver.solver.selections # If the user didn't say whether to use the GUI, choose for them. if options.gui is None and os.environ.get('DISPLAY', None): @@ -106,7 +106,7 @@ def get_selections(config, options, iface_uri, select_only, download_only, test_ logging.info(_("Switching to GUI mode... (use --console to disable)")) if options.gui: - gui_args = policy.requirements.get_as_options() + gui_args = driver.requirements.get_as_options() if download_only: # Just changes the button's label gui_args.append('--download-only') @@ -129,11 +129,11 @@ def get_selections(config, options, iface_uri, select_only, download_only, test_ return None # Aborted else: # Note: --download-only also makes us stop and download stale feeds first. - downloaded = policy.solve_and_download_impls(refresh = options.refresh or download_only or False, + downloaded = driver.solve_and_download_impls(refresh = options.refresh or download_only or False, select_only = select_only) if downloaded: tasks.wait_for_blocker(downloaded) - sels = policy.solver.selections + sels = driver.solver.selections return sels diff --git a/zeroinstall/injector/background.py b/zeroinstall/injector/background.py index dd35744..a7acccf 100644 --- a/zeroinstall/injector/background.py +++ b/zeroinstall/injector/background.py @@ -176,15 +176,16 @@ def _detach(): return False -def _check_for_updates(old_policy, verbose): +def _check_for_updates(requirements, verbose): from zeroinstall.injector.policy import Policy from zeroinstall.injector.config import load_config - iface_cache = old_policy.config.iface_cache - root_iface = iface_cache.get_interface(old_policy.root).get_name() + background_handler = BackgroundHandler(requirements.interface_uri, requirements.interface_uri) + background_config = load_config(background_handler) + root_iface = background_config.iface_cache.get_interface(requirements.interface_uri).get_name() + background_handler.title = root_iface - background_config = load_config(BackgroundHandler(root_iface, old_policy.root)) - policy = Policy(config = background_config, requirements = old_policy.requirements) + policy = Policy(config = background_config, requirements = requirements) info(_("Checking for updates to '%s' in a background process"), root_iface) if verbose: @@ -219,27 +220,26 @@ def _check_for_updates(old_policy, verbose): _exec_gui(policy.root, '--refresh', '--systray') sys.exit(1) -def spawn_background_update(policy, verbose): +def spawn_background_update(driver, verbose): """Spawn a detached child process to check for updates. - @param policy: policy containing interfaces to update - @type policy: L{policy.Policy} + @param driver: driver containing interfaces to update + @type policy: L{driver.Driver} @param verbose: whether to notify the user about minor events - @type verbose: bool""" - iface_cache = policy.config.iface_cache + @type verbose: bool + @since: 1.5 (used to take a Policy)""" + iface_cache = driver.config.iface_cache # Mark all feeds as being updated. Do this before forking, so that if someone is # running lots of 0launch commands in series on the same program we don't start # huge numbers of processes. - for uri in policy.solver.selections.selections: - iface_cache.mark_as_checking(uri) # Main feed - for f in policy.usable_feeds(iface_cache.get_interface(uri)): - iface_cache.mark_as_checking(f.uri) # Extra feeds + for uri in driver.solver.feeds_used: + iface_cache.mark_as_checking(uri) if _detach(): return try: try: - _check_for_updates(policy, verbose) + _check_for_updates(driver.requirements, verbose) except SystemExit: raise except: -- 2.11.4.GIT