summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/resources/about_credits.tmpl83
-rw-r--r--chrome/browser/resources/about_credits_entry.tmpl9
-rwxr-xr-xtools/licenses.py100
3 files changed, 172 insertions, 20 deletions
diff --git a/chrome/browser/resources/about_credits.tmpl b/chrome/browser/resources/about_credits.tmpl
new file mode 100644
index 0000000..f9cb1970
--- /dev/null
+++ b/chrome/browser/resources/about_credits.tmpl
@@ -0,0 +1,83 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<meta charset="utf-8">
+<title>Credits</title>
+<style>
+body {
+ font-family:Helvetica,Arial,sans-serif;
+ background-color:white;
+ font-size:84%;
+ max-width:1020px;
+}
+.page-title {
+ font-size:164%;
+ font-weight:bold;
+}
+.product {
+ background-color:#c3d9ff;
+ overflow:auto;
+ padding:2px;
+ margin-top:16px;
+ border-radius:5px;
+}
+.product .title {
+ font-size:110%;
+ font-weight:bold;
+ float:left;
+ margin:3px;
+}
+.product .homepage {
+ text-align:right;
+ float:right;
+ margin:3px;
+}
+.product .homepage:after {
+ content:" - ";
+}
+.product .show {
+ text-align:right;
+ float:right;
+ margin:3px;
+}
+.licence {
+ clear:both;
+ background-color:#e8eef7;
+ padding:16px;
+ border-radius:3px;
+ display:none;
+}
+.licence h3 {
+ margin-top:0px;
+}
+</style>
+<script>
+function $(o) {return document.getElementById(o);}
+function toggle(o) {
+ var licence = o.nextSibling;
+
+ while (licence.className != 'licence') {
+ if (!licence) return false;
+ licence = licence.nextSibling;
+ }
+
+ if (licence.style && licence.style.display == 'block') {
+ licence.style.display = 'none';
+ o.innerHTML = 'show license';
+ } else {
+ licence.style.display = 'block';
+ o.innerHTML = 'hide license';
+ }
+ return false;
+}
+</script>
+</head>
+<body>
+<span class="page-title" style="float:left;">Credits</span>
+<a href="javascript:window.print();" style="float:right;">Print</a>
+<div style="clear:both; overflow:auto;"><!-- Chromium <3s the following projects -->
+{{entries}}
+</div>
+
+</body>
+</html>
diff --git a/chrome/browser/resources/about_credits_entry.tmpl b/chrome/browser/resources/about_credits_entry.tmpl
new file mode 100644
index 0000000..ff0ea45b
--- /dev/null
+++ b/chrome/browser/resources/about_credits_entry.tmpl
@@ -0,0 +1,9 @@
+<div class="product">
+<span class="title">{{name}}</span>
+<a class="show" href="#" onclick="return toggle(this);">show license</a>
+<span class="homepage"><a href="{{url}}">homepage</a></span>
+<div class="licence">
+<pre>{{license}}</pre>
+</div>
+</div>
+
diff --git a/tools/licenses.py b/tools/licenses.py
index 4ed3fab..ff548a3 100755
--- a/tools/licenses.py
+++ b/tools/licenses.py
@@ -3,12 +3,21 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-"""
-Utilities for checking and processing licensing information in third_party
+"""Utility for checking and processing licensing information in third_party
directories.
+
+Usage: licenses.py <command>
+
+Commands:
+ scan scan third_party directories, verifying that we have licensing info
+ credits generate about:credits on stdout
+
+(You can also import this as a module.)
"""
+import cgi
import os
+import sys
# Paths from the root of the tree to directories to skip.
PRUNE_PATHS = set([
@@ -56,6 +65,8 @@ SPECIAL_CASES = {
'third_party/WebKit': {
"Name": "WebKit",
"URL": "http://webkit.org/",
+ # Absolute path here is resolved as relative to the source root.
+ "License File": "/webkit/LICENSE",
},
}
@@ -102,9 +113,14 @@ def ParseDir(path):
# Check that the license file exists.
for filename in (metadata["License File"], "COPYING"):
- license_path = os.path.join(path, filename)
+ if filename.startswith('/'):
+ # Absolute-looking paths are relative to the source root
+ # (which is the directory we're run from).
+ license_path = os.path.join(os.getcwd(), filename[1:])
+ else:
+ license_path = os.path.join(path, filename)
if os.path.exists(license_path):
- metadata["License File"] = filename
+ metadata["License File"] = license_path
break
license_path = None
@@ -118,20 +134,6 @@ def ParseDir(path):
return metadata
-def ScanThirdPartyDirs(third_party_dirs):
- """Scan a list of directories and report on any problems we find."""
- errors = []
- for path in sorted(third_party_dirs):
- try:
- metadata = ParseDir(path)
- except LicenseError, e:
- errors.append((path, e.args[0]))
- continue
-
- for path, error in sorted(errors):
- print path + ": " + error
-
-
def FindThirdPartyDirs():
"""Find all third_party directories underneath the current directory."""
third_party_dirs = []
@@ -162,7 +164,65 @@ def FindThirdPartyDirs():
return third_party_dirs
+def ScanThirdPartyDirs():
+ """Scan a list of directories and report on any problems we find."""
+ third_party_dirs = FindThirdPartyDirs()
+
+ errors = []
+ for path in sorted(third_party_dirs):
+ try:
+ metadata = ParseDir(path)
+ except LicenseError, e:
+ errors.append((path, e.args[0]))
+ continue
+
+ for path, error in sorted(errors):
+ print path + ": " + error
+
+ return len(errors) == 0
+
+def GenerateCredits():
+ """Generate about:credits, dumping the result to stdout."""
+
+ 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:
+ val = cgi.escape(val)
+ template = template.replace('{{%s}}' % key, val)
+ return template
-if __name__ == '__main__':
third_party_dirs = FindThirdPartyDirs()
- ScanThirdPartyDirs(third_party_dirs)
+
+ entry_template = open('chrome/browser/resources/about_credits_entry.tmpl',
+ 'rb').read()
+ entries = []
+ for path in sorted(third_party_dirs):
+ metadata = ParseDir(path)
+ env = {
+ 'name': metadata['Name'],
+ 'url': metadata['URL'],
+ 'license': open(metadata['License File'], 'rb').read(),
+ }
+ entries.append(EvaluateTemplate(entry_template, env))
+
+ file_template = open('chrome/browser/resources/about_credits.tmpl',
+ 'rb').read()
+ print EvaluateTemplate(file_template, {'entries': '\n'.join(entries)},
+ escape=False)
+
+if __name__ == '__main__':
+ command = 'help'
+ if len(sys.argv) > 1:
+ command = sys.argv[1]
+
+ if command == 'scan':
+ if not ScanThirdPartyDirs():
+ sys.exit(1)
+ elif command == 'credits':
+ if not GenerateCredits():
+ sys.exit(1)
+ else:
+ print __doc__
+ sys.exit(1)