summaryrefslogtreecommitdiffstats
path: root/android_webview/tools/webview_licenses.py
diff options
context:
space:
mode:
Diffstat (limited to 'android_webview/tools/webview_licenses.py')
-rwxr-xr-xandroid_webview/tools/webview_licenses.py58
1 files changed, 14 insertions, 44 deletions
diff --git a/android_webview/tools/webview_licenses.py b/android_webview/tools/webview_licenses.py
index d6123bd..a248600 100755
--- a/android_webview/tools/webview_licenses.py
+++ b/android_webview/tools/webview_licenses.py
@@ -220,8 +220,6 @@ def _FindThirdPartyDirs():
os.path.join('build', 'secondary'),
# Not shipped, Chromium code
os.path.join('tools', 'swarming_client'),
- # Not shipped, only relates to Chrome for Android, but not to WebView
- os.path.join('clank'),
]
third_party_dirs = licenses.FindThirdPartyDirs(prune_paths, REPOSITORY_ROOT)
return licenses.FilterDirsWithFiles(third_party_dirs, REPOSITORY_ROOT)
@@ -258,15 +256,9 @@ def _Scan():
class TemplateEntryGenerator(object):
def __init__(self):
- self._generate_licenses_file_list_only = False
- self._toc_index = 0
-
- def SetGenerateLicensesFileListOnly(self, generate_licenses_file_list_only):
- self._generate_licenses_file_list_only = generate_licenses_file_list_only
+ self.toc_index = 0
def _ReadFileGuessEncoding(self, name):
- if self._generate_licenses_file_list_only:
- return ''
contents = ''
with open(name, 'rb') as input_file:
contents = input_file.read()
@@ -278,17 +270,16 @@ class TemplateEntryGenerator(object):
return contents.decode('cp1252')
def MetadataToTemplateEntry(self, metadata):
- self._toc_index += 1
+ self.toc_index += 1
return {
'name': metadata['Name'],
'url': metadata['URL'],
- 'license_file': metadata['License File'],
'license': self._ReadFileGuessEncoding(metadata['License File']),
- 'toc_href': 'entry' + str(self._toc_index),
+ 'toc_href': 'entry' + str(self.toc_index),
}
-def GenerateNoticeFile(generate_licenses_file_list_only=False):
+def GenerateNoticeFile():
"""Generates the contents of an Android NOTICE file for the third-party code.
This is used by the snapshot tool.
Returns:
@@ -296,7 +287,6 @@ def GenerateNoticeFile(generate_licenses_file_list_only=False):
"""
generator = TemplateEntryGenerator()
- generator.SetGenerateLicensesFileListOnly(generate_licenses_file_list_only)
# Start from Chromium's LICENSE file
entries = [generator.MetadataToTemplateEntry({
'Name': 'The Chromium Project',
@@ -308,24 +298,17 @@ def GenerateNoticeFile(generate_licenses_file_list_only=False):
# We provide attribution for all third-party directories.
# TODO(mnaganov): Limit this to only code used by the WebView binary.
for directory in sorted(third_party_dirs):
- try:
- metadata = licenses.ParseDir(directory, REPOSITORY_ROOT,
- require_license_file=False)
- except licenses.LicenseError:
- sys.stderr.write('Got a LicenseError for %s\n' % directory)
- raise
+ metadata = licenses.ParseDir(directory, REPOSITORY_ROOT,
+ require_license_file=False)
license_file = metadata['License File']
if license_file and license_file != licenses.NOT_SHIPPED:
entries.append(generator.MetadataToTemplateEntry(metadata))
- if generate_licenses_file_list_only:
- return [entry['license_file'] for entry in entries]
- else:
- env = jinja2.Environment(
- loader=jinja2.FileSystemLoader(os.path.dirname(__file__)),
- extensions=['jinja2.ext.autoescape'])
- template = env.get_template('licenses_notice.tmpl')
- return template.render({ 'entries': entries }).encode('utf8')
+ env = jinja2.Environment(
+ loader=jinja2.FileSystemLoader(os.path.dirname(__file__)),
+ extensions=['jinja2.ext.autoescape'])
+ template = env.get_template('licenses_notice.tmpl')
+ return template.render({ 'entries': entries }).encode('utf8')
def _ProcessIncompatibleResult(incompatible_directories):
@@ -347,10 +330,7 @@ def main():
parser.description = (__doc__ +
'\nCommands:\n'
' scan Check licenses.\n'
- ' notice_deps Generate the list of dependencies for '
- 'Android NOTICE file.\n'
- ' notice [file] Generate Android NOTICE file on '
- 'stdout or into |file|.\n'
+ ' notice Generate Android NOTICE file on stdout.\n'
' incompatible_directories Scan for incompatibly'
' licensed directories.\n'
' all_incompatible_directories Scan for incompatibly'
@@ -359,7 +339,7 @@ def main():
' display_copyrights Display autorship on the files'
' using names provided via stdin.\n')
(_, args) = parser.parse_args()
- if len(args) < 1:
+ if len(args) != 1:
parser.print_help()
return ScanResult.Errors
@@ -368,18 +348,8 @@ def main():
if scan_result == ScanResult.Ok:
print 'OK!'
return scan_result
- elif args[0] == 'notice_deps':
- # 'set' is used to eliminate duplicate references to the same license file.
- print ' '.join(
- sorted(set(GenerateNoticeFile(generate_licenses_file_list_only=True))))
- return ScanResult.Ok
elif args[0] == 'notice':
- notice_file_contents = GenerateNoticeFile()
- if len(args) == 1:
- print notice_file_contents
- else:
- with open(args[1], 'w') as output_file:
- output_file.write(notice_file_contents)
+ print GenerateNoticeFile()
return ScanResult.Ok
elif args[0] == 'incompatible_directories':
return _ProcessIncompatibleResult(GetUnknownIncompatibleDirectories())