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..86bff383fc564c148516178f79baa12617d79749 100755 |
--- a/android_webview/tools/webview_licenses.py |
+++ b/android_webview/tools/webview_licenses.py |
@@ -74,6 +74,8 @@ def GetIncompatibleDirectories(): |
break |
return result |
+class ScanResult(object): |
+ Ok, Warnings, Errors = range(3) |
def _CheckLicenseHeaders(excluded_dirs_list, whitelisted_files): |
"""Checks that all files which are not in a listed third-party directory, |
@@ -82,8 +84,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. |
+ ScanResult.Ok if all files with non-standard license headers are whitelisted |
+ and the whitelist contains no stale entries; |
+ ScanResult.Warnings if there are stale entries; |
+ ScanResult.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 +133,25 @@ 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 |
+ if unknown: |
+ return ScanResult.Errors |
+ elif stale: |
+ return ScanResult.Warnings |
+ else: |
+ return ScanResult.Ok |
def _ReadFile(path): |
@@ -186,9 +192,13 @@ 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. |
+ ScanResult.Ok if everything is in order; |
+ ScanResult.Warnings if there are non-fatal problems (e.g. stale whitelist |
+ entries) |
+ ScanResult.Errors otherwise. |
""" |
third_party_dirs = _FindThirdPartyDirs() |
@@ -211,8 +221,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 ScanResult.Errors |
def GenerateNoticeFile(): |
@@ -255,20 +266,19 @@ def main(): |
(options, args) = parser.parse_args() |
if len(args) != 1: |
parser.print_help() |
- return 1 |
+ return ScanResult.Errors |
if args[0] == 'scan': |
- if _Scan(): |
+ scan_result = _Scan() |
+ if scan_result == ScanResult.Ok: |
print 'OK!' |
- return 0 |
- else: |
- return 1 |
+ return scan_result |
elif args[0] == 'notice': |
print GenerateNoticeFile() |
- return 0 |
+ return ScanResult.Ok |
parser.print_help() |
- return 1 |
+ return ScanResult.Errors |
if __name__ == '__main__': |
sys.exit(main()) |