Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 """Utility for checking and processing licensing information in third_party | 6 """Utility for checking and processing licensing information in third_party |
| 7 directories. | 7 directories. |
| 8 | 8 |
| 9 Usage: licenses.py <command> | 9 Usage: licenses.py <command> |
| 10 | 10 |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 227 if filename.startswith('/'): | 227 if filename.startswith('/'): |
| 228 # Absolute-looking paths are relative to the source root | 228 # Absolute-looking paths are relative to the source root |
| 229 # (which is the directory we're run from). | 229 # (which is the directory we're run from). |
| 230 absolute_path = os.path.join(os.getcwd(), filename[1:]) | 230 absolute_path = os.path.join(os.getcwd(), filename[1:]) |
| 231 else: | 231 else: |
| 232 absolute_path = os.path.join(path, filename) | 232 absolute_path = os.path.join(path, filename) |
| 233 if os.path.exists(absolute_path): | 233 if os.path.exists(absolute_path): |
| 234 return absolute_path | 234 return absolute_path |
| 235 return None | 235 return None |
| 236 | 236 |
| 237 def ParseDir(path): | 237 def ParseDir(path, require_license_file=True): |
| 238 """Examine a third_party/foo component and extract its metadata.""" | 238 """Examine a third_party/foo component and extract its metadata.""" |
| 239 | 239 |
| 240 # Parse metadata fields out of README.chromium. | 240 # Parse metadata fields out of README.chromium. |
| 241 # We examine "LICENSE" for the license file by default. | 241 # We examine "LICENSE" for the license file by default. |
| 242 metadata = { | 242 metadata = { |
| 243 "License File": "LICENSE", # Relative path to license text. | 243 "License File": "LICENSE", # Relative path to license text. |
| 244 "Name": None, # Short name (for header on about:credits). | 244 "Name": None, # Short name (for header on about:credits). |
| 245 "URL": None, # Project home page. | 245 "URL": None, # Project home page. |
| 246 "License": None, # Software license. | 246 "License": None, # Software license. |
| 247 } | 247 } |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 275 "in README.chromium or licences.py " | 275 "in README.chromium or licences.py " |
| 276 "SPECIAL_CASES") | 276 "SPECIAL_CASES") |
| 277 | 277 |
| 278 # Special-case modules that aren't in the shipping product, so don't need | 278 # Special-case modules that aren't in the shipping product, so don't need |
| 279 # their license in about:credits. | 279 # their license in about:credits. |
| 280 if metadata["License File"] != NOT_SHIPPED: | 280 if metadata["License File"] != NOT_SHIPPED: |
| 281 # Check that the license file exists. | 281 # Check that the license file exists. |
| 282 for filename in (metadata["License File"], "COPYING"): | 282 for filename in (metadata["License File"], "COPYING"): |
| 283 license_path = AbsolutePath(path, filename) | 283 license_path = AbsolutePath(path, filename) |
| 284 if license_path is not None: | 284 if license_path is not None: |
| 285 metadata["License File"] = license_path | |
| 286 break | 285 break |
| 287 | 286 |
| 288 if not license_path: | 287 if require_license_file and not license_path: |
| 289 raise LicenseError("License file not found. " | 288 raise LicenseError("License file not found. " |
| 290 "Either add a file named LICENSE, " | 289 "Either add a file named LICENSE, " |
| 291 "import upstream's COPYING if available, " | 290 "import upstream's COPYING if available, " |
| 292 "or add a 'License File:' line to " | 291 "or add a 'License File:' line to " |
| 293 "README.chromium with the appropriate path.") | 292 "README.chromium with the appropriate path.") |
| 293 metadata["License File"] = license_path | |
| 294 | 294 |
| 295 if "Required Text" in metadata: | 295 if "Required Text" in metadata: |
| 296 required_path = AbsolutePath(path, metadata["Required Text"]) | 296 required_path = AbsolutePath(path, metadata["Required Text"]) |
| 297 if required_path is not None: | 297 if required_path is not None: |
| 298 metadata["Required Text"] = required_path | 298 metadata["Required Text"] = required_path |
| 299 else: | 299 else: |
| 300 raise LicenseError("Required text file listed but not found.") | 300 raise LicenseError("Required text file listed but not found.") |
| 301 | 301 |
| 302 return metadata | 302 return metadata |
| 303 | 303 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 394 print >>sys.stderr, ("WARNING: licensing info for " + path + | 394 print >>sys.stderr, ("WARNING: licensing info for " + path + |
| 395 " is incomplete, skipping.") | 395 " is incomplete, skipping.") |
| 396 continue | 396 continue |
| 397 if metadata['License File'] == NOT_SHIPPED: | 397 if metadata['License File'] == NOT_SHIPPED: |
| 398 print >>sys.stderr, ("Path " + path + " marked as " + NOT_SHIPPED + | 398 print >>sys.stderr, ("Path " + path + " marked as " + NOT_SHIPPED + |
| 399 ", skipping.") | 399 ", skipping.") |
| 400 continue | 400 continue |
| 401 env = { | 401 env = { |
| 402 'name': metadata['Name'], | 402 'name': metadata['Name'], |
| 403 'url': metadata['URL'], | 403 'url': metadata['URL'], |
| 404 'license': open(metadata['License File'], 'rb').read(), | 404 'license': open(metadata['License File'], 'rb').read(), |
|
Nico
2012/08/16 18:10:15
Won't this be confused about None license files?
Steve Block
2012/08/17 10:33:23
No, because metadata comes from line 392, where we
| |
| 405 'license_unescaped': '', | 405 'license_unescaped': '', |
| 406 } | 406 } |
| 407 if 'Required Text' in metadata: | 407 if 'Required Text' in metadata: |
| 408 required_text = open(metadata['Required Text'], 'rb').read() | 408 required_text = open(metadata['Required Text'], 'rb').read() |
| 409 env["license_unescaped"] = required_text | 409 env["license_unescaped"] = required_text |
| 410 entries.append(EvaluateTemplate(entry_template, env)) | 410 entries.append(EvaluateTemplate(entry_template, env)) |
| 411 | 411 |
| 412 file_template = open('chrome/browser/resources/about_credits.tmpl', | 412 file_template = open('chrome/browser/resources/about_credits.tmpl', |
| 413 'rb').read() | 413 'rb').read() |
| 414 print "<!-- Generated by licenses.py; do not edit. -->" | 414 print "<!-- Generated by licenses.py; do not edit. -->" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 427 elif command == 'credits': | 427 elif command == 'credits': |
| 428 if not GenerateCredits(): | 428 if not GenerateCredits(): |
| 429 return 1 | 429 return 1 |
| 430 else: | 430 else: |
| 431 print __doc__ | 431 print __doc__ |
| 432 return 1 | 432 return 1 |
| 433 | 433 |
| 434 | 434 |
| 435 if __name__ == '__main__': | 435 if __name__ == '__main__': |
| 436 sys.exit(main()) | 436 sys.exit(main()) |
| OLD | NEW |