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 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 | 260 |
261 def ContainsFiles(path): | 261 def ContainsFiles(path): |
262 """Determines whether any files exist in a directory or in any of its | 262 """Determines whether any files exist in a directory or in any of its |
263 subdirectories.""" | 263 subdirectories.""" |
264 for _, _, files in os.walk(path): | 264 for _, _, files in os.walk(path): |
265 if files: | 265 if files: |
266 return True | 266 return True |
267 return False | 267 return False |
268 | 268 |
269 | 269 |
270 def FindThirdPartyDirs(): | 270 def FindThirdPartyDirs(prune_paths): |
271 """Find all third_party directories underneath the current directory.""" | 271 """Find all third_party directories underneath the current directory.""" |
272 third_party_dirs = [] | 272 third_party_dirs = [] |
273 for path, dirs, files in os.walk('.'): | 273 for path, dirs, files in os.walk('.'): |
274 path = path[len('./'):] # Pretty up the path. | 274 path = path[len('./'):] # Pretty up the path. |
275 | 275 |
276 if path in PRUNE_PATHS: | 276 if path in prune_paths: |
277 dirs[:] = [] | 277 dirs[:] = [] |
278 continue | 278 continue |
279 | 279 |
280 # Prune out directories we want to skip. | 280 # Prune out directories we want to skip. |
281 # (Note that we loop over PRUNE_DIRS so we're not iterating over a | 281 # (Note that we loop over PRUNE_DIRS so we're not iterating over a |
282 # list that we're simultaneously mutating.) | 282 # list that we're simultaneously mutating.) |
283 for skip in PRUNE_DIRS: | 283 for skip in PRUNE_DIRS: |
284 if skip in dirs: | 284 if skip in dirs: |
285 dirs.remove(skip) | 285 dirs.remove(skip) |
286 | 286 |
287 if os.path.basename(path) == 'third_party': | 287 if os.path.basename(path) == 'third_party': |
288 # Add all subdirectories that are not marked for skipping. | 288 # Add all subdirectories that are not marked for skipping. |
289 for dir in dirs: | 289 for dir in dirs: |
290 dirpath = os.path.join(path, dir) | 290 dirpath = os.path.join(path, dir) |
291 if dirpath not in PRUNE_PATHS: | 291 if dirpath not in prune_paths: |
292 third_party_dirs.append(dirpath) | 292 third_party_dirs.append(dirpath) |
293 | 293 |
294 # Don't recurse into any subdirs from here. | 294 # Don't recurse into any subdirs from here. |
295 dirs[:] = [] | 295 dirs[:] = [] |
296 continue | 296 continue |
297 | 297 |
298 # Don't recurse into paths in ADDITIONAL_PATHS, like we do with regular | 298 # Don't recurse into paths in ADDITIONAL_PATHS, like we do with regular |
299 # third_party/foo paths. | 299 # third_party/foo paths. |
300 if path in ADDITIONAL_PATHS: | 300 if path in ADDITIONAL_PATHS: |
301 dirs[:] = [] | 301 dirs[:] = [] |
302 | 302 |
303 for dir in ADDITIONAL_PATHS: | 303 for dir in ADDITIONAL_PATHS: |
304 third_party_dirs.append(dir) | 304 third_party_dirs.append(dir) |
305 | 305 |
306 # If a directory contains no files, assume it's a DEPS directory for a | 306 # If a directory contains no files, assume it's a DEPS directory for a |
307 # project not used by our current configuration and skip it. | 307 # project not used by our current configuration and skip it. |
308 return [x for x in third_party_dirs if ContainsFiles(x)] | 308 return [x for x in third_party_dirs if ContainsFiles(x)] |
309 | 309 |
310 | 310 |
311 def ScanThirdPartyDirs(): | 311 def ScanThirdPartyDirs(): |
312 """Scan a list of directories and report on any problems we find.""" | 312 """Scan a list of directories and report on any problems we find.""" |
313 third_party_dirs = FindThirdPartyDirs() | 313 third_party_dirs = FindThirdPartyDirs(PRUNE_PATHS) |
314 | 314 |
315 errors = [] | 315 errors = [] |
316 for path in sorted(third_party_dirs): | 316 for path in sorted(third_party_dirs): |
317 try: | 317 try: |
318 metadata = ParseDir(path) | 318 metadata = ParseDir(path) |
319 except LicenseError, e: | 319 except LicenseError, e: |
320 errors.append((path, e.args[0])) | 320 errors.append((path, e.args[0])) |
321 continue | 321 continue |
322 | 322 |
323 for path, error in sorted(errors): | 323 for path, error in sorted(errors): |
324 print path + ": " + error | 324 print path + ": " + error |
325 | 325 |
326 return len(errors) == 0 | 326 return len(errors) == 0 |
327 | 327 |
328 | 328 |
329 def GenerateCredits(): | 329 def GenerateCredits(): |
330 """Generate about:credits, dumping the result to stdout.""" | 330 """Generate about:credits, dumping the result to stdout.""" |
331 | 331 |
332 def EvaluateTemplate(template, env, escape=True): | 332 def EvaluateTemplate(template, env, escape=True): |
333 """Expand a template with variables like {{foo}} using a | 333 """Expand a template with variables like {{foo}} using a |
334 dictionary of expansions.""" | 334 dictionary of expansions.""" |
335 for key, val in env.items(): | 335 for key, val in env.items(): |
336 if escape and not key.endswith("_unescaped"): | 336 if escape and not key.endswith("_unescaped"): |
337 val = cgi.escape(val) | 337 val = cgi.escape(val) |
338 template = template.replace('{{%s}}' % key, val) | 338 template = template.replace('{{%s}}' % key, val) |
339 return template | 339 return template |
340 | 340 |
341 third_party_dirs = FindThirdPartyDirs() | 341 third_party_dirs = FindThirdPartyDirs(PRUNE_PATHS) |
342 | 342 |
343 entry_template = open('chrome/browser/resources/about_credits_entry.tmpl', | 343 entry_template = open('chrome/browser/resources/about_credits_entry.tmpl', |
344 'rb').read() | 344 'rb').read() |
345 entries = [] | 345 entries = [] |
346 for path in sorted(third_party_dirs): | 346 for path in sorted(third_party_dirs): |
347 try: | 347 try: |
348 metadata = ParseDir(path) | 348 metadata = ParseDir(path) |
349 except LicenseError: | 349 except LicenseError: |
350 print >>sys.stderr, ("WARNING: licensing info for " + path + | 350 print >>sys.stderr, ("WARNING: licensing info for " + path + |
351 " is incomplete, skipping.") | 351 " is incomplete, skipping.") |
(...skipping 27 matching lines...) Expand all Loading... |
379 elif command == 'credits': | 379 elif command == 'credits': |
380 if not GenerateCredits(): | 380 if not GenerateCredits(): |
381 return 1 | 381 return 1 |
382 else: | 382 else: |
383 print __doc__ | 383 print __doc__ |
384 return 1 | 384 return 1 |
385 | 385 |
386 | 386 |
387 if __name__ == '__main__': | 387 if __name__ == '__main__': |
388 sys.exit(main()) | 388 sys.exit(main()) |
OLD | NEW |