OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 | 303 |
304 def ContainsFiles(path): | 304 def ContainsFiles(path): |
305 """Determines whether any files exist in a directory or in any of its | 305 """Determines whether any files exist in a directory or in any of its |
306 subdirectories.""" | 306 subdirectories.""" |
307 for _, _, files in os.walk(path): | 307 for _, _, files in os.walk(path): |
308 if files: | 308 if files: |
309 return True | 309 return True |
310 return False | 310 return False |
311 | 311 |
312 | 312 |
313 def FindThirdPartyDirs(): | 313 def FindThirdPartyDirs(prune_paths): |
314 """Find all third_party directories underneath the current directory.""" | 314 """Find all third_party directories underneath the current directory.""" |
315 third_party_dirs = [] | 315 third_party_dirs = [] |
316 for path, dirs, files in os.walk('.'): | 316 for path, dirs, files in os.walk('.'): |
317 path = path[len('./'):] # Pretty up the path. | 317 path = path[len('./'):] # Pretty up the path. |
318 | 318 |
319 if path in PRUNE_PATHS: | 319 if path in prune_paths: |
320 dirs[:] = [] | 320 dirs[:] = [] |
321 continue | 321 continue |
322 | 322 |
323 # Prune out directories we want to skip. | 323 # Prune out directories we want to skip. |
324 # (Note that we loop over PRUNE_DIRS so we're not iterating over a | 324 # (Note that we loop over PRUNE_DIRS so we're not iterating over a |
325 # list that we're simultaneously mutating.) | 325 # list that we're simultaneously mutating.) |
326 for skip in PRUNE_DIRS: | 326 for skip in PRUNE_DIRS: |
327 if skip in dirs: | 327 if skip in dirs: |
328 dirs.remove(skip) | 328 dirs.remove(skip) |
329 | 329 |
330 if os.path.basename(path) == 'third_party': | 330 if os.path.basename(path) == 'third_party': |
331 # Add all subdirectories that are not marked for skipping. | 331 # Add all subdirectories that are not marked for skipping. |
332 for dir in dirs: | 332 for dir in dirs: |
333 dirpath = os.path.join(path, dir) | 333 dirpath = os.path.join(path, dir) |
334 if dirpath not in PRUNE_PATHS: | 334 if dirpath not in prune_paths: |
335 third_party_dirs.append(dirpath) | 335 third_party_dirs.append(dirpath) |
336 | 336 |
337 # Don't recurse into any subdirs from here. | 337 # Don't recurse into any subdirs from here. |
338 dirs[:] = [] | 338 dirs[:] = [] |
339 continue | 339 continue |
340 | 340 |
341 # Don't recurse into paths in ADDITIONAL_PATHS, like we do with regular | 341 # Don't recurse into paths in ADDITIONAL_PATHS, like we do with regular |
342 # third_party/foo paths. | 342 # third_party/foo paths. |
343 if path in ADDITIONAL_PATHS: | 343 if path in ADDITIONAL_PATHS: |
344 dirs[:] = [] | 344 dirs[:] = [] |
345 | 345 |
346 for dir in ADDITIONAL_PATHS: | 346 for dir in ADDITIONAL_PATHS: |
347 third_party_dirs.append(dir) | 347 third_party_dirs.append(dir) |
348 | 348 |
349 # If a directory contains no files, assume it's a DEPS directory for a | 349 # If a directory contains no files, assume it's a DEPS directory for a |
350 # project not used by our current configuration and skip it. | 350 # project not used by our current configuration and skip it. |
351 return [x for x in third_party_dirs if ContainsFiles(x)] | 351 return [x for x in third_party_dirs if ContainsFiles(x)] |
352 | 352 |
353 | 353 |
354 def ScanThirdPartyDirs(): | 354 def ScanThirdPartyDirs(): |
355 """Scan a list of directories and report on any problems we find.""" | 355 """Scan a list of directories and report on any problems we find.""" |
356 third_party_dirs = FindThirdPartyDirs() | 356 third_party_dirs = FindThirdPartyDirs(PRUNE_PATHS) |
357 | 357 |
358 errors = [] | 358 errors = [] |
359 for path in sorted(third_party_dirs): | 359 for path in sorted(third_party_dirs): |
360 try: | 360 try: |
361 metadata = ParseDir(path) | 361 metadata = ParseDir(path) |
362 except LicenseError, e: | 362 except LicenseError, e: |
363 errors.append((path, e.args[0])) | 363 errors.append((path, e.args[0])) |
364 continue | 364 continue |
365 | 365 |
366 for path, error in sorted(errors): | 366 for path, error in sorted(errors): |
367 print path + ": " + error | 367 print path + ": " + error |
368 | 368 |
369 return len(errors) == 0 | 369 return len(errors) == 0 |
370 | 370 |
371 | 371 |
372 def GenerateCredits(): | 372 def GenerateCredits(): |
373 """Generate about:credits, dumping the result to stdout.""" | 373 """Generate about:credits, dumping the result to stdout.""" |
374 | 374 |
375 def EvaluateTemplate(template, env, escape=True): | 375 def EvaluateTemplate(template, env, escape=True): |
376 """Expand a template with variables like {{foo}} using a | 376 """Expand a template with variables like {{foo}} using a |
377 dictionary of expansions.""" | 377 dictionary of expansions.""" |
378 for key, val in env.items(): | 378 for key, val in env.items(): |
379 if escape and not key.endswith("_unescaped"): | 379 if escape and not key.endswith("_unescaped"): |
380 val = cgi.escape(val) | 380 val = cgi.escape(val) |
381 template = template.replace('{{%s}}' % key, val) | 381 template = template.replace('{{%s}}' % key, val) |
382 return template | 382 return template |
383 | 383 |
384 third_party_dirs = FindThirdPartyDirs() | 384 third_party_dirs = FindThirdPartyDirs(PRUNE_PATHS) |
385 | 385 |
386 entry_template = open('chrome/browser/resources/about_credits_entry.tmpl', | 386 entry_template = open('chrome/browser/resources/about_credits_entry.tmpl', |
387 'rb').read() | 387 'rb').read() |
388 entries = [] | 388 entries = [] |
389 for path in sorted(third_party_dirs): | 389 for path in sorted(third_party_dirs): |
390 try: | 390 try: |
391 metadata = ParseDir(path) | 391 metadata = ParseDir(path) |
392 except LicenseError: | 392 except LicenseError: |
393 print >>sys.stderr, ("WARNING: licensing info for " + path + | 393 print >>sys.stderr, ("WARNING: licensing info for " + path + |
394 " is incomplete, skipping.") | 394 " is incomplete, skipping.") |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 elif command == 'credits': | 426 elif command == 'credits': |
427 if not GenerateCredits(): | 427 if not GenerateCredits(): |
428 return 1 | 428 return 1 |
429 else: | 429 else: |
430 print __doc__ | 430 print __doc__ |
431 return 1 | 431 return 1 |
432 | 432 |
433 | 433 |
434 if __name__ == '__main__': | 434 if __name__ == '__main__': |
435 sys.exit(main()) | 435 sys.exit(main()) |
OLD | NEW |