forked from cibomahto/s3g
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/env python | ||
from __future__ import with_statement | ||
import os | ||
import re | ||
import shutil | ||
import subprocess | ||
import sys | ||
import tempfile | ||
|
||
|
||
def system(*args, **kwargs): | ||
kwargs.setdefault('stdout', subprocess.PIPE) | ||
proc = subprocess.Popen(args, **kwargs) | ||
out, err = proc.communicate() | ||
return out | ||
|
||
|
||
def main(): | ||
ignores = ['W391', # Blank line at end of file | ||
'E128', # continuation line under-indented | ||
'E501', # line too long :( | ||
] # --ignore=E501,E128,W391 | ||
modified = re.compile('^[AM]+\s+(?P<name>.*\.py)', re.MULTILINE) | ||
files = system('git', 'status', '--porcelain') | ||
files = 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', '.', '--ignore=' + ','.join(ignores), cwd=tempdir) | ||
shutil.rmtree(tempdir) | ||
if output: | ||
print output, | ||
sys.exit(1) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |