Skip to content

Instantly share code, notes, and snippets.

@peterbe
Created June 10, 2011 09:46
Show Gist options
  • Save peterbe/1018559 to your computer and use it in GitHub Desktop.
Save peterbe/1018559 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
"""
Usage: licence_check.py [directory]
Finds all checked in files that suspiciously lack a MPL licensing header.
Options:
-h, --help show this help message and exit
(c) peterbe@mozilla.com, June 2011
"""
import subprocess
from collections import defaultdict
def check(filename):
content = open(filename).read()
if 'MPL 1.1' not in content:
if content.strip():
if len(content.splitlines()) > 1:
return True
def search(dir):
command = "git ls-files %s | grep -E '\.(js|css|py|html)$'" % dir
out, err = subprocess.Popen(command, shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE
).communicate()
for filename in out.splitlines():
if check(filename):
yield filename
def main(*args):
if '-h' in args or '--help' in args:
print __doc__
return 1
groups = defaultdict(list)
if not args:
args = ('apps',)
for arg in args:
for filename in search(arg):
groups[filename.split('.')[-1]].append(filename)
for ext in sorted(groups):
print ext.upper()
for name in groups[ext]:
print name
print
return 0
if __name__ == '__main__':
import sys
sys.exit(main(*sys.argv[1:]))
@peterbe
Copy link
Author

peterbe commented Jun 10, 2011

Find 17 files in 0.03 seconds on my macbook pro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment