Index: tools/licenses.py |
diff --git a/tools/licenses.py b/tools/licenses.py |
index 10a8d330ec73559bc76c9b8090e411a83e5056da..da650f61d6787ffebbbc287c7b42efea31019f2b 100755 |
--- a/tools/licenses.py |
+++ b/tools/licenses.py |
@@ -401,8 +401,12 @@ def ScanThirdPartyDirs(root=None): |
return len(errors) == 0 |
-def GenerateCredits(root=None): |
- """Generate about:credits, dumping the result to stdout.""" |
+def GenerateCredits(): |
+ """Generate about:credits.""" |
+ |
+ if len(sys.argv) not in (2, 3): |
+ print 'usage: licenses.py credits [output_file]' |
+ return False |
def EvaluateTemplate(template, env, escape=True): |
"""Expand a template with variables like {{foo}} using a |
@@ -413,8 +417,7 @@ def GenerateCredits(root=None): |
template = template.replace('{{%s}}' % key, val) |
return template |
- if root is None: |
- root = os.getcwd() |
+ root = os.path.join(os.path.dirname(__file__), '..') |
third_party_dirs = FindThirdPartyDirs(PRUNE_PATHS, root) |
entry_template = open(os.path.join(root, 'chrome', 'browser', 'resources', |
@@ -444,9 +447,18 @@ def GenerateCredits(root=None): |
file_template = open(os.path.join(root, 'chrome', 'browser', 'resources', |
'about_credits.tmpl'), 'rb').read() |
- print "<!-- Generated by licenses.py; do not edit. -->" |
- print EvaluateTemplate(file_template, {'entries': '\n'.join(entries)}, |
- escape=False) |
+ template_contents = "<!-- Generated by licenses.py; do not edit. -->" |
+ template_contents += EvaluateTemplate(file_template, |
+ {'entries': '\n'.join(entries)}, |
+ escape=False) |
+ |
+ if len(sys.argv) == 3: |
+ with open(sys.argv[2], 'w') as output_file: |
+ output_file.write(template_contents) |
+ elif len(sys.argv) == 2: |
+ print template_contents |
+ |
+ return True |
def main(): |