From 16b0675fe6641e2a35e6db67afd53cbfee677ae4 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Thu, 3 Feb 2005 20:34:47 +0000 Subject: [PATCH] Never choose an unusable impl. git-svn-id: file:///home/talex/Backups/sf.net/Subversion/zero-install/injector/head@36 9f8c893c-44ee-0310-b757-c8ca8341c71e --- model.py | 25 +++++++++++++++++++++++-- policy.py | 2 ++ run.py | 13 ++++++++++--- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/model.py b/model.py index 886fdeb..d62f0b9 100644 --- a/model.py +++ b/model.py @@ -68,7 +68,7 @@ class Dependency(object): class Implementation(object): """An Implementation is a package which implements an Interface.""" __slots__ = ['path', 'arch', 'upstream_stability', 'user_stability', - 'version', 'size', 'dependencies'] + 'version', 'size', 'dependencies', '_cached'] def __init__(self, path): assert path @@ -78,13 +78,24 @@ class Implementation(object): self.user_stability = None self.upstream_stability = None self.arch = None + self._cached = None self.dependencies = {} # URI -> Dependency def get_stability(self): return self.user_stability or self.upstream_stability or testing def get_cached(self): - return os.path.exists(self.path) + if self._cached is None: + self._cached = False + if os.path.exists(self.path): + cache_dir = cache_for(self.path) + for x in os.listdir(cache_dir): + if x[0] == '.': continue + if x == 'AppInfo.xml': continue + if os.path.isfile(os.path.join(cache_dir, x)): + self._cached = True + break + return self._cached def get_version(self): return '.'.join(map(str, self.version)) @@ -156,3 +167,13 @@ def escape(uri): class SafeException(Exception): pass + +try: + _cache = os.readlink('/uri/0install/.lazyfs-cache') +except: + _cache = None +def cache_for(path): + prefix = '/uri/0install/' + if path.startswith(prefix) and _cache: + return os.path.join(_cache, path[len(prefix):]) + return path diff --git a/policy.py b/policy.py index a741ded..ff9e43c 100644 --- a/policy.py +++ b/policy.py @@ -64,6 +64,8 @@ class Policy(object): for x in impls[1:]: if self.compare(iface, x, best) < 0: best = x + if self.is_unusable(best): + return None return best def compare(self, interface, b, a): diff --git a/run.py b/run.py index ea9574c..606f7a9 100644 --- a/run.py +++ b/run.py @@ -33,6 +33,13 @@ def get_impl(interface): try: return policy.implementation[interface] except KeyError: - raise SafeException("We don't have enough information to " - "run this program yet. " - "Need to download:\n%s" % interface.uri) + if not interface.name: + raise SafeException("We don't have enough information to " + "run this program yet. " + "Need to download:\n%s" % interface.uri) + if interface.implementations: + offline = "" + if policy.network_use == network_offline: + offline = "\nThis may be because 'Network Use' is set to Off-line." + raise SafeException("No usable implementation found for '%s'.%s" % + (interface.name, offline)) -- 2.11.4.GIT