Skip to content

Instantly share code, notes, and snippets.

@mattmcla
Created January 5, 2012 00:05
Show Gist options
  • Save mattmcla/1562952 to your computer and use it in GitHub Desktop.
Save mattmcla/1562952 to your computer and use it in GitHub Desktop.
cleanpy
#!/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}"
# (["'a-z0-9])(?:\\?.)*?\1,([^ ])
echo -n "Space After Commas "
if ! sed -re "s/([a-z0-9\"']),([a-z0-9\"'])/\1, \2/gi" $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