1""" 2Holds information about what the user asked for (which program, version constraints, etc). 3""" 4 5# Copyright (C) 2012, Thomas Leonard 6# See the README file for details, or visit http://0install.net. 7 8fromzeroinstallimportSafeException 9
57"""Update the settings based on the options (used for "0install update APP"). 58 @return: whether any settings were changed 59 @rtype: bool 60 @since: 1.9""" 61restriction_updates=self._handle_restrictions(options) 62 63changed=False 64forkeyin['message','cpu','os','command']: 65value=getattr(options,key) 66ifvalueisnotNone: 67changed=changedorvalue!=getattr(self,key) 68setattr(self,key,value) 69 70foruri,exprinrestriction_updates.items(): 71old=self.extra_restrictions.get(uri,None) 72changed=expr!=old 73ifexpr: 74self.extra_restrictions[uri]=expr 75elifuriinself.extra_restrictions: 76delself.extra_restrictions[uri] 77 78ifoptions.sourceandnotself.source: 79# (partly because it doesn't make much sense, and partly because you 80# can't undo it, as there's no --not-source option) 81raiseSafeException("Can't update from binary to source type!") 82returnchanged
85"""@rtype: [str]""" 86gui_args=[] 87ifself.extra_restrictions: 88# Currently, we only handle the case of restrictions on the root 89foruri,rinself.extra_restrictions.items(): 90gui_args.insert(0,r) 91gui_args.insert(0,uri) 92gui_args.insert(0,'--version-for') 93ifself.source: 94gui_args.insert(0,'--source') 95ifself.message: 96gui_args.insert(0,self.message) 97gui_args.insert(0,'--message') 98ifself.cpu: 99gui_args.insert(0,self.cpu)100gui_args.insert(0,'--cpu')101ifself.os:102gui_args.insert(0,self.os)103gui_args.insert(0,'--os')104gui_args.append('--command')105gui_args.append(self.commandor'')106107returngui_args
110"""Create list of L{model.Restriction}s for each interface, based on these requirements.111 @type iface_cache: L{zeroinstall.injector.iface_cache.IfaceCache}112 @rtype: {L{model.Interface}: [L{model.Restriction}]}"""113fromzeroinstall.injectorimportmodel114115returndict((iface_cache.get_interface(uri),[model.VersionExpressionRestriction(expr)])116foruri,exprinself.extra_restrictions.items())
119"""Gets the list of restrictions specified by the user.120 Handles --before, --not-before, --version and --version-for options.121 If a mapping isn't present, then the user didn't specify a restriction.122 If an entry maps to None, the user wishes to remove the restriction."""123version=options.version124125interface_uri=self.interface_uri126127# Convert old --before and --not_before to new --version-for128ifoptions.beforeisnotNoneoroptions.not_beforeisnotNone:129ifversionisnotNone:130raiseSafeException("Can't use --before or --not-before with --version")131ifoptions.beforeoroptions.not_before:132version=(options.not_beforeor'')+'..'133ifoptions.before:134version+='!'+options.before135else:136version=''# Reset137138restrictions=dict((uri,(exprorNone))for(uri,expr)in(options.version_foror[]))139140# Convert the --version short-cut to --version-for141ifversionisnotNone:142ifinterface_uriinrestrictions:143raiseSafeException("Can't use --version and --version-for to set {uri}".format(uri=interface_uri))144restrictions[interface_uri]=versionorNone145146returnrestrictions