From b571f56628fa49f58c8ebb9559397a490b94528a Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Sun, 27 Mar 2011 16:44:01 +0100 Subject: [PATCH] Don't abort if a local feed is missing The staleness check was throwing an exception. Also, added more unicode work-arounds in exception handling --- zeroinstall/cmd/select.py | 7 +++++-- zeroinstall/injector/model.py | 12 ++++++++---- zeroinstall/injector/reader.py | 7 +++++-- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/zeroinstall/cmd/select.py b/zeroinstall/cmd/select.py index 76c3e6d..4d6dd31 100644 --- a/zeroinstall/cmd/select.py +++ b/zeroinstall/cmd/select.py @@ -46,9 +46,11 @@ def get_selections(config, options, iface_uri, select_only, download_only, test_ if options.offline: config.network_use = model.network_offline + iface_cache = config.iface_cache + # Try to load it as a feed. If it is a feed, it'll get cached. If not, it's a # selections document and we return immediately. - maybe_selections = config.iface_cache.get_feed(iface_uri, selections_ok = True) + maybe_selections = iface_cache.get_feed(iface_uri, selections_ok = True) if isinstance(maybe_selections, selections.Selections): if not select_only: blocker = maybe_selections.download_missing(config) @@ -75,8 +77,9 @@ def get_selections(config, options, iface_uri, select_only, download_only, test_ can_run_immediately = not policy.need_download() stale_feeds = [feed for feed in policy.solver.feeds_used if + not os.path.isabs(feed) and # Ignore local feeds (note: file might be missing too) not feed.startswith('distribution:') and # Ignore (memory-only) PackageKit feeds - policy.is_stale(config.iface_cache.get_feed(feed))] + iface_cache.is_stale(iface_cache.get_feed(feed), config.freshness)] if download_only and stale_feeds: can_run_immediately = False diff --git a/zeroinstall/injector/model.py b/zeroinstall/injector/model.py index 42d2f7b..31028ff 100644 --- a/zeroinstall/injector/model.py +++ b/zeroinstall/injector/model.py @@ -55,10 +55,14 @@ class InvalidInterface(SafeException): SafeException.__init__(self, message) - def __str__(self): - if self.feed_url: - return SafeException.__str__(self) + ' in ' + self.feed_url - return SafeException.__str__(self) + def __unicode__(self): + if hasattr(SafeException, '__unicode__'): + # Python >= 2.6 + if self.feed_url: + return _('%s [%s]') % (SafeException.__unicode__(self), self.feed_url) + return SafeException.__unicode__(self) + else: + return unicode(SafeException.__str__(self)) def _split_arch(arch): """Split an arch into an (os, machine) tuple. Either or both parts may be None.""" diff --git a/zeroinstall/injector/reader.py b/zeroinstall/injector/reader.py index 2a1ff05..a7a12d6 100644 --- a/zeroinstall/injector/reader.py +++ b/zeroinstall/injector/reader.py @@ -15,6 +15,9 @@ from zeroinstall.injector.namespaces import config_site, config_prog, XMLNS_IFAC from zeroinstall.injector.model import Interface, InvalidInterface, ZeroInstallFeed, escape, Feed, stability_levels from zeroinstall.injector import model +class MissingLocalFeed(InvalidInterface): + pass + def update_from_cache(interface, iface_cache = None): """Read a cached interface and any native feeds or user overrides. @param interface: the interface object to update @@ -205,8 +208,8 @@ def load_feed(source, local = False, selections_ok = False): try: root = qdom.parse(file(source)) except IOError, ex: - if ex.errno == 2: - raise InvalidInterface(_("Feed not found. Perhaps this is a local feed that no longer exists? You can remove it from the list of feeds in that case."), ex) + if ex.errno == 2 and local: + raise MissingLocalFeed(_("Feed not found. Perhaps this is a local feed that no longer exists? You can remove it from the list of feeds in that case.")) raise InvalidInterface(_("Can't read file"), ex) except Exception, ex: raise InvalidInterface(_("Invalid XML"), ex) -- 2.11.4.GIT