From debc76ce79142a404f0dac263f983f4b6b73073e Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 7 Aug 2014 00:40:20 +0200 Subject: [PATCH] run_checks: Refactor VCS commit checking. --- scripts/run_checks.py | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/scripts/run_checks.py b/scripts/run_checks.py index aa5493fa5..924cc65b0 100755 --- a/scripts/run_checks.py +++ b/scripts/run_checks.py @@ -178,33 +178,26 @@ def check_git(): print() -def check_line(target): - """Run _check_file over a filetree.""" - print("------ line ------") - ret = [] +def check_vcs_conflict(target): + """Check VCS conflict markers.""" + print("------ VCS conflict markers ------") try: + ok = True for (dirpath, _dirnames, filenames) in os.walk(target): for name in (e for e in filenames if e.endswith('.py')): fn = os.path.join(dirpath, name) - ret.append(_check_file(fn)) - status['line_' + target] = all(ret) + with open(fn, 'r') as f: + for line in f: + if any(line.startswith(c * 7) for c in '<>=|'): + print("Found conflict marker in {}".format(fn)) + ok = False + status['vcs_' + target] = ok except Exception as e: print('{}: {}'.format(e.__class__.__name__, e)) - status['line_' + target] = None + status['vcs_' + target] = None print() -def _check_file(fn): - """Check a single file for CRLFs, conflict markers and weird whitespace.""" - ok = True - with open(fn, 'rb') as f: - for line in f: - if any(line.decode('UTF-8').startswith(c * 7) for c in "<>=|"): - print("Found conflict marker in {}".format(fn)) - ok = False - return ok - - def _get_args(checker): """Construct the arguments for a given checker. @@ -273,7 +266,7 @@ for trg in options['targets']: for chk in ('pylint', 'flake8'): # FIXME what the hell is the flake8 exit status? run(chk, trg, _get_args(chk)) - check_line(trg, ) + check_vcs_conflict(trg) if '--setup' in argv: print("==================== Setup checks ====================")