Created
October 10, 2020 12:21
-
-
Save galatolofederico/285a2b0b9d1529d4b3941d0cf5a54e6d to your computer and use it in GitHub Desktop.
Freeze and remove old virtualenvs
This file contains hidden or 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 | |
| # shellcheck source=/dev/null | |
| # Example: | |
| # Freeze and delete virtualenvs folders older than 100 days: | |
| # | |
| # find ./ -maxdepth 1 -type d -mtime +100 -print | ./virtualenvs_cleanup.sh | |
| # | |
| REQUIREMENTS_FILE="requirements.bak.txt" | |
| VIRTUALENV_NAMES=( "env" "venv" ) | |
| while IFS= read -r folder; do | |
| for env in "${VIRTUALENV_NAMES[@]}"; do | |
| current_env="${folder:?}/${env:?}" | |
| if [ -d "${current_env}" ]; then | |
| echo "Freezing ${current_env}" | |
| source "${current_env}/bin/activate" | |
| pip freeze > "${folder:?}/${env}_${REQUIREMENTS_FILE}" | |
| deactivate | |
| echo "Deleting ${current_env}" | |
| rm -rf "${current_env}" | |
| fi | |
| done | |
| done < "${1:-/dev/stdin}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment