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