OLD | NEW |
| (Empty) |
1 #!/usr/bin/python | |
2 # Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 | |
6 import sys | |
7 | |
8 if len(sys.argv) != 2: | |
9 print """Usage: sort_sln.py <SOLUTIONNAME>.sln | |
10 to sort the solution file to a normalized scheme. Do this before checking in | |
11 changes to a solution file to avoid having a lot of unnecessary diffs.""" | |
12 sys.exit(1) | |
13 | |
14 filename = sys.argv[1] | |
15 print "Sorting " + filename; | |
16 | |
17 try: | |
18 sln = open(filename, "r"); | |
19 except IOError: | |
20 print "Unable to open " + filename + " for reading." | |
21 sys.exit(1) | |
22 | |
23 output = "" | |
24 seclines = None | |
25 while 1: | |
26 line = sln.readline() | |
27 if not line: | |
28 break | |
29 | |
30 if seclines is not None: | |
31 # Process the end of a section, dump the sorted lines | |
32 if line.lstrip().startswith('End'): | |
33 output = output + ''.join(sorted(seclines)) | |
34 seclines = None | |
35 # Process within a section | |
36 else: | |
37 seclines.append(line) | |
38 continue | |
39 | |
40 # Process the start of a section | |
41 if (line.lstrip().startswith('GlobalSection') or | |
42 line.lstrip().startswith('ProjectSection')): | |
43 if seclines: raise Exception('Already in a section') | |
44 seclines = [] | |
45 | |
46 output = output + line | |
47 | |
48 sln.close() | |
49 try: | |
50 sln = open(filename, "w") | |
51 sln.write(output) | |
52 except IOError: | |
53 print "Unable to write to " + filename | |
54 sys.exit(1); | |
55 print "Done." | |
56 | |
OLD | NEW |