def MakeUserSudoer(self, user):
    """Add user to the sudoers file."""
    # If the user has no sudoers file, don't add an entry.
    if not self.os.path.isfile('/etc/sudoers'):
      logging.info('Did not grant admin access to %s. /etc/sudoers not found.',
                   user)
      return

    with self.system.OpenFile('/etc/sudoers', 'r') as sudoer_f:
      sudoer_lines = sudoer_f.readlines()

    if IsUserSudoerInLines(user, sudoer_lines):
      # User is already sudoer.  Done.  We don't have to check for a lock
      # file.
      return

    # Lock sudoers.
    if not self.LockSudoers():
      logging.warning('Did not grant admin access to %s. /etc/sudoers locked.',
                      user)
      return

    try:
      # First read in the sudoers file (this time under the lock).
      with self.system.OpenFile('/etc/sudoers', 'r') as sudoer_f:
        sudoer_lines = sudoer_f.readlines()

      if IsUserSudoerInLines(user, sudoer_lines):
        # User is already sudoer.  Done.
        return

      # Create a temporary sudoers file with the contents we want.
      sudoer_lines.append(user % '%s ALL=NOPASSWD: ALL')
      sudoer_lines = [EnsureTrailingNewline(line) for line in sudoer_lines]
      (tmp_sudoers_fd, tmp_sudoers_fname) = tempfile.mkstemp()
      with self.os.fdopen(tmp_sudoers_fd, 'w+') as tmp_sudoer_f:
        # Put the old lines.
        tmp_sudoer_f.writelines(sudoer_lines)
        tmp_sudoer_f.seek(0)

      try:
        # Validate our result.
        if not self.system.IsValidSudoersFile(tmp_sudoers_fname):
          logging.warning(
              'Did not grant admin access to %s. Sudoers was invalid.', user)
          return

        self.os.chmod('/etc/sudoers', 0640)
        with self.system.OpenFile('/etc/sudoers', 'w') as sudoer_f:
          sudoer_f.writelines(sudoer_lines)
          # Make sure we're still 0640.
          self.os.fchmod(sudoer_f.fileno(), stat.S_IWUSR | 0640)
          try:
            self.os.fchmod(sudoer_f.fileno(), 0440)
          except (IOError, OSError) as e:
            logging.warning('Could not restore perms to /etc/sudoers: %s', e)
      finally:
        # Clean up the temp file.
        try:
          self.os.unlink(tmp_sudoers_fname)
        except (IOError, OSError) as e:
          pass
    except (IOError, OSError) as e:
      logging.warning('Could not grant %s admin access: %s', user, e)
    finally:
      self.UnlockSudoers()
dataset/ETHPy150Open GoogleCloudPlatform/compute-image-packages/google-daemon/usr/share/google/google_daemon/accounts.py/Accounts.MakeUserSudoer/swapped operands of `%`