-
-
Save Ayushverma8/094f56ec9ba7723a3ce00054f7476e0b to your computer and use it in GitHub Desktop.
A couple quick bash scripts so I can keep virtualenvs somewhat consistent across machines. backup-requirements.sh exports requirements files for each virtualenv, names the files for the virtualenv and sends them to a date-versioned directory. install-requirements.sh loops through a directory of requirements files and checks to see if a virtualen…
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 | |
# grab the virtualenvwrapper settings | |
export WORKON_HOME=$HOME/.virtualenvs | |
export PIP_VIRTUALENV_BASE=$WORKON_HOME | |
export PIP_RESPECT_VIRTUALENV=true | |
# the location of your virtualenv wrapper shell script may differ | |
source /usr/local/share/python/virtualenvwrapper.sh | |
# path to requirements files | |
# i'm creating date-versioned directories to make sure I don't lose anything | |
PROJECT_ROOT="/Volumes/one_tb_hd/_programming/3scripts-dotfiles/requirements/`date +%Y-%m-%d`-files" | |
# make a new directory | |
mkdir $PROJECT_ROOT | |
# set list of virtualenvs to an array | |
array_of_virtualenvs=($(workon)) | |
# loop through the array | |
for i in "${array_of_virtualenvs[@]}" | |
do | |
# create an output file | |
OUTPUTFILE="$i.txt" | |
# activate the virtualenv | |
workon $i | |
# output the packages to a file | |
pip freeze $i > "$OUTPUTFILE" | |
# move the file to a created directory | |
mv "$OUTPUTFILE" $PROJECT_ROOT | |
done |
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 | |
# grab the virtualenvwrapper settings | |
export WORKON_HOME=$HOME/.virtualenvs | |
export PIP_VIRTUALENV_BASE=$WORKON_HOME | |
export PIP_RESPECT_VIRTUALENV=true | |
# the location of your virtualenv wrapper shell script may differ | |
source /usr/local/share/python/virtualenvwrapper.sh | |
# make a virtual environment | |
makeVirtualEnv(){ | |
mkvirtualenv "$1" | |
} | |
# activate a virtual environment | |
activateVirtualEnv(){ | |
workon "$1" | |
} | |
# install requirements | |
installRequirements(){ | |
pip install -r "$1" | |
} | |
# path to exported requirements files | |
requirements_directory="/Volumes/one_tb_hd/_programming/3scripts-dotfiles/requirements" | |
# path to virtualenvs directory | |
virtualenvs="/Users/ckeller/.virtualenvs" | |
# move to the directory to store requirements files | |
cd "$requirements_directory" | |
# loop through each file in the directory | |
for file in "$requirements_directory"/* | |
# then do something | |
do | |
virtualenv_name=$(basename ${file%.*}) | |
requirements_name=$(basename $file) | |
# path where new projects will be created | |
PROJECT_PATH="$virtualenvs/$virtualenv_name" | |
if [ -d "$PROJECT_PATH" ]; | |
then | |
echo "$virtualenv_name already exists" | |
# activate the virtualenv | |
echo "Activating $virtualenv_name to install missing packages" | |
activateVirtualEnv $virtualenv_name | |
# install the requirements | |
echo "Installing missing packages from $requirements_name" | |
installRequirements $requirements_name | |
# show what was installed | |
echo "Here's what is installed in $virtualenv_name" | |
pip freeze | |
# if the environment doesn't exist | |
else | |
echo "$virtualenv_name doesn't exist" | |
# make the virtualenv | |
echo "Making $virtualenv_name virtualenv" | |
makeVirtualEnv $virtualenv_name | |
# activate the virtualenv | |
echo "Activating $virtualenv_name to install missing packages" | |
activateVirtualEnv $virtualenv_name | |
# install the requirements | |
echo "Installing missing packages from $requirements_name" | |
installRequirements $requirements_name | |
# show what was installed | |
echo "Here's what is installed in $virtualenv_name" | |
pip freeze | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment