Skip to content

Instantly share code, notes, and snippets.

@bradwright
Forked from urschrei/mkflask.sh
Created May 13, 2012 19:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bradwright/2689895 to your computer and use it in GitHub Desktop.
Save bradwright/2689895 to your computer and use it in GitHub Desktop.
Bootstrap a Flask project
#!/bin/bash -e
# opinionated Flask bootstrap script
# assumes you'll be using MySQL, Fabric, and Blueprints
# creates a virtualenv and an Alembic migrations system
# The script will halt on any error, and remove the project dir if it created one
# accepts a single argument: a new directory name under which to create the project
# check that Python is installed
type python >/dev/null 2>&1 || { echo >&2 "Python doesn't appear to be installed. Aborting."; exit 1; }
# check that there's a system-wide virtualenv package installed
type virtualenv >/dev/null 2>&1 || { echo >&2 "This script requires a system-wide install of Virtualenv. Aborting."; exit 1; }
if [ ! -d $1 ]; then
# error handler removes the created project dir if there's a problem
dir=`pwd`
trap 'echo "Cleaning up"; cd $dir; rm -rf $1' INT TERM EXIT
mkdir -p $1/app/config
mkdir -p $1/app/templates/errors
mkdir -p $1/app/static/{css,js,img}
mkdir -p $1/apps
mkdir -p $1/fabfile
touch $1/requirements.txt
virtualenv $1/venv
source $1/venv/bin/activate
for package in flask fabric yolk flask-sqlalchemy mysql-python alembic ipython
do
echo "$package" >> $1/requirements.txt
done
pip install -r $1/requirements.txt
$1/venv/bin/easy_install readline
cd $1
alembic init db
cd ..
touch $1/run.py
touch $1/app/__init__.py
touch $1/fabfile/__init__.py
touch $1/app/config/common.py
touch $1/app/config/dev.py
trap 'echo "Finished creating project skeleton"' INT TERM EXIT
deactivate
else
{ echo >&2 "That directory already exists. Aborting."; exit 1; }
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment