From defddcf2de143ef5b099adc94f2ef5edf76d2b6a Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Sun, 9 Jan 2011 16:13:57 +0000 Subject: [PATCH] Allow passing a selections document in place of a feed --- zeroinstall/cmd/select.py | 7 +++++++ zeroinstall/injector/iface_cache.py | 8 ++++++-- zeroinstall/injector/reader.py | 11 ++++++++--- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/zeroinstall/cmd/select.py b/zeroinstall/cmd/select.py index 201552e..33e71f6 100644 --- a/zeroinstall/cmd/select.py +++ b/zeroinstall/cmd/select.py @@ -43,6 +43,13 @@ def get_selections(options, iface_uri, select_only, download_only, test_callback @return: the selected versions, or None if the user cancels @rtype: L{selections.Selections} | None """ + + # 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 = iface_cache.get_feed(iface_uri, selections_ok = True) + if isinstance(maybe_selections, selections.Selections): + return maybe_selections + root_iface = iface_cache.get_interface(iface_uri) if os.isatty(1): diff --git a/zeroinstall/injector/iface_cache.py b/zeroinstall/injector/iface_cache.py index d8e2760..fbfb61a 100644 --- a/zeroinstall/injector/iface_cache.py +++ b/zeroinstall/injector/iface_cache.py @@ -325,10 +325,11 @@ class IfaceCache(object): self.get_feed(feed_url, force = True) - def get_feed(self, url, force = False): + def get_feed(self, url, force = False, selections_ok = False): """Get a feed from the cache. @param url: the URL of the feed @param force: load the file from disk again + @param selections_ok: if url is a local selections file, return that instead @return: the feed, or None if it isn't cached @rtype: L{model.ZeroInstallFeed}""" if not force: @@ -342,7 +343,10 @@ class IfaceCache(object): return None # Can't happen? feed = self.distro.get_feed(master_feed) else: - feed = reader.load_feed_from_cache(url) + feed = reader.load_feed_from_cache(url, selections_ok = selections_ok) + if selections_ok and feed and not isinstance(feed, model.ZeroInstallFeed): + assert feed.selections is not None + return feed # (it's actually a selections document) if feed: reader.update_user_feed_overrides(feed) self._feeds[url] = feed diff --git a/zeroinstall/injector/reader.py b/zeroinstall/injector/reader.py index b6ecf52..01c0af8 100644 --- a/zeroinstall/injector/reader.py +++ b/zeroinstall/injector/reader.py @@ -42,13 +42,13 @@ def update_from_cache(interface): return main_feed is not None -def load_feed_from_cache(url): +def load_feed_from_cache(url, selections_ok = False): """Load a feed. If the feed is remote, load from the cache. If local, load it directly. @return: the feed, or None if it's remote and not cached.""" try: if os.path.isabs(url): debug(_("Loading local feed file '%s'"), url) - return load_feed(url, local = True) + return load_feed(url, local = True, selections_ok = selections_ok) else: cached = basedir.load_first_cache(config_site, 'interfaces', escape(url)) if cached: @@ -187,12 +187,14 @@ def update(interface, source, local = False): return feed -def load_feed(source, local = False): +def load_feed(source, local = False, selections_ok = False): """Load a feed from a local file. @param source: the name of the file to read @type source: str @param local: this is a local feed @type local: bool + @param selections_ok: if it turns out to be a local selections document, return that instead + @type selections_ok: bool @raise InvalidInterface: if the source's syntax is incorrect @return: the new feed @since: 0.48 @@ -207,6 +209,9 @@ def load_feed(source, local = False): raise InvalidInterface(_("Invalid XML"), ex) if local: + if selections_ok and root.uri == XMLNS_IFACE and root.name == 'selections': + from zeroinstall.injector import selections + return selections.Selections(root) local_path = source else: local_path = None -- 2.11.4.GIT