/src/etc/tidy.py
Python | 50 lines | 36 code | 12 blank | 2 comment | 22 complexity | 40dd39526555dbec033721f894ae3cf6 MD5 | raw file
1#!/usr/bin/env python 2 3import sys, fileinput, subprocess, re 4 5err=0 6cols=78 7 8# Be careful to support Python 2.4, 2.6, and 3.x here! 9config_proc=subprocess.Popen([ "git", "config", "core.autocrlf" ], 10 stdout=subprocess.PIPE) 11result=config_proc.communicate()[0] 12 13true="true".encode('utf8') 14autocrlf=result.strip() == true if result is not None else False 15 16def report_err(s): 17 global err 18 print("%s:%d: %s" % (fileinput.filename(), fileinput.filelineno(), s)) 19 err=1 20 21file_names = [s for s in sys.argv[1:] if (not s.endswith("_gen.rs")) 22 and (not s.startswith(".#"))] 23 24try: 25 for line in fileinput.input(file_names, 26 openhook=fileinput.hook_encoded("utf-8")): 27 28 if fileinput.filename().find("tidy.py") == -1: 29 if line.find("FIXME") != -1: 30 if re.search("FIXME.*#\d+", line) == None: 31 report_err("FIXME without issue number") 32 if line.find("TODO") != -1: 33 report_err("TODO is deprecated; use FIXME") 34 if (line.find('\t') != -1 and 35 fileinput.filename().find("Makefile") == -1): 36 report_err("tab character") 37 if not autocrlf and line.find('\r') != -1: 38 report_err("CR character") 39 if line.endswith(" \n") or line.endswith("\t\n"): 40 report_err("trailing whitespace") 41 line_len = len(line)-2 if autocrlf else len(line)-1 42 43 if line_len > cols: 44 report_err("line longer than %d chars" % cols) 45except UnicodeDecodeError, e: 46 report_err("UTF-8 decoding error " + str(e)) 47 48 49sys.exit(err) 50