Created
December 8, 2011 19:17
-
-
Save mattmcla/1448130 to your computer and use it in GitHub Desktop.
PEP8 Python file scrubbing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
# Text color variables | |
txtund=$(tput sgr 0 1) # Underline | |
txtbld=$(tput bold) # Bold | |
txtred=$(tput setaf 1) # Red | |
txtgrn=$(tput setaf 2) # Green | |
txtylw=$(tput setaf 3) # Yellow | |
txtblu=$(tput setaf 4) # Blue | |
txtpur=$(tput setaf 5) # Purple | |
txtcyn=$(tput setaf 6) # Cyan | |
txtwht=$(tput setaf 7) # White | |
txtrst=$(tput sgr0) # Text reset | |
bldgrn=${txtbld}${txtgrn} | |
bldred=${txtbld}${txtred} | |
if [ -f $1 ]; then | |
echo -n "Stripping Whitespace " | |
if ! sed -e 's/[ \t]*$//' $1 -i ; then | |
echo "${bldred}[FAIL]${txtrst}" | |
exit 1 | |
fi | |
echo "${bldgrn}[OK]${txtrst}" | |
echo -n "Space After Commas" | |
if ! sed -e "s/\(\w[\d\w\"']\),\([\d\w\"']\w\)/\1, \2/g" $1 -i ; then | |
echo "${bldred}[FAIL]${txtrst}" | |
exit 1 | |
fi | |
echo "${bldgrn}[OK]${txtrst}" | |
echo -n "PEP8 " | |
if ! pep8 $1; then | |
echo "${bldred}[FAIL]${txtrst}" | |
exit 1 | |
fi | |
echo "${bldgrn}[OK]${txtrst}" | |
echo -n "PyFlakes " | |
if ! pyflakes $1; then | |
echo "${bldred}[FAIL]${txtrst}" | |
exit 1 | |
fi | |
echo "${bldgrn}[OK]${txtrst}" | |
else | |
echo "$1 Not a file" | |
exit 1 | |
fi | |
echo "${bldgrn}Dunzo${txtrst}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment