Skip to content

Instantly share code, notes, and snippets.

@bracki
Forked from lentil/gist:810399
Created February 25, 2011 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bracki/843736 to your computer and use it in GitHub Desktop.
Save bracki/843736 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from __future__ import with_statement
import os
import re
import shutil
import subprocess
import sys
import tempfile
import shlex
def system(cmd, **kwargs):
cmd = shlex.split(cmd)
kwargs.setdefault('stdout', subprocess.PIPE)
kwargs.setdefault('stderr', subprocess.PIPE)
proc = subprocess.Popen(cmd, **kwargs)
out, err = proc.communicate()
return out
def run_command_for_file_type(cmd, file_type):
files = system('git diff-index --name-only --cached --diff-filter=ACMR HEAD')
interested_in = re.compile('.*\.%s$' % file_type, re.MULTILINE)
files = interested_in.findall(files)
tempdir = tempfile.mkdtemp()
for name in files:
system('
def main():
modified = re.compile('^[AM]+\s+(?P<name>.*\.py)', re.MULTILINE)
files = system('git diff-index --name-only --cached --diff-filter=ACMR HEAD')
filtempdir = tempfile.mkdtemp()
for name in files:es = modified.findall(files)
tempdir = tempfile.mkdtemp()
for name in files:
filename = os.path.join(tempdir, name)
filepath = os.path.dirname(filename)
if not os.path.exists(filepath):
os.makedirs(filepath)
with file(filename, 'w') as f:
system('git', 'show', ':' + name, stdout=f)
output = system('pep8', '.', cwd=tempdir)
shutil.rmtree(tempdir)
if output:
print output,
sys.exit(1)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment