tools/sort_sources.py
def ProcessFile(filename, should_confirm):
  """Process the input file and rewrite if needed.

  Args:
    filename: Path to the input file.
    should_confirm: If true, diff and confirmation prompt are shown.
  """

  original_lines = []
  with open(filename, 'r') as input_file:
    for line in input_file:
      original_lines.append(line)

  new_lines = SortSources(original_lines)
  if original_lines == new_lines:
    print('%s: no change' % filename)
    return

  if should_confirm:
    diff = difflib.unified_diff(original_lines, new_lines)
    sys.stdout.writelines(diff)
    if not YesNo('Use new file (y/N)'):
      return

  with open(filename, 'w') as output_file:
    output_file.writelines(new_lines)
Process the input file and rewrite if needed.

  Args:
    filename: Path to the input file.
    should_confirm: If true, diff and confirmation prompt are shown.
  
Process the input file and rewrite if needed.
Process the input file and rewrite if needed .
def ProcessFile(filename, should_confirm):
  original_lines = []
  with open(filename, 'r') as input_file:
    for line in input_file:
      original_lines.append(line)
  new_lines = SortSources(original_lines)
  if original_lines == new_lines:
    print('%s: no change' % filename)
    return
  if should_confirm:
    diff = difflib.unified_diff(original_lines, new_lines)
    sys.stdout.writelines(diff)
    if not YesNo('Use new file (y/N)'):
      return
  with open(filename, 'w') as output_file:
    output_file.writelines(new_lines)
def ProcessFile ( filename , should_confirm ) : original_lines = [ ] with open ( filename , 'r' ) as input_file : for line in input_file : original_lines . append ( line ) new_lines = SortSources ( original_lines ) if original_lines == new_lines : print ( '%s: no change' % filename ) return if should_confirm : diff = difflib . unified_diff ( original_lines , new_lines ) sys . stdout . writelines ( diff ) if not YesNo ( 'Use new file (y/N)' ) : return with open ( filename , 'w' ) as output_file : output_file . writelines ( new_lines )
Process the input file and rewrite if needed.
Process the input file and rewrite if needed .
"""Process the input file and rewrite if needed.

  Args:
    filename: Path to the input file.
    should_confirm: If true, diff and confirmation prompt are shown.
  """
filename
Path to the input file.
Path to the input file .
should_confirm
If true, diff and confirmation prompt are shown.
If true diff and confirmation prompt are shown .