diff --git a/extras/pre-commit b/extras/pre-commit
index 43a0465a6b811ac8af525750b2b141df6bf5ae23..c32277c3d858ef7dbd693ed9989ceee007ccdd08 100755
--- a/extras/pre-commit
+++ b/extras/pre-commit
@@ -123,6 +123,8 @@ def GetFileType(filepath):
return "python"
elif fo == "%s: a ost script text executable" % filepath:
return "python"
+ elif fo == "%s: a /usr/bin/env ost script text executable" % filepath:
+ return "python"
elif fo == "%s: Bourne shell script text executable" % filepath:
return "shell-script"
elif fo == "%s: POSIX shell script text executable" % filepath:
@@ -192,21 +194,23 @@ def GetModFiles():
+"recognised by the pre-commit hook which is not handled.", 13)
return py_files, rst_files, cmake_files, shell_scripts, c_files, ukn_files
-def TestLineWidthExit(line, filename):
+def TestLineWidthExit(line, line_no, filename):
"""
Test the line width and fail.
"""
if len(line) > 79:
- FailMsg("Line width in '%s' exceeds 79 characters. For better " % filename
- +"readability of code, this is prohibited.", 15)
+ FailMsg("Line width in '%s:%d' exceeds 79 " % (filename, line_no)
+ +"characters. For better readability of code, this is prohibited.",
+ 15)
def CheckPythonCode(filepath):
fh = open(filepath, "U")
print_re = re.compile('print')
import_re = re.compile('import\s+\*')
+ lno = 1
for line in fh:
line = line.strip()
- TestLineWidthExit(line, filepath)
+ TestLineWidthExit(line, lno, filepath)
m_line = re.match('([^#]*)', line)
ex_line = m_line.group(1)
if len(ex_line):
@@ -216,34 +220,39 @@ def CheckPythonCode(filepath):
if import_re.match(ex_line):
FailMsg("'%s' imports *. This clutters namespaces." \
% filepath, 14)
+ lno += 1
def CheckRest(filepath):
fh = open(filepath, "U")
+ lno = 1
for line in fh:
line = line.strip()
- TestLineWidthExit(line, filepath)
-
+ TestLineWidthExit(line, lno, filepath)
+ lno += 1
def CheckCmake(filepath):
fh = open(filepath, "U")
+ lno = 1
for line in fh:
line = line.strip()
- TestLineWidthExit(line, filepath)
- return
+ TestLineWidthExit(line, lno, filepath)
+ lno += 1
def CheckShellScript(filepath):
fh = open(filepath, "U")
+ lno = 1
for line in fh:
line = line.strip()
- TestLineWidthExit(line, filepath)
- return
+ TestLineWidthExit(line, lno, filepath)
+ lno += 1
def CheckCCode(filepath):
fh = open(filepath, "U")
+ lno = 1
for line in fh:
line = line.strip()
- TestLineWidthExit(line, filepath)
- return
+ TestLineWidthExit(line, lno, filepath)
+ lno += 1
### FUNCTIONS - END
### MAIN - BEGIN