Change all python files to use Python3

This commit is contained in:
John Newbery 2017-12-12 14:47:24 -05:00
parent ec7dbaa37c
commit bc6fdf2d15
12 changed files with 56 additions and 70 deletions
contrib/devtools

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
#===- clang-format-diff.py - ClangFormat Diff Reformatter ----*- python -*--===#
#
@ -69,10 +69,10 @@ Example usage for git/svn users:
import argparse
import difflib
import io
import re
import string
import subprocess
import StringIO
import sys
@ -133,9 +133,9 @@ def main():
['-lines', str(start_line) + ':' + str(end_line)])
# Reformat files containing changes in place.
for filename, lines in lines_by_file.iteritems():
for filename, lines in lines_by_file.items():
if args.i and args.verbose:
print 'Formatting', filename
print('Formatting {}'.format(filename))
command = [binary, filename]
if args.i:
command.append('-i')
@ -143,8 +143,11 @@ def main():
command.append('-sort-includes')
command.extend(lines)
command.extend(['-style=file', '-fallback-style=none'])
p = subprocess.Popen(command, stdout=subprocess.PIPE,
stderr=None, stdin=subprocess.PIPE)
p = subprocess.Popen(command,
stdout=subprocess.PIPE,
stderr=None,
stdin=subprocess.PIPE,
universal_newlines=True)
stdout, stderr = p.communicate()
if p.returncode != 0:
sys.exit(p.returncode)
@ -152,11 +155,11 @@ def main():
if not args.i:
with open(filename) as f:
code = f.readlines()
formatted_code = StringIO.StringIO(stdout).readlines()
formatted_code = io.StringIO(stdout).readlines()
diff = difflib.unified_diff(code, formatted_code,
filename, filename,
'(before formatting)', '(after formatting)')
diff_string = string.join(diff, '')
diff_string = ''.join(diff)
if len(diff_string) > 0:
sys.stdout.write(diff_string)