From 8def0f5ba7c0bdcae915a2d5cc51465e6a5557cd Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Sat, 20 Feb 2010 17:17:28 +0000 Subject: [PATCH] Added Implementation.local_path attribute This is the absolute path of the implementation for local implementations, or None if it's not local (a distribution package or a Zero Install package identified by a digest, whether cached or not). This is so that we can avoid id.startswith('/') checks everywhere, since this doesn't work on Windows. --- 0alias | 8 +++----- zeroinstall/0launch-gui/impl_list.py | 4 ++-- zeroinstall/0launch-gui/utils.py | 2 +- zeroinstall/gtkui/cache.py | 2 +- zeroinstall/injector/model.py | 11 +++++++++++ zeroinstall/injector/policy.py | 8 +++----- zeroinstall/injector/run.py | 9 ++++----- zeroinstall/injector/selections.py | 11 ++++++++--- zeroinstall/injector/solver.py | 2 +- 9 files changed, 34 insertions(+), 23 deletions(-) diff --git a/0alias b/0alias index b081024..8b88848 100755 --- a/0alias +++ b/0alias @@ -115,11 +115,9 @@ if options.manpage: sys.exit(1) selected_impl = sels.selections[interface_uri] - if selected_impl.id.startswith('/'): - impl_path = selected_impl.id - else: - from zeroinstall.injector.iface_cache import iface_cache - impl_path = iface_cache.stores.lookup(selected_impl.id) + + from zeroinstall.injector.iface_cache import iface_cache + impl_path = selected_impl.local_path or iface_cache.stores.lookup(selected_impl.id) if main is None: main = selected_impl.main diff --git a/zeroinstall/0launch-gui/impl_list.py b/zeroinstall/0launch-gui/impl_list.py index 75a2066..4d15ffa 100644 --- a/zeroinstall/0launch-gui/impl_list.py +++ b/zeroinstall/0launch-gui/impl_list.py @@ -59,8 +59,8 @@ class ImplTips(TreeTips): def get_tooltip_text(self): impl = self.item - if impl.id.startswith('/'): - return _("Local: %s") % impl.id + if impl.local_path: + return _("Local: %s") % impl.local_path if impl.id.startswith('package:'): return _("Native package: %s") % impl.id.split(':', 1)[1] if self.policy.get_cached(impl): diff --git a/zeroinstall/0launch-gui/utils.py b/zeroinstall/0launch-gui/utils.py index eeb4593..9a71179 100644 --- a/zeroinstall/0launch-gui/utils.py +++ b/zeroinstall/0launch-gui/utils.py @@ -8,7 +8,7 @@ def get_fetch_info(policy, impl): if impl is None: return "" elif policy.get_cached(impl): - if impl.id.startswith('/'): + if impl.local_path: return _('(local)') elif impl.id.startswith('package:'): return _('(package)') diff --git a/zeroinstall/gtkui/cache.py b/zeroinstall/gtkui/cache.py index 3514e89..eafe239 100644 --- a/zeroinstall/gtkui/cache.py +++ b/zeroinstall/gtkui/cache.py @@ -362,7 +362,7 @@ class CacheExplorer: else: cached_iface = ValidInterface(iface, iface_size) for impl in iface.implementations.values(): - if impl.id.startswith('/') or impl.id.startswith('.'): + if impl.local_path: cached_iface.in_cache.append(LocalImplementation(impl)) if impl.id in unowned: cached_dir = unowned[impl.id].dir diff --git a/zeroinstall/injector/model.py b/zeroinstall/injector/model.py index bba01fc..9b64f44 100644 --- a/zeroinstall/injector/model.py +++ b/zeroinstall/injector/model.py @@ -377,6 +377,8 @@ class Implementation(object): @ivar id: a unique identifier for this Implementation @ivar version: a parsed version number @ivar released: release date + @ivar local_path: the directory containing this local implementation, or None if it isn't local (id isn't a path) + @type local_path: str | None """ # Note: user_stability shouldn't really be here @@ -424,6 +426,8 @@ class Implementation(object): os = None + local_path = None + class DistributionImplementation(Implementation): """An implementation provided by the distribution. Information such as the version comes from the package manager. @@ -457,6 +461,12 @@ class ZeroInstallImplementation(Implementation): def set_arch(self, arch): self.os, self.machine = _split_arch(arch) arch = property(lambda self: _join_arch(self.os, self.machine), set_arch) + + @property + def local_path(self): + if self.id.startswith('/'): + return self.id + return None class Interface(object): """An Interface represents some contract of behaviour. @@ -624,6 +634,7 @@ class ZeroInstallFeed(object): if not feed_src: raise InvalidInterface(_('Missing "src" attribute in ')) if feed_src.startswith('http:') or local_path: + # XXX self.feeds.append(Feed(feed_src, x.getAttribute('arch'), False, langs = x.getAttribute('langs'))) else: raise InvalidInterface(_("Invalid feed URL '%s'") % feed_src) diff --git a/zeroinstall/injector/policy.py b/zeroinstall/injector/policy.py index 8a697d9..e4e9804 100644 --- a/zeroinstall/injector/policy.py +++ b/zeroinstall/injector/policy.py @@ -221,9 +221,7 @@ class Policy(object): @rtype: str @raise zeroinstall.zerostore.NotStored: if it needs to be added to the cache first.""" assert isinstance(impl, Implementation) - if impl.id.startswith('/'): - return impl.id - return iface_cache.stores.lookup(impl.id) + return impl.local_path or iface_cache.stores.lookup(impl.id) def get_implementation(self, interface): """Get the chosen implementation. @@ -257,8 +255,8 @@ class Policy(object): """ if isinstance(impl, DistributionImplementation): return impl.installed - if impl.id.startswith('/'): - return os.path.exists(impl.id) + if impl.local_path: + return os.path.exists(impl.local_path) else: try: path = self.get_implementation_path(impl) diff --git a/zeroinstall/injector/run.py b/zeroinstall/injector/run.py index 9c578fc..2f08d1b 100644 --- a/zeroinstall/injector/run.py +++ b/zeroinstall/injector/run.py @@ -56,11 +56,10 @@ def execute(policy, prog_args, dry_run = False, main = None, wrapper = None): def _do_bindings(impl, bindings): for b in bindings: if isinstance(b, EnvironmentBinding): - do_env_binding(b, _get_implementation_path(impl.id)) + do_env_binding(b, _get_implementation_path(impl)) -def _get_implementation_path(id): - if id.startswith('/'): return id - return iface_cache.stores.lookup(id) +def _get_implementation_path(impl): + return impl.local_path or iface_cache.stores.lookup(impl.id) def execute_selections(selections, prog_args, dry_run = False, main = None, wrapper = None): """Execute program. On success, doesn't return. On failure, raises an Exception. @@ -142,7 +141,7 @@ def _execute(root_impl, prog_args, dry_run, main, wrapper): elif root_impl.main: main = os.path.join(os.path.dirname(root_impl.main), main) if main is not None: - prog_path = os.path.join(_get_implementation_path(root_impl.id), main) + prog_path = os.path.join(_get_implementation_path(root_impl), main) if main is None: raise SafeException(_("Implementation '%s' cannot be executed directly; it is just a library " diff --git a/zeroinstall/injector/selections.py b/zeroinstall/injector/selections.py index 76b040d..c2a5f0c 100644 --- a/zeroinstall/injector/selections.py +++ b/zeroinstall/injector/selections.py @@ -40,6 +40,12 @@ class Selection(object): feed = property(lambda self: self.attrs.get('from-feed', self.interface)) main = property(lambda self: self.attrs.get('main', None)) + @property + def local_path(self): + if self.id.startswith('/'): + return self.id + return None + def __repr__(self): return self.id @@ -197,10 +203,9 @@ class Selections(object): # Check that every required selection is cached needed_downloads = [] for sel in self.selections.values(): - iid = sel.id - if not iid.startswith('/'): + if not sel.local_path: try: - iface_cache.stores.lookup(iid) + iface_cache.stores.lookup(sel.id) except NotStored, ex: needed_downloads.append(sel) if not needed_downloads: diff --git a/zeroinstall/injector/solver.py b/zeroinstall/injector/solver.py index b17aaef..9361bd7 100644 --- a/zeroinstall/injector/solver.py +++ b/zeroinstall/injector/solver.py @@ -272,7 +272,7 @@ class DefaultSolver(Solver): """ if isinstance(impl, model.DistributionImplementation): return impl.installed - if impl.id.startswith('/'): + if impl.local_path: return os.path.exists(impl.id) else: try: -- 2.11.4.GIT