22"""All options for selecting.""" 23parser.add_option("","--before",help=_("choose a version before this"),metavar='VERSION') 24parser.add_option("","--command",help=_("command to select"),metavar='COMMAND') 25parser.add_option("","--cpu",help=_("target CPU type"),metavar='CPU') 26parser.add_option("","--message",help=_("message to display when interacting with user")) 27parser.add_option("","--not-before",help=_("minimum version to choose"),metavar='VERSION') 28parser.add_option("-o","--offline",help=_("try to avoid using the network"),action='store_true') 29parser.add_option("","--os",help=_("target operation system type"),metavar='OS') 30parser.add_option("-r","--refresh",help=_("refresh all used interfaces"),action='store_true') 31parser.add_option("-s","--source",help=_("select source code"),action='store_true') 32parser.add_option("","--version",help=_("specify version constraint (e.g. '3' or '3..')"),metavar='RANGE') 33parser.add_option("","--version-for",help=_("set version constraints for a specific interface"), 34nargs=2,metavar='URI RANGE',action='append')
37"""Options for 'select' and 'download' (but not 'run')""" 38add_generic_select_options(parser) 39parser.add_option("","--xml",help=_("write selected versions as XML"),action='store_true')
42"""Get selections for iface_uri, according to the options passed. 43 Will switch to GUI mode if necessary. 44 @type config: L{zeroinstall.injector.config.Config} 45 @param options: options from OptionParser 46 @param iface_uri: canonical URI of the interface 47 @type iface_uri: str 48 @param select_only: return immediately even if the selected versions aren't cached 49 @type select_only: bool 50 @param download_only: wait for stale feeds, and display GUI button as Download, not Run 51 @type download_only: bool 52 @param requirements: requirements to use; if None, requirements come from options (since 1.15) 53 @type requirements: Requirements 54 @return: the selected versions, or None if the user cancels 55 @rtype: L{selections.Selections} | None""" 56ifoptions.offline: 57config.network_use=model.network_offline 58 59iface_cache=config.iface_cache 60 61# Try to load it as a feed. If it is a feed, it'll get cached. If not, it's a 62# selections document and we return immediately. 63maybe_selections=iface_cache.get_feed(iface_uri,selections_ok=True) 64ifisinstance(maybe_selections,selections.Selections): 65ifnotselect_only: 66blocker=maybe_selections.download_missing(config) 67ifblocker: 68logger.info(_("Waiting for selected implementations to be downloaded...")) 69tasks.wait_for_blocker(blocker) 70returnmaybe_selections 71 72ifrequirementsisNone: 73requirements=Requirements(iface_uri) 74requirements.parse_options(options) 75 76returnget_selections_for(requirements,config,options,select_only,download_only,test_callback)
79"""Get selections for given requirements. 80 @type requirements: L{Requirements} 81 @type config: L{zeroinstall.injector.config.Config} 82 @type select_only: bool 83 @type download_only: bool 84 @rtype: L{zeroinstall.injector.selections.Selections} 85 @since: 1.9""" 86ifoptions.offline: 87config.network_use=model.network_offline 88 89iface_cache=config.iface_cache 90 91driver=Driver(config=config,requirements=requirements) 92 93# Note that need_download() triggers a solve 94ifoptions.refreshoroptions.gui: 95# We could run immediately, but the user asked us not to 96can_run_immediately=False 97else: 98ifselect_only: 99# --select-only: we only care that we've made a selection, not that we've cached the implementations100driver.need_download()101can_run_immediately=driver.solver.ready102else:103can_run_immediately=notdriver.need_download()104105stale_feeds=[feedforfeedindriver.solver.feeds_usedif106notfeed.startswith('distribution:')and# Ignore (memory-only) PackageKit feeds107iface_cache.is_stale(feed,config.freshness)]108109ifdownload_onlyandstale_feeds:110can_run_immediately=False111112ifcan_run_immediately:113ifstale_feeds:114ifconfig.network_use==model.network_offline:115logger.debug(_("No doing background update because we are in off-line mode."))116elifoptions.dry_run:117print(_("[dry-run] would check for updates in the background"))118else:119# There are feeds we should update, but we can run without them.120# Do the update in the background while the program is running.121fromzeroinstall.injectorimportbackground122background.spawn_background_update(driver,options.verbose)123returndriver.solver.selections124125# If we need to download anything, we might as well126# refresh all the feeds first.127options.refresh=True128129ifoptions.gui!=False:130# If the user didn't say whether to use the GUI, choose for them.131gui_args=driver.requirements.get_as_options()132ifdownload_only:133# Just changes the button's label134gui_args.append('--download-only')135ifoptions.refresh:136gui_args.append('--refresh')137ifoptions.verbose:138gui_args.insert(0,'--verbose')139ifoptions.verbose>1:140gui_args.insert(0,'--verbose')141ifoptions.with_store:142forxinoptions.with_store:143gui_args+=['--with-store',x]144ifselect_only:145gui_args.append('--select-only')146147fromzeroinstallimporthelpers148sels=helpers.get_selections_gui(requirements.interface_uri,gui_args,test_callback,use_gui=options.gui)149150ifnotsels:151returnNone# Aborted152elifselsishelpers.DontUseGUI:153sels=None154else:155sels=None156157ifselsisNone:158# Note: --download-only also makes us stop and download stale feeds first.159downloaded=driver.solve_and_download_impls(refresh=options.refreshordownload_onlyorFalse,160select_only=select_only)161ifdownloaded:162tasks.wait_for_blocker(downloaded)163sels=driver.solver.selections164165returnsels