Fix rewrite_includes to work in both Python 2 and 3.

This is patterned after http://review.skia.org/439776, but uses the
`six` library for Python 2/3 cross-compatibility.

Change-Id: If64c48c35d86b83c77316bb5536be6e7bd24c967
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/439936
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: Kevin Lubick <kjlubick@google.com>
Reviewed-by: Kevin Lubick <kjlubick@google.com>
This commit is contained in:
John Stiles 2021-08-16 18:14:52 -04:00 committed by SkCQ
parent 3ed2d0eab2
commit 4498aa8ac7

View File

@ -1,4 +1,4 @@
#!/usr/bin/python2
#!/usr/bin/python
#
# Copyright 2019 Google Inc.
#
@ -6,12 +6,13 @@
# found in the LICENSE file.
from __future__ import print_function
import StringIO
import argparse
import os
import six
import sys
from six import StringIO
parser = argparse.ArgumentParser()
parser.add_argument('-n', '--dry-run', action='store_true',
@ -89,7 +90,7 @@ for file_path in to_rewrite():
lines = open(file_path).readlines()
# Write it back out again line by line with substitutions for #includes.
output = StringIO.StringIO() if args.dry_run else open(file_path, 'wb')
output = StringIO() if args.dry_run else open(file_path, 'w')
includes = []
for line in lines: