diff options
author | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-17 00:02:55 +0000 |
---|---|---|
committer | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-17 00:02:55 +0000 |
commit | 54ce726e1af62939cb12b09dc687737b114d426c (patch) | |
tree | 892d28d72c629cd2e5e6b3ff985873c4361c75ab /tools/licenses.py | |
parent | 9f525003ef9bfc8a4a51a6b22f1532d0857190cf (diff) | |
download | chromium_src-54ce726e1af62939cb12b09dc687737b114d426c.zip chromium_src-54ce726e1af62939cb12b09dc687737b114d426c.tar.gz chromium_src-54ce726e1af62939cb12b09dc687737b114d426c.tar.bz2 |
First pass at generating about:credits.
Modify the license script to have a "credits" mode, which uses
two templates derived from the existing about:credits HTML.
BUG=39240
Review URL: http://codereview.chromium.org/1520039
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44863 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/licenses.py')
-rwxr-xr-x | tools/licenses.py | 100 |
1 files changed, 80 insertions, 20 deletions
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) |