| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Utility for checking and processing licensing information in third_party | 6 """Utility for checking and processing licensing information in third_party |
| 7 directories. | 7 directories. |
| 8 | 8 |
| 9 Usage: licenses.py <command> | 9 Usage: licenses.py <command> |
| 10 | 10 |
| 11 Commands: | 11 Commands: |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 | 229 |
| 230 # Don't recurse into any subdirs from here. | 230 # Don't recurse into any subdirs from here. |
| 231 dirs[:] = [] | 231 dirs[:] = [] |
| 232 continue | 232 continue |
| 233 | 233 |
| 234 for dir in ADDITIONAL_PATHS: | 234 for dir in ADDITIONAL_PATHS: |
| 235 third_party_dirs.append(dir) | 235 third_party_dirs.append(dir) |
| 236 | 236 |
| 237 return third_party_dirs | 237 return third_party_dirs |
| 238 | 238 |
| 239 |
| 239 def ScanThirdPartyDirs(): | 240 def ScanThirdPartyDirs(): |
| 240 """Scan a list of directories and report on any problems we find.""" | 241 """Scan a list of directories and report on any problems we find.""" |
| 241 third_party_dirs = FindThirdPartyDirs() | 242 third_party_dirs = FindThirdPartyDirs() |
| 242 | 243 |
| 243 errors = [] | 244 errors = [] |
| 244 for path in sorted(third_party_dirs): | 245 for path in sorted(third_party_dirs): |
| 245 try: | 246 try: |
| 246 metadata = ParseDir(path) | 247 metadata = ParseDir(path) |
| 247 except LicenseError, e: | 248 except LicenseError, e: |
| 248 errors.append((path, e.args[0])) | 249 errors.append((path, e.args[0])) |
| 249 continue | 250 continue |
| 250 | 251 |
| 251 for path, error in sorted(errors): | 252 for path, error in sorted(errors): |
| 252 print path + ": " + error | 253 print path + ": " + error |
| 253 | 254 |
| 254 return len(errors) == 0 | 255 return len(errors) == 0 |
| 255 | 256 |
| 257 |
| 256 def GenerateCredits(): | 258 def GenerateCredits(): |
| 257 """Generate about:credits, dumping the result to stdout.""" | 259 """Generate about:credits, dumping the result to stdout.""" |
| 258 | 260 |
| 259 def EvaluateTemplate(template, env, escape=True): | 261 def EvaluateTemplate(template, env, escape=True): |
| 260 """Expand a template with variables like {{foo}} using a | 262 """Expand a template with variables like {{foo}} using a |
| 261 dictionary of expansions.""" | 263 dictionary of expansions.""" |
| 262 for key, val in env.items(): | 264 for key, val in env.items(): |
| 263 if escape: | 265 if escape: |
| 264 val = cgi.escape(val) | 266 val = cgi.escape(val) |
| 265 template = template.replace('{{%s}}' % key, val) | 267 template = template.replace('{{%s}}' % key, val) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 283 'license': open(metadata['License File'], 'rb').read(), | 285 'license': open(metadata['License File'], 'rb').read(), |
| 284 } | 286 } |
| 285 entries.append(EvaluateTemplate(entry_template, env)) | 287 entries.append(EvaluateTemplate(entry_template, env)) |
| 286 | 288 |
| 287 file_template = open('chrome/browser/resources/about_credits.tmpl', | 289 file_template = open('chrome/browser/resources/about_credits.tmpl', |
| 288 'rb').read() | 290 'rb').read() |
| 289 print "<!-- Generated by licenses.py; do not edit. -->" | 291 print "<!-- Generated by licenses.py; do not edit. -->" |
| 290 print EvaluateTemplate(file_template, {'entries': '\n'.join(entries)}, | 292 print EvaluateTemplate(file_template, {'entries': '\n'.join(entries)}, |
| 291 escape=False) | 293 escape=False) |
| 292 | 294 |
| 293 if __name__ == '__main__': | 295 |
| 296 def main(): |
| 294 command = 'help' | 297 command = 'help' |
| 295 if len(sys.argv) > 1: | 298 if len(sys.argv) > 1: |
| 296 command = sys.argv[1] | 299 command = sys.argv[1] |
| 297 | 300 |
| 298 if command == 'scan': | 301 if command == 'scan': |
| 299 if not ScanThirdPartyDirs(): | 302 if not ScanThirdPartyDirs(): |
| 300 sys.exit(1) | 303 return 1 |
| 301 elif command == 'credits': | 304 elif command == 'credits': |
| 302 if not GenerateCredits(): | 305 if not GenerateCredits(): |
| 303 sys.exit(1) | 306 return 1 |
| 304 else: | 307 else: |
| 305 print __doc__ | 308 print __doc__ |
| 306 sys.exit(1) | 309 return 1 |
| 310 |
| 311 |
| 312 if __name__ == '__main__': |
| 313 sys.exit(main()) |
| OLD | NEW |