OLD | NEW |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2010 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 """ | 6 """ |
7 Utilities for checking and processing licensing information in third_party | 7 Utilities for checking and processing licensing information in third_party |
8 directories. | 8 directories. |
9 """ | 9 """ |
10 | 10 |
(...skipping 14 matching lines...) Expand all Loading... | |
25 # Two directories that are the same as those in base/third_party. | 25 # Two directories that are the same as those in base/third_party. |
26 "v8/src/third_party/dtoa", | 26 "v8/src/third_party/dtoa", |
27 "v8/src/third_party/valgrind", | 27 "v8/src/third_party/valgrind", |
28 ]) | 28 ]) |
29 | 29 |
30 # Directories we don't scan through. | 30 # Directories we don't scan through. |
31 PRUNE_DIRS = ('.svn', '.git', # VCS metadata | 31 PRUNE_DIRS = ('.svn', '.git', # VCS metadata |
32 'out', 'Debug', 'Release', # build files | 32 'out', 'Debug', 'Release', # build files |
33 'layout_tests') # lots of subdirs | 33 'layout_tests') # lots of subdirs |
34 | 34 |
35 # Directories where we check out directly from upstream, and therefore | |
36 # can't provide a README.chromium. Please prefer a README.chromium | |
37 # wherever possible. | |
38 SPECIAL_CASES = { | |
39 'third_party/ots': { | |
40 "Name": "OTS (OpenType Sanitizer)", | |
41 "URL": "http://code.google.com/p/ots/", | |
42 } | |
43 } | |
44 | |
35 class LicenseError(Exception): | 45 class LicenseError(Exception): |
36 """We raise this exception when a directory's licensing info isn't | 46 """We raise this exception when a directory's licensing info isn't |
37 fully filled out.""" | 47 fully filled out.""" |
38 pass | 48 pass |
39 | 49 |
40 | 50 |
41 def ParseDir(path): | 51 def ParseDir(path): |
42 """Examine a third_party/foo component and extract its metadata.""" | 52 """Examine a third_party/foo component and extract its metadata.""" |
43 | 53 |
44 # Try to find README.chromium. | |
45 readme_path = os.path.join(path, 'README.chromium') | |
46 if not os.path.exists(readme_path): | |
47 raise LicenseError("missing README.chromium") | |
48 | |
49 # Parse metadata fields out of README.chromium. | 54 # Parse metadata fields out of README.chromium. |
50 # We examine "LICENSE" for the license file by default. | 55 # We examine "LICENSE" for the license file by default. |
51 metadata = { | 56 metadata = { |
52 "License File": "LICENSE", # Relative path to license text. | 57 "License File": "LICENSE", # Relative path to license text. |
53 "Name": None, # Short name (for header on about:credits). | 58 "Name": None, # Short name (for header on about:credits). |
54 "URL": None, # Project home page. | 59 "URL": None, # Project home page. |
55 } | 60 } |
56 for line in open(readme_path): | 61 |
57 line = line.strip() | 62 if path in SPECIAL_CASES: |
58 if not line: | 63 metadata.update(SPECIAL_CASES[path]) |
59 break | 64 else: |
60 for key in metadata.keys(): | 65 # Try to find README.chromium. |
61 field = key + ": " | 66 readme_path = os.path.join(path, 'README.chromium') |
62 if line.startswith(field): | 67 if not os.path.exists(readme_path): |
63 metadata[key] = line[len(field):] | 68 raise LicenseError("missing README.chromium") |
69 | |
70 for line in open(readme_path): | |
71 line = line.strip() | |
72 if not line: | |
73 break | |
74 for key in metadata.keys(): | |
75 field = key + ": " | |
76 if line.startswith(field): | |
77 metadata[key] = line[len(field):] | |
64 | 78 |
65 # Check that all expected metadata is present. | 79 # Check that all expected metadata is present. |
66 for key, value in metadata.iteritems(): | 80 for key, value in metadata.iteritems(): |
67 if not value: | 81 if not value: |
68 raise LicenseError("couldn't find '" + key + "' line " | 82 raise LicenseError("couldn't find '" + key + "' line " |
69 "in README.chromium") | 83 "in README.chromium or licences.py " |
84 "SPECIAL_CASES") | |
70 | 85 |
71 # Check that the license file exists. | 86 # Check that the license file exists. |
72 for filename in (metadata["License File"], "COPYING"): | 87 for filename in (metadata["License File"], "COPYING"): |
73 license_path = os.path.join(path, filename) | 88 license_path = os.path.join(path, filename) |
74 if os.path.exists(license_path): | 89 if os.path.exists(license_path): |
75 metadata["License File"] = filename | 90 metadata["License File"] = filename |
76 break | 91 break |
77 license_path = None | 92 license_path = None |
78 | 93 |
79 if not license_path: | 94 if not license_path: |
(...skipping 10 matching lines...) Expand all Loading... | |
90 """Scan a list of directories and report on any problems we find.""" | 105 """Scan a list of directories and report on any problems we find.""" |
91 errors = [] | 106 errors = [] |
92 for path in sorted(third_party_dirs): | 107 for path in sorted(third_party_dirs): |
93 try: | 108 try: |
94 metadata = ParseDir(path) | 109 metadata = ParseDir(path) |
95 except LicenseError, e: | 110 except LicenseError, e: |
96 errors.append((path, e.args[0])) | 111 errors.append((path, e.args[0])) |
97 continue | 112 continue |
98 print path, "OK:", metadata["License File"] | 113 print path, "OK:", metadata["License File"] |
99 | 114 |
115 print | |
M-A Ruel
2010/03/22 23:52:09
It works as-is?
| |
116 | |
100 for path, error in sorted(errors): | 117 for path, error in sorted(errors): |
101 print path + ": " + error | 118 print path + ": " + error |
102 | 119 |
103 | 120 |
104 def FindThirdPartyDirs(): | 121 def FindThirdPartyDirs(): |
105 """Find all third_party directories underneath the current directory.""" | 122 """Find all third_party directories underneath the current directory.""" |
106 third_party_dirs = [] | 123 third_party_dirs = [] |
107 for path, dirs, files in os.walk('.'): | 124 for path, dirs, files in os.walk('.'): |
108 path = path[len('./'):] # Pretty up the path. | 125 path = path[len('./'):] # Pretty up the path. |
109 | 126 |
(...skipping 18 matching lines...) Expand all Loading... | |
128 # Don't recurse into any subdirs from here. | 145 # Don't recurse into any subdirs from here. |
129 dirs[:] = [] | 146 dirs[:] = [] |
130 continue | 147 continue |
131 | 148 |
132 return third_party_dirs | 149 return third_party_dirs |
133 | 150 |
134 | 151 |
135 if __name__ == '__main__': | 152 if __name__ == '__main__': |
136 third_party_dirs = FindThirdPartyDirs() | 153 third_party_dirs = FindThirdPartyDirs() |
137 ScanThirdPartyDirs(third_party_dirs) | 154 ScanThirdPartyDirs(third_party_dirs) |
OLD | NEW |