| 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 |
| 11 import os | 11 import os |
| 12 | 12 |
| 13 | 13 |
| 14 class LicenseError(Exception): | 14 class LicenseError(Exception): |
| 15 """We raise this exception when a directory's licensing info isn't | 15 """We raise this exception when a directory's licensing info isn't |
| 16 fully filled out.""" | 16 fully filled out.""" |
| 17 pass | 17 pass |
| 18 | 18 |
| 19 | 19 |
| 20 def ParseDir(path): | 20 def ParseDir(path): |
| 21 """Examine a third_party/foo component and extract its metadata.""" | 21 """Examine a third_party/foo component and extract its metadata.""" |
| 22 | 22 |
| 23 # Try to find README.chromium. | 23 # Try to find README.chromium. |
| 24 readme_path = os.path.join(path, 'README.chromium') | 24 readme_path = os.path.join(path, 'README.chromium') |
| 25 if not os.path.exists(readme_path): | 25 if not os.path.exists(readme_path): |
| 26 raise LicenseError("missing README.chromium") | 26 raise LicenseError("missing README.chromium") |
| 27 | 27 |
| 28 # Parse metadata fields out of README.chromium. | 28 # Parse metadata fields out of README.chromium. |
| 29 # We provide a default value of "LICENSE" for the license file. |
| 29 metadata = { | 30 metadata = { |
| 30 "License File": None, # Relative path to license text. | 31 "License File": "LICENSE", # Relative path to license text. |
| 31 "Name": None, # Short name (for header on about:credits). | 32 "Name": None, # Short name (for header on about:credits). |
| 32 "URL": None, # Project home page. | 33 "URL": None, # Project home page. |
| 33 } | 34 } |
| 34 for line in open(readme_path): | 35 for line in open(readme_path): |
| 35 line = line.strip() | 36 line = line.strip() |
| 36 for key in metadata.keys(): | 37 for key in metadata.keys(): |
| 37 field = key + ": " | 38 field = key + ": " |
| 38 if line.startswith(field): | 39 if line.startswith(field): |
| 39 metadata[key] = line[len(field):] | 40 metadata[key] = line[len(field):] |
| 40 | 41 |
| 41 # Check that all expected metadata is present. | 42 # Check that all expected metadata is present. |
| 42 for key, value in metadata.iteritems(): | 43 for key, value in metadata.iteritems(): |
| 43 if not value: | 44 if not value: |
| 44 raise LicenseError("couldn't find '" + key + "' line " | 45 raise LicenseError("couldn't find '" + key + "' line " |
| 45 "in README.chromium") | 46 "in README.chromium") |
| 46 | 47 |
| 47 # Check that the license file exists. | 48 # Check that the license file exists. |
| 48 license_file = metadata["License File"] | 49 license_file = metadata["License File"] |
| 49 license_path = os.path.join(path, license_file) | 50 license_path = os.path.join(path, license_file) |
| 50 if not os.path.exists(license_path): | 51 if not os.path.exists(license_path): |
| 51 raise LicenseError("README.chromium mentions license file '" + | 52 raise LicenseError("License file '" + license_file + "' doesn't exist. " |
| 52 license_file + "' that doesn't exist") | 53 "Either add a 'License File:' section to " |
| 54 "README.chromium or add the missing file.") |
| 53 | 55 |
| 54 return metadata | 56 return metadata |
| 55 | 57 |
| 56 | 58 |
| 57 def ScanThirdPartyDirs(third_party_dirs): | 59 def ScanThirdPartyDirs(third_party_dirs): |
| 58 """Scan a list of directories and report on any problems we find.""" | 60 """Scan a list of directories and report on any problems we find.""" |
| 59 errors = [] | 61 errors = [] |
| 60 for path in sorted(third_party_dirs): | 62 for path in sorted(third_party_dirs): |
| 61 try: | 63 try: |
| 62 metadata = ParseDir(path) | 64 metadata = ParseDir(path) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 89 # Don't recurse into any subdirs from here. | 91 # Don't recurse into any subdirs from here. |
| 90 dirs[:] = [] | 92 dirs[:] = [] |
| 91 continue | 93 continue |
| 92 | 94 |
| 93 return third_party_dirs | 95 return third_party_dirs |
| 94 | 96 |
| 95 | 97 |
| 96 if __name__ == '__main__': | 98 if __name__ == '__main__': |
| 97 third_party_dirs = FindThirdPartyDirs() | 99 third_party_dirs = FindThirdPartyDirs() |
| 98 ScanThirdPartyDirs(third_party_dirs) | 100 ScanThirdPartyDirs(third_party_dirs) |
| OLD | NEW |