summaryrefslogtreecommitdiffstats
path: root/tools/sort-headers.py
diff options
context:
space:
mode:
authorscottmg@chromium.org <scottmg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-04 06:27:38 +0000
committerscottmg@chromium.org <scottmg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-04 06:27:38 +0000
commit4a2a50cb21a126dfc04a4166f96efdd53299bf40 (patch)
tree26618237fa9798c51b84063245e63ae6667f5a1e /tools/sort-headers.py
parent8ce8d2cd31361bc50f3ec329606290aa29676897 (diff)
downloadchromium_src-4a2a50cb21a126dfc04a4166f96efdd53299bf40.zip
chromium_src-4a2a50cb21a126dfc04a4166f96efdd53299bf40.tar.gz
chromium_src-4a2a50cb21a126dfc04a4166f96efdd53299bf40.tar.bz2
fix tools/sort-headers.py on non-cygwin windows
Review URL: https://chromiumcodereview.appspot.com/16140018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@203867 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/sort-headers.py')
-rwxr-xr-xtools/sort-headers.py34
1 files changed, 21 insertions, 13 deletions
diff --git a/tools/sort-headers.py b/tools/sort-headers.py
index ac20ca1..fb70678 100755
--- a/tools/sort-headers.py
+++ b/tools/sort-headers.py
@@ -12,8 +12,6 @@ Works great with tools/git/for-all-touched-files.py.
import optparse
import os
import sys
-import termios
-import tty
def YesNo(prompt):
@@ -21,14 +19,20 @@ def YesNo(prompt):
print prompt,
sys.stdout.flush()
# http://code.activestate.com/recipes/134892/
- fd = sys.stdin.fileno()
- old_settings = termios.tcgetattr(fd)
- ch = 'n'
- try:
- tty.setraw(sys.stdin.fileno())
- ch = sys.stdin.read(1)
- finally:
- termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
+ if sys.platform == 'win32':
+ import msvcrt
+ ch = msvcrt.getch()
+ else:
+ import termios
+ import tty
+ fd = sys.stdin.fileno()
+ old_settings = termios.tcgetattr(fd)
+ ch = 'n'
+ try:
+ tty.setraw(sys.stdin.fileno())
+ ch = sys.stdin.read(1)
+ finally:
+ termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
print ch
return ch in ('Y', 'y')
@@ -91,14 +95,16 @@ def FixFileWithConfirmFunction(filename, confirm_function):
false to not use it.
"""
fixfilename = filename + '.new'
- infile = open(filename, 'r')
- outfile = open(fixfilename, 'w')
+ infile = open(filename, 'rb')
+ outfile = open(fixfilename, 'wb')
SortHeader(infile, outfile)
infile.close()
outfile.close() # Important so the below diff gets the updated contents.
try:
if confirm_function(filename, fixfilename):
+ if sys.platform == 'win32':
+ os.unlink(filename)
os.rename(fixfilename, filename)
finally:
try:
@@ -116,7 +122,9 @@ def DiffAndConfirm(filename, should_confirm):
"""
def ConfirmFunction(filename, fixfilename):
diff = os.system('diff -u %s %s' % (filename, fixfilename))
- if diff >> 8 == 0: # Check exit code.
+ if sys.platform != 'win32':
+ diff >>= 8
+ if diff == 0: # Check exit code.
print '%s: no change' % filename
return False