Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: tools/licenses.py

Issue 12177010: Generate about:credits page automatically at build time. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix ninja Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/chrome_resources.gyp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 except LicenseError, e: 394 except LicenseError, e:
395 errors.append((path, e.args[0])) 395 errors.append((path, e.args[0]))
396 continue 396 continue
397 397
398 for path, error in sorted(errors): 398 for path, error in sorted(errors):
399 print path + ": " + error 399 print path + ": " + error
400 400
401 return len(errors) == 0 401 return len(errors) == 0
402 402
403 403
404 def GenerateCredits(root=None): 404 def GenerateCredits():
405 """Generate about:credits, dumping the result to stdout.""" 405 """Generate about:credits."""
406
407 if len(sys.argv) not in (2, 3):
408 print 'usage: licenses.py credits [output_file]'
409 return False
406 410
407 def EvaluateTemplate(template, env, escape=True): 411 def EvaluateTemplate(template, env, escape=True):
408 """Expand a template with variables like {{foo}} using a 412 """Expand a template with variables like {{foo}} using a
409 dictionary of expansions.""" 413 dictionary of expansions."""
410 for key, val in env.items(): 414 for key, val in env.items():
411 if escape and not key.endswith("_unescaped"): 415 if escape and not key.endswith("_unescaped"):
412 val = cgi.escape(val) 416 val = cgi.escape(val)
413 template = template.replace('{{%s}}' % key, val) 417 template = template.replace('{{%s}}' % key, val)
414 return template 418 return template
415 419
416 if root is None: 420 root = os.path.join(os.path.dirname(__file__), '..')
417 root = os.getcwd()
418 third_party_dirs = FindThirdPartyDirs(PRUNE_PATHS, root) 421 third_party_dirs = FindThirdPartyDirs(PRUNE_PATHS, root)
419 422
420 entry_template = open(os.path.join(root, 'chrome', 'browser', 'resources', 423 entry_template = open(os.path.join(root, 'chrome', 'browser', 'resources',
421 'about_credits_entry.tmpl'), 'rb').read() 424 'about_credits_entry.tmpl'), 'rb').read()
422 entries = [] 425 entries = []
423 for path in sorted(third_party_dirs): 426 for path in sorted(third_party_dirs):
424 try: 427 try:
425 metadata = ParseDir(path, root) 428 metadata = ParseDir(path, root)
426 except LicenseError: 429 except LicenseError:
427 print >>sys.stderr, ("WARNING: licensing info for " + path + 430 print >>sys.stderr, ("WARNING: licensing info for " + path +
428 " is incomplete, skipping.") 431 " is incomplete, skipping.")
429 continue 432 continue
430 if metadata['License File'] == NOT_SHIPPED: 433 if metadata['License File'] == NOT_SHIPPED:
431 print >>sys.stderr, ("Path " + path + " marked as " + NOT_SHIPPED + 434 print >>sys.stderr, ("Path " + path + " marked as " + NOT_SHIPPED +
432 ", skipping.") 435 ", skipping.")
433 continue 436 continue
434 env = { 437 env = {
435 'name': metadata['Name'], 438 'name': metadata['Name'],
436 'url': metadata['URL'], 439 'url': metadata['URL'],
437 'license': open(metadata['License File'], 'rb').read(), 440 'license': open(metadata['License File'], 'rb').read(),
438 'license_unescaped': '', 441 'license_unescaped': '',
439 } 442 }
440 if 'Required Text' in metadata: 443 if 'Required Text' in metadata:
441 required_text = open(metadata['Required Text'], 'rb').read() 444 required_text = open(metadata['Required Text'], 'rb').read()
442 env["license_unescaped"] = required_text 445 env["license_unescaped"] = required_text
443 entries.append(EvaluateTemplate(entry_template, env)) 446 entries.append(EvaluateTemplate(entry_template, env))
444 447
445 file_template = open(os.path.join(root, 'chrome', 'browser', 'resources', 448 file_template = open(os.path.join(root, 'chrome', 'browser', 'resources',
446 'about_credits.tmpl'), 'rb').read() 449 'about_credits.tmpl'), 'rb').read()
447 print "<!-- Generated by licenses.py; do not edit. -->" 450 template_contents = "<!-- Generated by licenses.py; do not edit. -->"
448 print EvaluateTemplate(file_template, {'entries': '\n'.join(entries)}, 451 template_contents += EvaluateTemplate(file_template,
449 escape=False) 452 {'entries': '\n'.join(entries)},
453 escape=False)
454
455 if len(sys.argv) == 3:
456 with open(sys.argv[2], 'w') as output_file:
457 output_file.write(template_contents)
458 elif len(sys.argv) == 2:
459 print template_contents
460
461 return True
450 462
451 463
452 def main(): 464 def main():
453 command = 'help' 465 command = 'help'
454 if len(sys.argv) > 1: 466 if len(sys.argv) > 1:
455 command = sys.argv[1] 467 command = sys.argv[1]
456 468
457 if command == 'scan': 469 if command == 'scan':
458 if not ScanThirdPartyDirs(): 470 if not ScanThirdPartyDirs():
459 return 1 471 return 1
460 elif command == 'credits': 472 elif command == 'credits':
461 if not GenerateCredits(): 473 if not GenerateCredits():
462 return 1 474 return 1
463 else: 475 else:
464 print __doc__ 476 print __doc__
465 return 1 477 return 1
466 478
467 479
468 if __name__ == '__main__': 480 if __name__ == '__main__':
469 sys.exit(main()) 481 sys.exit(main())
OLDNEW
« no previous file with comments | « chrome/chrome_resources.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698