OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import copy | 6 import copy |
7 import optparse | 7 import optparse |
8 | 8 |
9 __version__ = "1.0" | 9 __version__ = "1.0" |
10 | 10 |
11 # Constants used by Visual Studio. | 11 # Constants used by Visual Studio. |
12 UNKNOWN_GUID = "{00000000-0000-0000-0000-000000000000}" | 12 UNKNOWN_GUID = "{00000000-0000-0000-0000-000000000000}" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 # End of a dependency group. | 56 # End of a dependency group. |
57 while line and line != "EndProjectSection": | 57 while line and line != "EndProjectSection": |
58 project.deps.append(line[:len(project.guid)]) | 58 project.deps.append(line[:len(project.guid)]) |
59 line = sln.readline().strip() | 59 line = sln.readline().strip() |
60 | 60 |
61 # We are done parsing. | 61 # We are done parsing. |
62 sln.close() | 62 sln.close() |
63 return projects | 63 return projects |
64 | 64 |
65 | 65 |
66 def main(filename, project_to_scan, reverse): | 66 def sln_deps(filename, project_to_scan, reverse): |
67 """Displays the project's dependencies.""" | 67 """Displays the project's dependencies.""" |
68 project_to_scan = project_to_scan.lower() | 68 project_to_scan = project_to_scan.lower() |
69 | 69 |
70 projects = ScanSlnFile(filename) | 70 projects = ScanSlnFile(filename) |
71 | 71 |
72 if reverse: | 72 if reverse: |
73 # Inverse the dependencies map so they are displayed in the reverse order. | 73 # Inverse the dependencies map so they are displayed in the reverse order. |
74 # First, create a copy of the map. | 74 # First, create a copy of the map. |
75 projects_reversed = copy.deepcopy(projects) | 75 projects_reversed = copy.deepcopy(projects) |
76 for project_reversed in projects_reversed.itervalues(): | 76 for project_reversed in projects_reversed.itervalues(): |
77 project_reversed.deps = [] | 77 project_reversed.deps = [] |
78 # Then, assign reverse dependencies. | 78 # Then, assign reverse dependencies. |
79 for project in projects.itervalues(): | 79 for project in projects.itervalues(): |
80 for dep in project.deps: | 80 for dep in project.deps: |
81 projects_reversed[dep].deps.append(project.guid) | 81 projects_reversed[dep].deps.append(project.guid) |
82 projects = projects_reversed | 82 projects = projects_reversed |
83 | 83 |
84 # Print the results. | 84 # Print the results. |
85 for project in projects.itervalues(): | 85 for project in projects.itervalues(): |
86 if project.type == FOLDER_GUID: | 86 if project.type == FOLDER_GUID: |
87 continue | 87 continue |
88 if project_to_scan and project.name.lower() != project_to_scan: | 88 if project_to_scan and project.name.lower() != project_to_scan: |
89 continue | 89 continue |
90 print project.name | 90 print project.name |
91 deps_name = [projects[d].name for d in project.deps] | 91 deps_name = [projects[d].name for d in project.deps] |
92 print "\n".join(str(" " + name) for name in sorted(deps_name, | 92 print "\n".join(str(" " + name) for name in sorted(deps_name, |
93 key=str.lower)) | 93 key=str.lower)) |
| 94 return 0 |
94 | 95 |
95 | 96 |
96 if __name__ == '__main__': | 97 def main(): |
97 usage = "usage: %prog [options] solution [project]" | 98 usage = "usage: %prog [options] solution [project]" |
98 | 99 |
99 description = ("Display the dependencies of a project in human readable" | 100 description = ("Display the dependencies of a project in human readable" |
100 " form. [project] is optional. If omited, all projects are" | 101 " form. [project] is optional. If omited, all projects are" |
101 " listed.") | 102 " listed.") |
102 | 103 |
103 option_parser = optparse.OptionParser(usage = usage, | 104 option_parser = optparse.OptionParser(usage = usage, |
104 version="%prog " + __version__, | 105 version="%prog " + __version__, |
105 description = description) | 106 description = description) |
106 option_parser.add_option("-r", | 107 option_parser.add_option("-r", |
107 "--reverse", | 108 "--reverse", |
108 dest="reverse", | 109 dest="reverse", |
109 action="store_true", | 110 action="store_true", |
110 default=False, | 111 default=False, |
111 help="Display the reverse dependencies") | 112 help="Display the reverse dependencies") |
112 options, args = option_parser.parse_args() | 113 options, args = option_parser.parse_args() |
113 if len(args) != 1 and len(args) != 2: | 114 if len(args) != 1 and len(args) != 2: |
114 option_parser.error("incorrect number of arguments") | 115 option_parser.error("incorrect number of arguments") |
115 | 116 |
116 project_to_scan = "" | 117 project_to_scan = "" |
117 if len(args) == 2: | 118 if len(args) == 2: |
118 project_to_scan = args[1] | 119 project_to_scan = args[1] |
119 main(args[0], project_to_scan, options.reverse) | 120 return sln_deps(args[0], project_to_scan, options.reverse) |
120 | 121 |
| 122 |
| 123 if __name__ == '__main__': |
| 124 sys.exit(main()) |
OLD | NEW |