From 459f532d64de1671cc3e13a88687c3c9f1e1cdf3 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Mon, 14 Jun 2010 18:58:01 +0100 Subject: [PATCH] Added update_local attribute to solve_with_downloads If set, feeds starting with 'distribution:' are refreshed but others aren't. The idea is that these feeds represent information from a local package manager. --- zeroinstall/0launch-gui/main.py | 2 +- zeroinstall/injector/cli.py | 4 +++- zeroinstall/injector/policy.py | 34 ++++++++++++++++++++++++++-------- zeroinstall/injector/solver.py | 4 ++-- 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/zeroinstall/0launch-gui/main.py b/zeroinstall/0launch-gui/main.py index 2e0d299..b718aaa 100644 --- a/zeroinstall/0launch-gui/main.py +++ b/zeroinstall/0launch-gui/main.py @@ -148,7 +148,7 @@ def run_gui(args): window.refresh_button.set_sensitive(False) window.browser.set_update_icons(force_refresh) - solved = policy.solve_with_downloads(force = force_refresh) + solved = policy.solve_with_downloads(force = force_refresh, update_local = True) if not window.systray_icon: window.show() diff --git a/zeroinstall/injector/cli.py b/zeroinstall/injector/cli.py index b1b1818..a4d4bd1 100644 --- a/zeroinstall/injector/cli.py +++ b/zeroinstall/injector/cli.py @@ -191,7 +191,9 @@ def _normal_mode(options, args): else: can_run_immediately = not policy.need_download() - stale_feeds = [feed for feed in policy.solver.feeds_used if policy.is_stale(iface_cache.get_feed(feed))] + stale_feeds = [feed for feed in policy.solver.feeds_used if + not feed.startswith('distribution:') and # Ignore (memory-only) PackageKit feeds + policy.is_stale(iface_cache.get_feed(feed))] if options.download_only and stale_feeds: can_run_immediately = False diff --git a/zeroinstall/injector/policy.py b/zeroinstall/injector/policy.py index 359cbe9..cbd3b4b 100644 --- a/zeroinstall/injector/policy.py +++ b/zeroinstall/injector/policy.py @@ -298,11 +298,12 @@ class Policy(object): return [iface_cache.get_interface(uri) for uri in feed_targets] @tasks.async - def solve_with_downloads(self, force = False): + def solve_with_downloads(self, force = False, update_local = False): """Run the solver, then download any feeds that are missing or that need to be updated. Each time a new feed is imported into the cache, the solver is run again, possibly adding new downloads. - @param force: whether to download even if we're already ready to run.""" + @param force: whether to download even if we're already ready to run. + @param update_local: fetch PackageKit feeds even if we're ready to run.""" downloads_finished = set() # Successful or otherwise downloads_in_progress = {} # URL -> Download @@ -311,16 +312,26 @@ class Policy(object): if self.src: host_arch = arch.SourceArchitecture(host_arch) + # There are three cases: + # 1. We want to run immediately if possible. If not, download all the information we can. + # (force = False, update_local = False) + # 2. We're in no hurry, but don't want to use the network unnecessarily. + # We should still update local information (from PackageKit). + # (force = False, update_local = True) + # 3. The user explicitly asked us to refresh everything. + # (force = True) + + try_quick_exit = not (force or update_local) + while True: self.solver.solve(self.root, host_arch) for w in self.watchers: w() - if self.solver.ready and not force: + if try_quick_exit and self.solver.ready: break - else: - if self.network_use == network_offline and not force: - info(_("Can't choose versions and in off-line mode, so aborting")) - break + try_quick_exit = False + + if not self.solver.ready: # Once we've starting downloading some things, # we might as well get them all. force = True @@ -330,11 +341,18 @@ class Policy(object): continue if os.path.isabs(f): continue - downloads_in_progress[f] = self.fetcher.download_and_import_feed(f, iface_cache) + elif f.startswith('distribution:'): + if force or update_local: + downloads_in_progress[f] = self.fetcher.download_and_import_feed(f, iface_cache) + elif force and self.network_use != network_offline: + downloads_in_progress[f] = self.fetcher.download_and_import_feed(f, iface_cache) if not downloads_in_progress: + if self.network_use == network_offline: + info(_("Can't choose versions and in off-line mode, so aborting")) break + # Wait for at least one download to finish blockers = downloads_in_progress.values() yield blockers tasks.check(blockers, self.handler.report_error) diff --git a/zeroinstall/injector/solver.py b/zeroinstall/injector/solver.py index 9143b23..568eeee 100644 --- a/zeroinstall/injector/solver.py +++ b/zeroinstall/injector/solver.py @@ -319,8 +319,8 @@ class SATSolver(Solver): try: feed = self.iface_cache.get_feed(f) if feed is None: continue - if feed.name and iface.uri != feed.url and iface.uri not in feed.feed_for: - info(_("Missing for '%(uri)s' in '%(feed)s'"), {'uri': iface.uri, 'feed': f}) + #if feed.name and iface.uri != feed.url and iface.uri not in feed.feed_for: + # info(_("Missing for '%(uri)s' in '%(feed)s'"), {'uri': iface.uri, 'feed': f}) if feed.implementations: impls.extend(feed.implementations.values()) -- 2.11.4.GIT