From 0047ab179ea19b62a135073232ac2d2efa74f985 Mon Sep 17 00:00:00 2001 From: Tim Diels Date: Wed, 1 Jun 2011 15:23:45 +0200 Subject: [PATCH] Extracted ZeroInstallImplementation.retrieve from Fetcher.download_impl --- zeroinstall/injector/fetch.py | 30 +----------------------------- zeroinstall/injector/model.py | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 29 deletions(-) diff --git a/zeroinstall/injector/fetch.py b/zeroinstall/injector/fetch.py index 98450f0..3b159a0 100644 --- a/zeroinstall/injector/fetch.py +++ b/zeroinstall/injector/fetch.py @@ -311,35 +311,7 @@ class Fetcher(object): if isinstance(retrieval_method, DistributionSource): return retrieval_method.install(self.handler) - best = impl.best_digest - - if best is None: - if not impl.digests: - raise SafeException(_("No given for '%(implementation)s' version %(version)s") % - {'implementation': impl.feed.get_name(), 'version': impl.get_version()}) - raise SafeException(_("Unknown digest algorithms '%(algorithms)s' for '%(implementation)s' version %(version)s") % - {'algorithms': impl.digests, 'implementation': impl.feed.get_name(), 'version': impl.get_version()}) - else: - alg, required_digest = best - - @tasks.async - def download_impl(): - if isinstance(retrieval_method, DownloadSource): - blocker, stream = self.download_archive(retrieval_method, force = force, impl_hint = impl) - yield blocker - tasks.check(blocker) - - stream.seek(0) - self._add_to_cache(required_digest, stores, retrieval_method, stream) - elif isinstance(retrieval_method, Recipe): - blocker = self.cook(required_digest, retrieval_method, stores, force, impl_hint = impl) - yield blocker - tasks.check(blocker) - else: - raise Exception(_("Unknown download type for '%s'") % retrieval_method) - - self.handler.impl_added_to_store(impl) - return download_impl() + return impl.retrieve(self, retrieval_method, stores, force) def _add_to_cache(self, required_digest, stores, retrieval_method, stream): assert isinstance(retrieval_method, DownloadSource) diff --git a/zeroinstall/injector/model.py b/zeroinstall/injector/model.py index b2bc1c7..9fa6830 100644 --- a/zeroinstall/injector/model.py +++ b/zeroinstall/injector/model.py @@ -20,6 +20,7 @@ from zeroinstall import SafeException, version from zeroinstall.injector.namespaces import XMLNS_IFACE from zeroinstall.injector import qdom from zeroinstall.zerostore import unpack +from zeroinstall.support import tasks # Element names for bindings in feed files binding_names = frozenset(['environment', 'overlay']) @@ -724,6 +725,44 @@ class ZeroInstallImplementation(Implementation): else: return None + def retrieve(self, fetcher, retrieval_method, stores, force = False): + """Retrieve an implementation. + @param retrieval_method: a way of getting the implementation (e.g. an Archive or a Recipe) + @type retrieval_method: L{model.RetrievalMethod} + @param stores: where to store the downloaded implementation + @type stores: L{zerostore.Stores} + @param force: whether to abort and restart an existing download + @rtype: L{tasks.Blocker}""" + best = self.best_digest + + if best is None: + if not self.digests: + raise SafeException(_("No given for '%(implementation)s' version %(version)s") % + {'implementation': self.feed.get_name(), 'version': self.get_version()}) + raise SafeException(_("Unknown digest algorithms '%(algorithms)s' for '%(implementation)s' version %(version)s") % + {'algorithms': self.digests, 'implementation': self.feed.get_name(), 'version': self.get_version()}) + else: + alg, required_digest = best + + @tasks.async + def retrieve(): + if isinstance(retrieval_method, DownloadSource): + blocker, stream = fetcher.download_archive(retrieval_method, force = force, impl_hint = self) + yield blocker + tasks.check(blocker) + + stream.seek(0) + fetcher._add_to_cache(required_digest, stores, retrieval_method, stream) + elif isinstance(retrieval_method, Recipe): + blocker = fetcher.cook(required_digest, retrieval_method, stores, force, impl_hint = self) + yield blocker + tasks.check(blocker) + else: + raise Exception(_("Unknown download type for '%s'") % retrieval_method) + + fetcher.handler.impl_added_to_store(self) + return retrieve() + class Interface(object): """An Interface represents some contract of behaviour. @ivar uri: the URI for this interface. -- 2.11.4.GIT