From 074dd2de44358a093f53ae4a581872b3fcc33ee4 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Tue, 17 Jun 2008 13:45:11 +0100 Subject: [PATCH] When running with --set-selections, download any missing implementations Note that we don't download or update their feeds yet; we assume that the information about where to get the missing implementations is already cached. --- zeroinstall/injector/cli.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/zeroinstall/injector/cli.py b/zeroinstall/injector/cli.py index 082bcdc..84afe03 100755 --- a/zeroinstall/injector/cli.py +++ b/zeroinstall/injector/cli.py @@ -252,6 +252,43 @@ def _fork_gui(iface_uri, gui_args, prog_args, options = None): bool(options and options.dry_run), options and options.main) return helpers.get_selections_gui(iface_uri, gui_args, test_callback) + +def _download_missing_selections(options, sels): + from zeroinstall.zerostore import NotStored + + # Check that every required selection is cached + needed_downloads = [] + for sel in sels.selections.values(): + iid = sel.id + if not iid.startswith('/'): + try: + iface_cache.stores.lookup(iid) + except NotStored, ex: + logging.info("Not stored: %s", ex) + needed_downloads.append(sel) + if not needed_downloads: + return + + logging.info("Some selected implementations are missing. Attempting to locate them...") + + # We're missing some. For each one, get the feed it came from + # and find the corresponding in that. This will + # tell us where to get it from. + needed_impls = [] + for sel in needed_downloads: + feed_url = sel.attrs.get('from-feed', None) or sel.attrs['interface'] + feed = iface_cache.get_feed(feed_url) + # TODO: we should download missing feeds too + impl = feed.implementations[sel.id] + needed_impls.append(impl) + + from zeroinstall.injector import fetch + from zeroinstall.injector.handler import Handler + handler = Handler(dry_run = options.dry_run) + fetcher = fetch.Fetcher(handler) + blocker = fetcher.download_impls(needed_impls, iface_cache.stores) + logging.info("Waiting for selected implementations to be downloaded...") + handler.wait_for_blocker(blocker) def _get_selections(policy): import selections @@ -326,6 +363,7 @@ def main(command_args): elif options.set_selections: from zeroinstall.injector import selections, qdom, run sels = selections.Selections(qdom.parse(file(options.set_selections))) + _download_missing_selections(options, sels) run.execute_selections(sels, args, options.dry_run, options.main, options.wrapper) elif getattr(options, 'import'): _import_feed(args) -- 2.11.4.GIT