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

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

Issue 7048007: Move scoped_temp_dir and scoped_native_library back from base/memory to base. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: scriptfix 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 | « remoting/host/json_host_config_unittest.cc ('k') | ui/base/resource/data_pack_unittest.cc » ('j') | 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:
42 return ''
38 return line 43 return line
39 44
40 45
46
41 def IsInclude(line): 47 def IsInclude(line):
42 """Returns True if the line is an #include/#import line.""" 48 """Returns True if the line is an #include/#import line."""
43 return line.startswith('#include ') or line.startswith('#import ') 49 return line.startswith('#include ') or line.startswith('#import ')
44 50
45 51
46 def SortHeader(infile, outfile): 52 def SortHeader(infile, outfile):
47 """Sorts the headers in infile, writing the sorted file to outfile.""" 53 """Sorts the headers in infile, writing the sorted file to outfile."""
48 for line in infile: 54 for line in infile:
49 if IsInclude(line): 55 if IsInclude(line):
50 headerblock = [] 56 headerblock = []
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 finally: 91 finally:
86 try: 92 try:
87 os.remove(fixfilename) 93 os.remove(fixfilename)
88 except OSError: 94 except OSError:
89 # If the file isn't there, we don't care. 95 # If the file isn't there, we don't care.
90 pass 96 pass
91 97
92 98
93 if __name__ == '__main__': 99 if __name__ == '__main__':
94 main() 100 main()
OLDNEW
« no previous file with comments | « remoting/host/json_host_config_unittest.cc ('k') | ui/base/resource/data_pack_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698