Last active
August 28, 2015 08:21
-
-
Save SeavantUUz/a9374a4f5ff230c9c056 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# coding: utf-8 | |
__inspired__ = 'jimmyislive <https://github.com/jimmyislive/hg-pylint-commit-hook>' | |
__author__ = 'AprocySanae' | |
import os | |
import subprocess | |
from hgapi import hgapi | |
import re | |
from StringIO import StringIO | |
Threshold = 5 | |
golden_fingers = { | |
} | |
PATTERN = 'Your code has been rated at -*(\d+\.\d*)/10' | |
def pylint_hook(ui, repo, **kwargs): | |
base_path = os.path.dirname(repo.path) | |
hgrepo = hgapi.Repo(os.path.abspath(os.curdir)) | |
hg_status = hgrepo.hg_status() | |
candidate_files = [] | |
candidate_files.extend(hg_status['A']) | |
candidate_files.extend(hg_status['M']) | |
failed = False | |
for item in candidate_files: | |
file_path = os.path.join(base_path, item) | |
if file_path.endswith('.py'): | |
p = subprocess.Popen(['pylint', file_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
stdoutdata, stderrdata = p.communicate() | |
print ('>>>CHECKING {}!<<<'.format(item)) | |
print('***\nStdErr: {}\n***'.format(stderrdata)) | |
print('***\nStdOut: {}\n***'.format(stdoutdata)) | |
match = re.search(PATTERN, stdoutdata, re.I|re.M) | |
if match and len(match.groups()): | |
score = float(match.group(1)) | |
score += golden_fingers.get(item, 0) | |
if score >= Threshold: | |
print 'File {} is a real man, score: {}'.format(item, score) | |
else: | |
failed = True | |
print '***WARNING!!!!****\nFile {} is a not real man'.format(item) | |
else: | |
failed = True | |
print '****ERROR!!!***' | |
if failed: | |
print 'pylint checks failed!' | |
return True | |
else: | |
print 'GOOD JOB! MAN!' | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment