OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 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 """Makes sure that all files contain proper licensing information.""" | 6 """Makes sure that all files contain proper licensing information.""" |
7 | 7 |
8 | 8 |
9 import optparse | 9 import optparse |
10 import os.path | 10 import os.path |
11 import subprocess | 11 import subprocess |
12 import sys | 12 import sys |
13 | 13 |
14 | 14 |
15 def PrintUsage(): | 15 def PrintUsage(): |
16 print """Usage: python checklicenses.py [--root <root>] [tocheck] | 16 print """Usage: python checklicenses.py [--root <root>] [tocheck] |
17 --root Specifies the repository root. This defaults to "../.." relative | 17 --root Specifies the repository root. This defaults to "../.." relative |
18 to the script file. This will be correct given the normal location | 18 to the script file. This will be correct given the normal location |
19 of the script in "<root>/tools/checklicenses". | 19 of the script in "<root>/tools/checklicenses". |
20 | 20 |
| 21 --ignore-suppressions Ignores path-specific license whitelist. Useful when |
| 22 trying to remove a suppression/whitelist entry. |
| 23 |
21 tocheck Specifies the directory, relative to root, to check. This defaults | 24 tocheck Specifies the directory, relative to root, to check. This defaults |
22 to "." so it checks everything. | 25 to "." so it checks everything. |
23 | 26 |
24 Examples: | 27 Examples: |
25 python checklicenses.py | 28 python checklicenses.py |
26 python checklicenses.py --root ~/chromium/src third_party""" | 29 python checklicenses.py --root ~/chromium/src third_party""" |
27 | 30 |
28 | 31 |
29 WHITELISTED_LICENSES = [ | 32 WHITELISTED_LICENSES = [ |
30 'Apache (v2.0)', | 33 'Apache (v2.0)', |
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 # For now we're just interested in the license. | 490 # For now we're just interested in the license. |
488 license = license.replace('*No copyright*', '').strip() | 491 license = license.replace('*No copyright*', '').strip() |
489 | 492 |
490 # Skip generated files. | 493 # Skip generated files. |
491 if 'GENERATED FILE' in license: | 494 if 'GENERATED FILE' in license: |
492 continue | 495 continue |
493 | 496 |
494 if license in WHITELISTED_LICENSES: | 497 if license in WHITELISTED_LICENSES: |
495 continue | 498 continue |
496 | 499 |
497 found_path_specific = False | 500 if not options.ignore_suppressions: |
498 for prefix in PATH_SPECIFIC_WHITELISTED_LICENSES: | 501 found_path_specific = False |
499 if (filename.startswith(prefix) and | 502 for prefix in PATH_SPECIFIC_WHITELISTED_LICENSES: |
500 license in PATH_SPECIFIC_WHITELISTED_LICENSES[prefix]): | 503 if (filename.startswith(prefix) and |
| 504 license in PATH_SPECIFIC_WHITELISTED_LICENSES[prefix]): |
501 found_path_specific = True | 505 found_path_specific = True |
502 break | 506 break |
503 if found_path_specific: | 507 if found_path_specific: |
504 continue | 508 continue |
505 | 509 |
506 print "'%s' has non-whitelisted license '%s'" % (filename, license) | 510 print "'%s' has non-whitelisted license '%s'" % (filename, license) |
507 success = False | 511 success = False |
508 | 512 |
509 if success: | 513 if success: |
510 print "\nSUCCESS\n" | 514 print "\nSUCCESS\n" |
511 sys.exit(0) | 515 sys.exit(0) |
512 else: | 516 else: |
513 print "\nFAILED\n" | 517 print "\nFAILED\n" |
514 print "Please read", | 518 print "Please read", |
(...skipping 10 matching lines...) Expand all Loading... |
525 default_root = os.path.abspath( | 529 default_root = os.path.abspath( |
526 os.path.join(os.path.dirname(__file__), '..', '..')) | 530 os.path.join(os.path.dirname(__file__), '..', '..')) |
527 option_parser = optparse.OptionParser() | 531 option_parser = optparse.OptionParser() |
528 option_parser.add_option('--root', default=default_root, | 532 option_parser.add_option('--root', default=default_root, |
529 dest='base_directory', | 533 dest='base_directory', |
530 help='Specifies the repository root. This defaults ' | 534 help='Specifies the repository root. This defaults ' |
531 'to "../.." relative to the script file, which ' | 535 'to "../.." relative to the script file, which ' |
532 'will normally be the repository root.') | 536 'will normally be the repository root.') |
533 option_parser.add_option('-v', '--verbose', action='store_true', | 537 option_parser.add_option('-v', '--verbose', action='store_true', |
534 default=False, help='Print debug logging') | 538 default=False, help='Print debug logging') |
| 539 option_parser.add_option('--ignore-suppressions', |
| 540 action='store_true', |
| 541 default=False, |
| 542 help='Ignore path-specific license whitelist.') |
535 options, args = option_parser.parse_args() | 543 options, args = option_parser.parse_args() |
536 main(options, args) | 544 main(options, args) |
OLD | NEW |