Skip to content

Instantly share code, notes, and snippets.

@kellya
Last active September 11, 2015 21:16
Show Gist options
  • Save kellya/29e4597db48c21428d96 to your computer and use it in GitHub Desktop.
Save kellya/29e4597db48c21428d96 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Defaults to pip2 unless otherwise specified
if [ "$1" = 3 ]; then
PYTHON_VERSION=3
fi
function outdated() {
# List out outdated python packages delimited by newline
pip${PYTHON_VERSION} list --outdated \
| sed \
-e 's/(.*//g' \
-e '/^Could/ d' \
-e '/^Some/ d'
}
main() {
echo "Unpacking outdated packages for Python ${PYTHON_VERSION:-2}"
declare -a list=( $(outdated) )
# Loop through each package and install upgrade
for ((i=0; i<${#list[@]}; i++)); do
printf "Installing Package: %-20s" "${list[i]}"
# Checks for successful installation
if [ "pip${PYTHON_VERSION} install --upgrade ${list[i]} >/dev/null" ]; then
printf "$(tput setaf 2)%s$(tput sgr0)\n" "Success"
else
printf "$(tput setaf 1)%s$(tput sgr0)\n" "Fail"
fi
done
}
if [ "$0" = "${BASH_SOURCE}" ]; then
main
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment