Skip to content
Snippets Groups Projects
Commit 13c230ed authored by Bienchen's avatar Bienchen Committed by BIOPZ-Johner Niklaus
Browse files

More pre-commit hook

parent af3dcd9c
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment