tools/android/sdk_updater/update_sdk.py
def _ReplaceVersionInFile(file_path, pattern, version, dry_run=False):
  """Replace the version of sdk package argument in file.

  Check whether the version in file is the same as the new version first.
  Replace the version if not dry run.

  Args:
    file_path: Path to the file to update the version of sdk package argument.
    pattern: Pattern for the sdk package argument. Must capture at least one
      group that the first group is the argument line excluding version.
    version: The new version of the package.
    dry_run: Bool. To show what packages would be created and packages, without
      actually doing either.
  """
  with tempfile.NamedTemporaryFile() as temp_file:
    with open(file_path) as f:
      for line in f:
        new_line = re.sub(pattern, r'\g<1>\g<2>%s\g<3>\n' % version, line)
        if new_line != line:
          print('    Note: file "%s" argument ' % file_path +
                '"%s" would be updated to "%s".' % (line.strip(), version))
        temp_file.write(new_line)
    if not dry_run:
      temp_file.flush()
      shutil.move(temp_file.name, file_path)
      temp_file.delete = False
Replace the version of sdk package argument in file.

  Check whether the version in file is the same as the new version first.
  Replace the version if not dry run.

  Args:
    file_path: Path to the file to update the version of sdk package argument.
    pattern: Pattern for the sdk package argument. Must capture at least one
      group that the first group is the argument line excluding version.
    version: The new version of the package.
    dry_run: Bool. To show what packages would be created and packages, without
      actually doing either.
  
Replace the version of sdk package argument in file.
Check whether the version in file is the same as the new version first.
Replace the version if not dry run.
Replace the version of sdk package argument in file . Check whether the version in file is the same as the new version first . Replace the version if not dry run .
def _ReplaceVersionInFile(file_path, pattern, version, dry_run=False):
  with tempfile.NamedTemporaryFile() as temp_file:
    with open(file_path) as f:
      for line in f:
        new_line = re.sub(pattern, r'\g<1>\g<2>%s\g<3>\n' % version, line)
        if new_line != line:
          print('    Note: file "%s" argument ' % file_path +
                '"%s" would be updated to "%s".' % (line.strip(), version))
        temp_file.write(new_line)
    if not dry_run:
      temp_file.flush()
      shutil.move(temp_file.name, file_path)
      temp_file.delete = False
def _ReplaceVersionInFile ( file_path , pattern , version , dry_run = False ) : with tempfile . NamedTemporaryFile ( ) as temp_file : with open ( file_path ) as f : for line in f : new_line = re . sub ( pattern , r'\g<1>\g<2>%s\g<3>\n' % version , line ) if new_line != line : print ( '    Note: file "%s" argument ' % file_path + '"%s" would be updated to "%s".' % ( line . strip ( ) , version ) ) temp_file . write ( new_line ) if not dry_run : temp_file . flush ( ) shutil . move ( temp_file . name , file_path ) temp_file . delete = False
Replace the version of sdk package argument in file.
Replace the version of sdk package argument in file .
"""Replace the version of sdk package argument in file.

  Check whether the version in file is the same as the new version first.
  Replace the version if not dry run.

  Args:
    file_path: Path to the file to update the version of sdk package argument.
    pattern: Pattern for the sdk package argument. Must capture at least one
      group that the first group is the argument line excluding version.
    version: The new version of the package.
    dry_run: Bool. To show what packages would be created and packages, without
      actually doing either.
  """
file_path
Path to the file to update the version of sdk package argument.
Path to the file to update the version of sdk package argument .
pattern
Pattern for the sdk package argument. Must capture at least one
group that the first group is the argument line excluding version.
Pattern for the sdk package argument . Must capture at least one group that the first group is the argument line excluding version .
version
The new version of the package.
The new version of the package .
dry_run
Bool. To show what packages would be created and packages, without
actually doing either.
Bool . To show what packages would be created and packages without actually doing either .