Chromium Code Reviews| Index: android_webview/tools/webview_licenses.py |
| diff --git a/android_webview/tools/webview_licenses.py b/android_webview/tools/webview_licenses.py |
| index 3e9aef6a6cdf030c1f8275bffc7509435b6da01e..6f54f70a12d4e3cfb0099dea6ee75f3985687a53 100755 |
| --- a/android_webview/tools/webview_licenses.py |
| +++ b/android_webview/tools/webview_licenses.py |
| @@ -74,6 +74,9 @@ def GetIncompatibleDirectories(): |
| break |
| return result |
| +SCAN_OK = 0 |
| +SCAN_WARNINGS = 1 << 0 |
| +SCAN_ERRORS = 1 << 1 |
|
mkosiba (inactive)
2013/02/06 15:40:49
It seems these are exclusive, not flags, so how ab
mnaganov (inactive)
2013/02/06 16:42:17
Fixed, thanks!
|
| def _CheckLicenseHeaders(excluded_dirs_list, whitelisted_files): |
| """Checks that all files which are not in a listed third-party directory, |
| @@ -82,8 +85,10 @@ def _CheckLicenseHeaders(excluded_dirs_list, whitelisted_files): |
| excluded_dirs_list: The list of directories to exclude from scanning. |
| whitelisted_files: The whitelist of files. |
| Returns: |
| - True if all files with non-standard license headers are whitelisted and the |
| - whitelist contains no stale entries, otherwise false. |
| + SCAN_OK if all files with non-standard license headers are whitelisted and |
|
mkosiba (inactive)
2013/02/06 15:40:49
if you go with the suggestion above you could say
mnaganov (inactive)
2013/02/06 16:42:17
The interpretation of results are method-dependent
mkosiba (inactive)
2013/02/06 16:54:51
ah, ok then.
|
| + the whitelist contains no stale entries; |
| + SCAN_WARNINGS if there are stale entries; |
| + SCAN_ERRORS if new non-whitelisted entries found. |
| """ |
| excluded_dirs_list = [d for d in excluded_dirs_list if not 'third_party' in d] |
| @@ -129,23 +134,20 @@ def _CheckLicenseHeaders(excluded_dirs_list, whitelisted_files): |
| offending_files.append(os.path.normpath(entries[0])) |
| break |
| - all_files_valid = True |
| unknown = set(offending_files) - set(whitelisted_files) |
| if unknown: |
| print 'The following files contain a third-party license but are not in ' \ |
| 'a listed third-party directory and are not whitelisted. You must ' \ |
| 'add the following files to the whitelist.\n%s' % \ |
| '\n'.join(sorted(unknown)) |
| - all_files_valid = False |
| stale = set(whitelisted_files) - set(offending_files) |
| if stale: |
| print 'The following files are whitelisted unnecessarily. You must ' \ |
| ' remove the following files from the whitelist.\n%s' % \ |
| '\n'.join(sorted(stale)) |
| - all_files_valid = False |
| - return all_files_valid |
| + return SCAN_ERRORS if unknown else (SCAN_WARNINGS if stale else SCAN_OK) |
|
mkosiba (inactive)
2013/02/06 15:40:49
I think it would be slightly clearer to make this
mnaganov (inactive)
2013/02/06 16:42:17
Done.
|
| def _ReadFile(path): |
| @@ -186,9 +188,12 @@ def _FindThirdPartyDirs(): |
| def _Scan(): |
| - """Checks that license meta-data is present for all third-party code. |
| + """Checks that license meta-data is present for all third-party code and |
| + that all non third-party code doesn't contain external copyrighted code. |
| Returns: |
| - Whether the check succeeded. |
| + SCAN_OK if everything is in order; |
| + SCAN_WARNINGS if there are non-fatal problems (e.g. stale whitelist entries) |
| + SCAN_ERRORS otherwise. |
| """ |
| third_party_dirs = _FindThirdPartyDirs() |
| @@ -211,8 +216,9 @@ def _Scan(): |
| match = re.match(r'([^#\s]+)', line) |
| if match: |
| whitelisted_files.append(match.group(1)) |
| - return _CheckLicenseHeaders(third_party_dirs, whitelisted_files) \ |
| - and all_licenses_valid |
| + licenses_check = _CheckLicenseHeaders(third_party_dirs, whitelisted_files) |
| + |
| + return licenses_check if all_licenses_valid else SCAN_ERRORS |
| def GenerateNoticeFile(): |
| @@ -255,20 +261,19 @@ def main(): |
| (options, args) = parser.parse_args() |
| if len(args) != 1: |
| parser.print_help() |
| - return 1 |
| + return SCAN_ERRORS |
| if args[0] == 'scan': |
| - if _Scan(): |
| + scan_result = _Scan() |
| + if scan_result == SCAN_OK: |
| print 'OK!' |
| - return 0 |
| - else: |
| - return 1 |
| + return scan_result |
| elif args[0] == 'notice': |
| print GenerateNoticeFile() |
| - return 0 |
| + return SCAN_OK |
| parser.print_help() |
| - return 1 |
| + return SCAN_ERRORS |
| if __name__ == '__main__': |
| sys.exit(main()) |