Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Side by Side Diff: tools/sort-headers.py

Issue 7050020: Teach sort-headers.py about windows.h. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 2
3 """Given a filename as an argument, sort the #include/#imports in that file. 3 """Given a filename as an argument, sort the #include/#imports in that file.
4 4
5 Shows a diff and prompts for confirmation before doing the deed. 5 Shows a diff and prompts for confirmation before doing the deed.
6 """ 6 """
7 7
8 import optparse 8 import optparse
9 import os 9 import os
10 import sys 10 import sys
(...skipping 16 matching lines...) Expand all
27 print ch 27 print ch
28 return ch in ('Y', 'y') 28 return ch in ('Y', 'y')
29 29
30 30
31 def IncludeCompareKey(line): 31 def IncludeCompareKey(line):
32 """Sorting comparator key used for comparing two #include lines. 32 """Sorting comparator key used for comparing two #include lines.
33 Returns the filename without the #include/#import prefix. 33 Returns the filename without the #include/#import prefix.
34 """ 34 """
35 for prefix in ('#include ', '#import '): 35 for prefix in ('#include ', '#import '):
36 if line.startswith(prefix): 36 if line.startswith(prefix):
37 return line[len(prefix):] 37 line = line[len(prefix):]
38 break
39 # <windows.h> needs to be before other includes, so return a key
40 # that's less than all other keys.
41 if line.find('<windows.h>') != -1:
Evan Martin 2011/05/19 20:04:33 Maybe test .startswith() instead? (will catch the
Nico 2011/05/19 20:06:21 Done. (lstrip().startswith() if someone accidental
42 return ''
38 return line 43 return line
39 44
40 45
41 def IsInclude(line): 46 def IsInclude(line):
42 """Returns True if the line is an #include/#import line.""" 47 """Returns True if the line is an #include/#import line."""
43 return line.startswith('#include ') or line.startswith('#import ') 48 return line.startswith('#include ') or line.startswith('#import ')
44 49
45 50
46 def SortHeader(infile, outfile): 51 def SortHeader(infile, outfile):
47 """Sorts the headers in infile, writing the sorted file to outfile.""" 52 """Sorts the headers in infile, writing the sorted file to outfile."""
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 finally: 90 finally:
86 try: 91 try:
87 os.remove(fixfilename) 92 os.remove(fixfilename)
88 except OSError: 93 except OSError:
89 # If the file isn't there, we don't care. 94 # If the file isn't there, we don't care.
90 pass 95 pass
91 96
92 97
93 if __name__ == '__main__': 98 if __name__ == '__main__':
94 main() 99 main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698