summaryrefslogtreecommitdiffstats
path: root/tools/sort-headers.py
diff options
context:
space:
mode:
authorjoi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-22 11:28:57 +0000
committerjoi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-22 11:28:57 +0000
commit1836722eb2a7a8506c0ed6e749d683f06b54f40b (patch)
tree1c5fcde8e127cbb5ada8e8842368381673e48db5 /tools/sort-headers.py
parent85b9737db348cfcf0f66962ecfcd9b01f9efe300 (diff)
downloadchromium_src-1836722eb2a7a8506c0ed6e749d683f06b54f40b.zip
chromium_src-1836722eb2a7a8506c0ed6e749d683f06b54f40b.tar.gz
chromium_src-1836722eb2a7a8506c0ed6e749d683f06b54f40b.tar.bz2
Automatically sort headers in files affected by move_source_file.py, and update full-path references in // comments.
Sorting headers does not seem to affect timing appreciably in my test case, but searching for full-path references in comments does increase the time taken by around 20%. If the speed ever becomes a problem, this latter feature could be made optional, but for now it is probably simplest to leave it on all the time. BUG=None Review URL: https://chromiumcodereview.appspot.com/11412006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@169252 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/sort-headers.py')
-rwxr-xr-xtools/sort-headers.py36
1 files changed, 25 insertions, 11 deletions
diff --git a/tools/sort-headers.py b/tools/sort-headers.py
index a786822..501f92c 100755
--- a/tools/sort-headers.py
+++ b/tools/sort-headers.py
@@ -81,11 +81,13 @@ def SortHeader(infile, outfile):
outfile.write(line)
-def DiffAndConfirm(filename, should_confirm):
- """Shows a diff of what the tool would change the file named
- filename to. Shows a confirmation prompt if should_confirm is true.
- Saves the resulting file if should_confirm is false or the user
- answers Y to the confirmation prompt.
+def FixFileWithConfirmFunction(filename, confirm_function):
+ """Creates a fixed version of the file, invokes |confirm_function|
+ to decide whether to use the new file, and cleans up.
+
+ |confirm_function| takes two parameters, the original filename and
+ the fixed-up filename, and returns True to use the fixed-up file,
+ false to not use it.
"""
fixfilename = filename + '.new'
infile = open(filename, 'r')
@@ -95,12 +97,7 @@ def DiffAndConfirm(filename, should_confirm):
outfile.close() # Important so the below diff gets the updated contents.
try:
- diff = os.system('diff -u %s %s' % (filename, fixfilename))
- if diff >> 8 == 0: # Check exit code.
- print '%s: no change' % filename
- return
-
- if not should_confirm or YesNo('Use new file (y/N)?'):
+ if confirm_function(filename, fixfilename):
os.rename(fixfilename, filename)
finally:
try:
@@ -110,6 +107,23 @@ def DiffAndConfirm(filename, should_confirm):
pass
+def DiffAndConfirm(filename, should_confirm):
+ """Shows a diff of what the tool would change the file named
+ filename to. Shows a confirmation prompt if should_confirm is true.
+ Saves the resulting file if should_confirm is false or the user
+ answers Y to the confirmation prompt.
+ """
+ def ConfirmFunction(filename, fixfilename):
+ diff = os.system('diff -u %s %s' % (filename, fixfilename))
+ if diff >> 8 == 0: # Check exit code.
+ print '%s: no change' % filename
+ return False
+
+ return (not should_confirm or YesNo('Use new file (y/N)?'))
+
+ FixFileWithConfirmFunction(filename, ConfirmFunction)
+
+
def main():
parser = optparse.OptionParser(usage='%prog filename1 filename2 ...')
parser.add_option('-f', '--force', action='store_false', default=True,