Skip to content

Instantly share code, notes, and snippets.

@dhruvbaldawa
Created February 12, 2013 10:56
Show Gist options
  • Save dhruvbaldawa/4761557 to your computer and use it in GitHub Desktop.
Save dhruvbaldawa/4761557 to your computer and use it in GitHub Desktop.
Reload database script for Flask
#### I am no Bash expert, I just googled and put this script together
#### Be free to fork and post updates to this gist
#### Also, you can change the username and email below for the django superuser
DEFAULT_USER="dhruv"
DEFAULT_EMAIL="dbaldawa@enthought.com"
DEFAULT_PASS="d"
function usage
{
echo "usage: $0 [-r | --runserver]"
}
runserver=
while [ "$1" != "" ]; do
case $1 in
-r | --runserver ) runserver=1
;;
-h | --help ) usage
exit
;;
* ) usage
exit 1
esac
shift
done
######## MAIN CLEAN #########
rm website.db
python manage.py init_db
export PYTHONPATH=.
## python manage.py migrate
### Create super-user
echo "from grits.users.models import User;\
from grits.polenta.models import Action;\
import time;\
u = User(email='$DEFAULT_EMAIL', password='$DEFAULT_PASS', active=True);\
u.save();\
details = {'tags': ['__root__'], 'expiration': 253402300800};\
action_dict = {'guid': u.id, 'action_type': 'grant_until', 'action_time': time.time(), 'details': details};\
a = Action(**action_dict);\
a.save()
" | python manage.py shell --no-ipython
######## OPTIONAL RUNSERVER ########
if [ "$runserver" = "1" ]; then
python manage.py runserver
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment