(keychain, gui=False, password=None)
return keychain == SYSTEM_KEYCHAIN, sudo_pass
Determine if we need sudo and get a sudo password if necessary.

  Args:
    keychain: path to keychain
    gui: True if we are running from the gui
    password: The user's password.

  Returns:
    sudo: True if this is the system keychain and we will need sudo
    sudo_pass: sudo password if necessary, or None if not necessary or not
               available.
Determine if we need sudo and get a sudo password if necessary.
Determine if we need sudo and get a sudo password if necessary .
def _GetSudoContext(keychain, gui=False, password=None):
  """Determine if we need sudo and get a sudo password if necessary.

  Args:
    keychain: path to keychain
    gui: True if we are running from the gui
    password: The user's password.

  Returns:
    sudo: True if this is the system keychain and we will need sudo
    sudo_pass: sudo password if necessary, or None if not necessary or not
               available.
  """

  sudo_pass = None
  if keychain == SYSTEM_KEYCHAIN:

    # If we're given a password we should test if it works for sudo.
    if password:
      (unused_stdout, unused_stderr, return_code) = gmacpyutil.RunProcess(
          ['-v'], sudo=True, sudo_password=password)
      if return_code == 0:
        return keychain == SYSTEM_KEYCHAIN, password

    if gui:
      # If we arrive here it means the password doesn't work for sudo, if this
      # is a gui context, try and get a passwd, otherwise let sudo do the
      # prompting in the terminal
      try:
        sudo_pass = getauth.GetPassword(
            gui=gui, title='Get sudo Password', prompt='sudo password',
            text='Enter local machine password')
      except (EOFError, KeyboardInterrupt):
        logging.exception('Could not get sudo password from GUI prompt')
        raise
  return keychain == SYSTEM_KEYCHAIN, sudo_pass
def _GetSudoContext ( keychain , gui = False , password = None ) : sudo_pass = None if keychain == SYSTEM_KEYCHAIN : # If we're given a password we should test if it works for sudo. if password : ( unused_stdout , unused_stderr , return_code ) = gmacpyutil . RunProcess ( [ '-v' ] , sudo = True , sudo_password = password ) if return_code == 0 : return keychain == SYSTEM_KEYCHAIN , password if gui : # If we arrive here it means the password doesn't work for sudo, if this # is a gui context, try and get a passwd, otherwise let sudo do the # prompting in the terminal try : sudo_pass = getauth . GetPassword ( gui = gui , title = 'Get sudo Password' , prompt = 'sudo password' , text = 'Enter local machine password' ) except ( EOFError , KeyboardInterrupt ) : logging . exception ( 'Could not get sudo password from GUI prompt' ) raise return keychain == SYSTEM_KEYCHAIN , sudo_pass