Skip to content

Commit

Permalink
Collect license version as an optional_key in licenses.py
Browse files Browse the repository at this point in the history
This changes licenses.py to collect the license version information
during ParseDir, as an optional field.  This is for scripts that
import this script as a module, that may need this information.

Additionally, this removes the "Required Text" support from
licenses.py, because it was only used by SwiftShader, which no
longer needs this functionality.

BUG=424424

Review URL: https://codereview.chromium.org/660163002

Cr-Commit-Position: refs/heads/master@{#302213}
  • Loading branch information
mckev-amazon authored and Commit bot committed Oct 31, 2014
1 parent 592f8e1 commit 95468c6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 18 deletions.
3 changes: 2 additions & 1 deletion android_webview/tools/webview_licenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ def GetIncompatibleDirectories():
continue
try:
metadata = licenses.ParseDir(directory, REPOSITORY_ROOT,
require_license_file=False)
require_license_file=False,
optional_keys=['License Android Compatible'])
except licenses.LicenseError as e:
print 'Got LicenseError while scanning ' + directory
raise
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/resources/about_credits_entry.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<a class="show" href="#">show license</a>
<span class="homepage"><a href="{{url}}">homepage</a></span>
<div class="licence">
<pre>{{license}}</pre>{{license_unescaped}}
<pre>{{license}}</pre>
</div>
</div>

20 changes: 4 additions & 16 deletions tools/licenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def AbsolutePath(path, filename, root):
return absolute_path
return None

def ParseDir(path, root, require_license_file=True):
def ParseDir(path, root, require_license_file=True, optional_keys=None):
"""Examine a third_party/foo component and extract its metadata."""

# Parse metadata fields out of README.chromium.
Expand All @@ -266,9 +266,8 @@ def ParseDir(path, root, require_license_file=True):
"License": None, # Software license.
}

# Relative path to a file containing some html we're required to place in
# about:credits.
optional_keys = ["Required Text", "License Android Compatible"]
if optional_keys is None:
optional_keys = []

if path in SPECIAL_CASES:
metadata.update(SPECIAL_CASES[path])
Expand Down Expand Up @@ -312,13 +311,6 @@ def ParseDir(path, root, require_license_file=True):
"README.chromium with the appropriate path.")
metadata["License File"] = license_path

if "Required Text" in metadata:
required_path = AbsolutePath(path, metadata["Required Text"], root)
if required_path is not None:
metadata["Required Text"] = required_path
else:
raise LicenseError("Required text file listed but not found.")

return metadata


Expand Down Expand Up @@ -412,7 +404,7 @@ def EvaluateTemplate(template, env, escape=True):
"""Expand a template with variables like {{foo}} using a
dictionary of expansions."""
for key, val in env.items():
if escape and not key.endswith("_unescaped"):
if escape:
val = cgi.escape(val)
template = template.replace('{{%s}}' % key, val)
return template
Expand All @@ -435,11 +427,7 @@ def EvaluateTemplate(template, env, escape=True):
'name': metadata['Name'],
'url': metadata['URL'],
'license': open(metadata['License File'], 'rb').read(),
'license_unescaped': '',
}
if 'Required Text' in metadata:
required_text = open(metadata['Required Text'], 'rb').read()
env["license_unescaped"] = required_text
entries.append(EvaluateTemplate(entry_template, env))

file_template = open(os.path.join(root, 'chrome', 'browser', 'resources',
Expand Down

0 comments on commit 95468c6

Please sign in to comment.