Chromium Code Reviews| Index: tools/licenses.py |
| diff --git a/tools/licenses.py b/tools/licenses.py |
| index b01db489da107bfd599742db55a4bb243c092558..4ac2aa468f3bcf61e7462535403becf64c7548c7 100755 |
| --- a/tools/licenses.py |
| +++ b/tools/licenses.py |
| @@ -173,8 +173,14 @@ def AbsolutePath(path, filename): |
| return absolute_path |
| return None |
| -def ParseDir(path): |
| - """Examine a third_party/foo component and extract its metadata.""" |
| +def ParseDir(path, raise_on_error): |
| + """Examine a third_party/foo component and extract its metadata. |
| + Args: |
| + path the path to the component to examine |
| + raise_on_error whether to raise an exception if an error occurs |
| + Returns: |
| + metadata for the component |
| + """ |
| # Parse metadata fields out of README.chromium. |
| # We examine "LICENSE" for the license file by default. |
| @@ -194,23 +200,25 @@ def ParseDir(path): |
| # Try to find README.chromium. |
| readme_path = os.path.join(path, 'README.chromium') |
| if not os.path.exists(readme_path): |
| - raise LicenseError("missing README.chromium") |
| - |
| - for line in open(readme_path): |
| - line = line.strip() |
| - if not line: |
| - break |
| - for key in metadata.keys() + optional_keys: |
| - field = key + ": " |
| - if line.startswith(field): |
| - metadata[key] = line[len(field):] |
| + if raise_on_error: |
| + raise LicenseError("missing README.chromium") |
| + else: |
| + for line in open(readme_path): |
| + line = line.strip() |
| + if not line: |
| + break |
| + for key in metadata.keys() + optional_keys: |
| + field = key + ": " |
| + if line.startswith(field): |
| + metadata[key] = line[len(field):] |
| # Check that all expected metadata is present. |
| - for key, value in metadata.iteritems(): |
| - if not value: |
| - raise LicenseError("couldn't find '" + key + "' line " |
| - "in README.chromium or licences.py " |
| - "SPECIAL_CASES") |
| + if raise_on_error: |
| + for key, value in metadata.iteritems(): |
| + if not value: |
| + raise LicenseError("couldn't find '" + key + "' line " |
| + "in README.chromium or licences.py " |
| + "SPECIAL_CASES") |
| # Check that the license file exists. |
| for filename in (metadata["License File"], "COPYING"): |
| @@ -219,7 +227,7 @@ def ParseDir(path): |
| metadata["License File"] = license_path |
| break |
| - if not license_path: |
| + if raise_on_error and not license_path: |
| raise LicenseError("License file not found. " |
| "Either add a file named LICENSE, " |
| "import upstream's COPYING if available, " |
| @@ -230,7 +238,7 @@ def ParseDir(path): |
| required_path = AbsolutePath(path, metadata["Required Text"]) |
| if required_path is not None: |
| metadata["Required Text"] = required_path |
| - else: |
| + elif raise_on_error: |
| raise LicenseError("Required text file listed but not found.") |
| return metadata |
| @@ -277,7 +285,7 @@ def ScanThirdPartyDirs(): |
| errors = [] |
| for path in sorted(third_party_dirs): |
| try: |
| - metadata = ParseDir(path) |
| + metadata = ParseDir(path, True) |
|
Evan Martin
2012/07/24 19:41:28
Consider something like:
ParseDir(path, raise_on
Steve Block
2012/07/24 21:20:58
Regarding a try block, this approach doesn't work
|
| except LicenseError, e: |
| errors.append((path, e.args[0])) |
| continue |
| @@ -307,7 +315,7 @@ def GenerateCredits(): |
| entries = [] |
| for path in sorted(third_party_dirs): |
| try: |
| - metadata = ParseDir(path) |
| + metadata = ParseDir(path, True) |
| except LicenseError: |
| print >>sys.stderr, ("WARNING: licensing info for " + path + |
| " is incomplete, skipping.") |