From b81dd300382cd78babe3421a994f4745e4a6f085 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Tue, 29 Jan 2008 18:46:55 +0000 Subject: [PATCH] Don't use tasks system if nothing needs to be downloaded. --- zeroinstall/injector/autopolicy.py | 3 ++- zeroinstall/injector/iface_cache.py | 9 ++++++++- zeroinstall/injector/policy.py | 20 +++++++++++++++----- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/zeroinstall/injector/autopolicy.py b/zeroinstall/injector/autopolicy.py index 97559a2..15483a6 100644 --- a/zeroinstall/injector/autopolicy.py +++ b/zeroinstall/injector/autopolicy.py @@ -41,7 +41,8 @@ class AutoPolicy(policy.Policy): def execute(self, prog_args, main = None, wrapper = None): downloaded = self.download_impls() - self.handler.wait_for_blocker(downloaded) + if downloaded: + self.handler.wait_for_blocker(downloaded) if not self.download_only: run.execute(self, prog_args, dry_run = self.dry_run, main = main, wrapper = wrapper) else: diff --git a/zeroinstall/injector/iface_cache.py b/zeroinstall/injector/iface_cache.py index 8aea746..00253dd 100644 --- a/zeroinstall/injector/iface_cache.py +++ b/zeroinstall/injector/iface_cache.py @@ -348,9 +348,16 @@ class IfaceCache(object): reader.update_from_cache(interface) def get_feed(self, url): + """Get a feed from the cache. + @param url: the URL of the feed + @return: the feed, or None if it isn't cached + @rtype: L{model.ZeroInstallFeed}""" # TODO: This isn't a good implementation iface = self.get_interface(url) - return iface._main_feed + feed = iface._main_feed + if not isinstance(feed, model.DummyFeed): + return feed + return None def get_interface(self, uri): """Get the interface for uri, creating a new one if required. diff --git a/zeroinstall/injector/policy.py b/zeroinstall/injector/policy.py index 55dd47f..38c2327 100644 --- a/zeroinstall/injector/policy.py +++ b/zeroinstall/injector/policy.py @@ -224,7 +224,12 @@ class Policy(object): def is_stale(self, feed): """Check whether feed needs updating, based on the configured L{freshness}. + None is considered to be stale. @return: true if feed is stale or missing.""" + if feed is None: + return True + if feed.url.startswith('/'): + return False # Local feeds are never stale if feed.last_modified is None: return True # Don't even have it yet now = time.time() @@ -558,7 +563,6 @@ class Policy(object): return False - @tasks.async def download_impls(self): """Download all implementations that are missing from the cache.""" blockers = [] @@ -573,8 +577,14 @@ class Policy(object): "interface!)") blockers.append(self.download_impl(impl, source)) - while blockers: - yield blockers - tasks.check(blockers) + if not blockers: + return None + + @tasks.async + def download_impls(blockers): + while blockers: + yield blockers + tasks.check(blockers) - blockers = [b for b in blockers if not b.happened] + blockers = [b for b in blockers if not b.happened] + return download_impls(blockers) -- 2.11.4.GIT