#NEWLINE# def AddPreferredNetwork( interface , ssid , security , index = ( - 1 ) , password = None , sudo_password = None ) : #NEWLINE# #INDENT# 'Adds |ssid| to the list of preferred networks on |interface|.\n\n  If Python is not running as root and sudo_password is not supplied an\n  authorization dialog will appear.\n\n  Args:\n    interface: the interface to add the preference to.\n    ssid: the SSID of the network.\n    security: the security type of the network, must be in _SECURITY_TYPES.\n    index: optional, the index in the network list to store the network.\n      Defaults to -1, which is the end of the list.\n    password: an optional password for the network to store in the keychain.\n    sudo_password: optional password to get sudo access.\n\n  Raises:\n    PreferenceAdditionError: preference could not be added. Exception message\n      is the stderr.\n    BadSecurityTypeError: specified security type is not valid.\n  ' #NEWLINE# security = security . upper ( ) #NEWLINE# if ( security not in _SECURITY_TYPES ) : #NEWLINE# #INDENT# raise BadSecurityTypeError #NEWLINE# #UNINDENT# args = [ _NETWORK_SETUP , '-addpreferredwirelessnetworkatindex' , interface , ssid , str ( index ) , security ] #NEWLINE# if password : #NEWLINE# #INDENT# args . append ( password ) #NEWLINE# #UNINDENT# ( _ , stderr , rc ) = gmacpyutil . RunProcess ( args , sudo = bool ( sudo_password ) , sudo_password = sudo_password ) #NEWLINE# if rc : #NEWLINE# #INDENT# raise PreferenceAdditionError ( stderr )