Commit c82d1bb0 authored by Ilias Tsitsimpis's avatar Ilias Tsitsimpis
Browse files

ci: Improve pep8 script

Rewrite the script in python.
Invoke pep8 for a list of files given in the command line.
Exclude files which are not python ones (their names don't
end with .py) or are not real files (i.e. have been removed
during the last commit).
parent ee229de8
#!/usr/bin/env python
Check for pep8 error in a list of files
Get a list of files as command line arguments.
Of these files, invoke pep8 only for the ones that
actually exists, their name ends with .py, and doesn't
belong to our exclude list.
import os
import sys
def filter_files(files):
"""Filter our non-useful files
We want to keep only python files (ending with .py),
that actually exists and are not in our exclude list
# Remove duplicated file names
files = list(set(files))
py_files = []
for f in files:
# Check if file is a python file
if not f.endswith(".py"):
#Check if file is to be excluded
if os.path.basename(f) in EXCLUDE:
# Check if file existsw
if not os.path.isfile(f):
# Append file name
return py_files
def run_pep8(files):
"""Invoke pep8
Return the exit code
if files:
print "Invoke pep8 for the following files:\n %s\n\n" \
% "\n ".join(files)
return os.system("pep8 %s" % " ".join(files))
print "No files to check.. aborting"
return 0
def main():
"""Our main program
Read command line arguments.
Filter out non-useful files.
Invoke pep8.
files = sys.argv[1:]
py_files = filter_files(files)
exit_code = run_pep8(py_files)
if exit_code != 0:
status = "exit with status %s" % exit_code
if __name__ == "__main__":
# Files to be excluded from pep8 tests
# Keep only *.py files
py_files=$(echo "$@" | awk '/.*\.py/' RS=" " ORS=" ")
if [ -z "$py_files" ]; then
echo "No files to be tested"
pep8 --exclude=$EXCLUDE $py_files
# !/usr/bin/env python
#!/usr/bin/env python
Synnefo ci utils module
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment