Permalink
Browse files

Splitting code_init and env_setup

  • Loading branch information...
1 parent f14af8a commit ad07a3367f6503a415887b80f6931e96d55fdee1 @swaroopch committed May 10, 2011
Showing with 113 additions and 156 deletions.
  1. +7 −1 README.textile
  2. +14 −13 fabfile.py
  3. +28 −0 setup/bashutils.bash
  4. +10 −56 setup/{code_setup.bash → code_init.bash}
  5. +5 −7 setup/copy_html5.bash
  6. +9 −15 setup/custom_setup.bash
  7. +23 −0 setup/env_setup.bash
  8. +17 −64 setup/server_setup.bash
View
8 README.textile
@@ -19,7 +19,8 @@ h2. Get Started
@git clone git://github.com/swaroopch/flask-boilerplate.git mynewapp@
@cd mynewapp@
@pip install Fabric@
-@fab code_setup:mynewapp.com@
+@fab code_init:mynewapp.com@
+@fab env_setup@
Write your code in @flask_application/controllers/frontend.py@
@fab serve@
@@ -28,6 +29,11 @@ When you're ready to deploy your code to a server:
@fab server_setup@ # once per server
@fab deploy@
+When you clone a repo and want to run it:
+
+@fab env_setup@
+@fab serve@
+
h2. Also See
* "Mobile browser detection":https://github.com/shichuan/mobile-html5-boilerplate/wiki/Server-side-redirection-script to redirect users to a version of the website that uses the "Mobile HTML5 Boilerplate":http://html5boilerplate.com/mobile/.
View
27 fabfile.py
@@ -4,11 +4,11 @@
Run 'fab --list' to see list of available commands.
References:
-# http://docs.fabfile.org/0.9.3/usage/execution.html#how-host-lists-are-constructed
+# http://docs.fabfile.org/en/1.0.1/usage/execution.html#how-host-lists-are-constructed
'''
import platform
-assert (2,6) < platform.python_version_tuple() < (3,0)
+assert (2,6) <= platform.python_version_tuple() < (3,0)
import os
import datetime
@@ -32,9 +32,19 @@ def _transfer_files(src, dst, ssh_port=None):
local('rsync -avh --delete-before --copy-unsafe-links -e "ssh -p {0}" {1} {2}'.format(ssh_port, src, dst), capture=False)
-def code_setup(domain_name):
+def code_init(domain_name):
'''Initialize with this domain name.'''
- local('bash setup/code_setup.bash {0}'.format(domain_name))
+ local('bash setup/code_init.bash {0}'.format(domain_name))
+
+
+def env_setup():
+ '''Initialize environment.'''
+ local('bash setup/env_setup.bash')
+
+
+def serve():
+ '''Run the dev server'''
+ local('env DEV=yes python runserver.py', capture=False)
def server_setup():
@@ -92,15 +102,6 @@ def test():
local('env TEST=yes python tests.py', capture=False)
-def serve():
- '''Run the dev server'''
- local('env DEV=yes python runserver.py', capture=False)
-
-
-def apache():
- '''Install the Apache virtualhost config file.'''
- pass
-
def update_html5():
'''Update HTML5-Boilerplate.'''
local("cd html5 && git pull origin master")
View
28 setup/bashutils.bash
@@ -0,0 +1,28 @@
+
+## Color ##
+
+# http://linuxtidbits.wordpress.com/2008/08/11/output-color-on-bash-scripts/
+txtred=$(tput setaf 1)
+txtgreen=$(tput setaf 2)
+txtyellow=$(tput setaf 3)
+txtreset=$(tput sgr0)
+txtunderline=$(tput sgr 0 1)
+
+common_prefix="! "
+
+function info
+{
+ echo "$txtgreen$common_prefix$@$txtreset"
+}
+
+function warning
+{
+ echo "$txtyellow$common_prefix$@$txtreset"
+}
+
+function critical
+{
+ echo "$txtunderline$txtred$common_prefix$@$txtreset"
+ exit 1
+}
+
View
66 setup/code_setup.bash → setup/code_init.bash
@@ -1,11 +1,17 @@
#!/bin/bash
+## Environment ##
+
+SITE_CODE_DIR=$PWD
+APP_NAME="flask_application"
+
+source "$SITE_CODE_DIR/setup/bashutils.bash"
+
## Check Python version ##
if [[ $(python -c "import sys; print (2,6) <= sys.version_info < (3,0)") != "True" ]]
then
- echo "Need at least Python 2.6"
- exit 1
+ critical "Need at least Python 2.6"
fi
## Take website name as command line argument ##
@@ -15,68 +21,21 @@ shift
if [[ -z "$SITE_NAME" ]]
then
- echo "Usage: $0 SITE_NAME"
- exit 1
+ critical "Usage: $0 SITE_NAME"
fi
ADMIN_EMAIL="admin@$SITE_NAME"
-APP_NAME="flask_application"
-
-## Utilities ##
-
-# http://linuxtidbits.wordpress.com/2008/08/11/output-color-on-bash-scripts/
-txtred=$(tput setaf 1)
-txtgreen=$(tput setaf 2)
-txtyellow=$(tput setaf 3)
-txtreset=$(tput sgr0)
-txtunderline=$(tput sgr 0 1)
-
-common_prefix="! "
-
-function info
-{
- echo "$txtgreen$common_prefix$@$txtreset"
-}
-
-function warning
-{
- echo "$txtyellow$common_prefix$@$txtreset"
-}
-
-function critical
-{
- echo "$txtunderline$txtred$common_prefix$@$txtreset"
- exit 1
-}
-
# /home/foo -> \/home\/foo ... so that sed does not get confused.
LINUX_HOME="/home/$USER"
LINUX_HOME_ESCAPED=${LINUX_HOME//\//\\/}
-## Environment ##
-
-SITE_CODE_DIR=$PWD
-
## Assumptions ##
[[ -f "$SITE_CODE_DIR/$APP_NAME/__init__.py" ]] || critical "$SITE_CODE_DIR/$APP_NAME/__init__.py is missing"
## Main ##
-# Flask, assets, forms, scripts, email, caching, etc.
-info "Installing Python packages"
-pip install Flask Flask-Assets cssmin Flask-WTF Flask-Script Flask-Mail Flask-Cache || critical "Could not install Flask and dependencies"
-# Sitemap - NOTE This installation actually errors out for readme, but code does get installed.
-#pip install "http://www.florian-diesch.de/software/apesmit/dist/apesmit-0.01.tar.gz"
-
-# Custom dependencies
-info "Installing custom dependencies"
-bash "$SITE_CODE_DIR/setup/custom_setup.bash"
-
-info "NOTE This script assumes that you already have your system dependencies such as Memcache, MongoDB, etc. installed on your local machine already."
-info "NOTE The script will install system dependencies on the server when you do fab server_setup though."
-
info "Domain name --> $SITE_NAME"
cd "$SITE_CODE_DIR/$APP_NAME"
@@ -110,10 +69,5 @@ git rm $SITE_CODE_DIR/README.textile
info "Setting up the new git repo"
cd "$SITE_CODE_DIR"
-sed -i "" -e "s/origin/flask_boilerplate/g" ".git/config"
+#sed -i "" -e "s/origin/flask_boilerplate/g" ".git/config"
git commit -a -m "Initial commit for site $SITE_NAME"
-
-info "Fetching submodules"
-bash $SITE_CODE_DIR/setup/copy_html5.bash $SITE_CODE_DIR
-
-info "DONE"
View
12 setup/copy_html5.bash
@@ -1,23 +1,21 @@
#!/usr/bin/env bash
-function die
-{
- echo "$@"
- exit 1
-}
+## Environment ##
SITE_CODE_DIR=$1
shift
-[[ -n "$SITE_CODE_DIR" ]] || die "Usage: $0 SITE_CODE_DIR"
+[[ -n "$SITE_CODE_DIR" ]] || exit 1
+
+source "$SITE_CODE_DIR/setup/bashutils.bash"
APP_NAME="flask_application"
HTML5_DIR="$SITE_CODE_DIR/html5"
STATIC_DIR="$SITE_CODE_DIR/$APP_NAME/static"
TEMPLATE_DIR="$SITE_CODE_DIR/$APP_NAME/templates"
PUBLIC_DIR="$SITE_CODE_DIR/../../public"
-## main ##
+## Main ##
cd $SITE_CODE_DIR
git submodule update --init --recursive
View
24 setup/custom_setup.bash
@@ -1,23 +1,17 @@
-#!/usr/bin/env bash
+#!/bin/bash
-function die
-{
- echo "$@"
- exit 1
-}
+## Environment ##
-function install_apache_package
-{
- name=$1
- shift
- [[ -z "$name" ]] && die "Code Error: Called install_apache_package without a name"
+SITE_CODE_DIR=$PWD
+APP_NAME="flask_application"
- [[ -z $(dpkg -l | fgrep -i $name) ]] && ( sudo aptitude install $name || die "Could not apt-get $name package" )
-}
+source "$SITE_CODE_DIR/setup/bashutils.bash"
-SITE_CODE_DIR=$PWD
+## Assumptions ##
+
+[[ -f "$SITE_CODE_DIR/$APP_NAME/__init__.py" ]] || critical "$SITE_CODE_DIR/$APP_NAME/__init__.py is missing"
-## main ##
+## Main ##
# TODO Your code goes here
View
23 setup/env_setup.bash
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+## Environment ##
+
+SITE_CODE_DIR=$PWD
+APP_NAME="flask_application"
+
+source "$SITE_CODE_DIR/setup/bashutils.bash"
+
+## Assumptions ##
+
+[[ -f "$SITE_CODE_DIR/$APP_NAME/__init__.py" ]] || critical "$SITE_CODE_DIR/$APP_NAME/__init__.py is missing"
+
+## Main ##
+
+# Flask, assets, forms, scripts, email, caching, etc.
+echo "Installing Python packages"
+pip install Flask Flask-Assets cssmin Flask-WTF Flask-Script Flask-Mail Flask-Cache Fabric python-memcached || critical "Could not install Flask and dependencies"
+# Sitemap - NOTE This installation actually errors out for readme, but code does get installed.
+#pip install "http://www.florian-diesch.de/software/apesmit/dist/apesmit-0.01.tar.gz"
+
+# Custom requirements for your app
+source "$SITE_CODE_DIR/setup/custom_setup.bash"
View
81 setup/server_setup.bash
@@ -1,28 +1,28 @@
#!/usr/bin/env bash
+## Environment ##
+
+SITE_CODE_DIR=$PWD
+APP_NAME="flask_application"
+
+source "$SITE_CODE_DIR/setup/bashutils.bash"
+
## Check Operating system ##
# This script assumes Ubuntu directory structure.
# (The directory structure is different for different Linux distributions.)
-function die_without_linux
-{
- echo "This script works only with Ubuntu Linux and Bash."
- exit 1
-}
-
-[[ "$OSTYPE" == "linux-gnu" ]] || die_without_linux
-[[ $(which lsb_release) != "" ]] || die_without_linux
-[[ $(lsb_release -i) =~ "Ubuntu" ]] || die_without_linux
-[[ ${SHELL} =~ "bash" ]] || die_without_linux
-[[ "${BASH_VERSINFO[0]}" -ge "4" ]] || die_without_linux
+[[ "$OSTYPE" == "linux-gnu" ]] || critical "This script works only with Ubuntu Linux and Bash."
+[[ $(which lsb_release) != "" ]] || critical "This script works only with Ubuntu Linux and Bash."
+[[ $(lsb_release -i) =~ "Ubuntu" ]] || critical "This script works only with Ubuntu Linux and Bash."
+[[ ${SHELL} =~ "bash" ]] || critical "This script works only with Ubuntu Linux and Bash."
+[[ "${BASH_VERSINFO[0]}" -ge "4" ]] || critical "This script works only with Ubuntu Linux and Bash."
## Check Python version ##
if [[ $(python -c "import sys; print (2,6) <= sys.version_info < (3,0)") != "True" ]]
then
- echo "Need at least Python 2.6"
- exit 1
+ critical "Need at least Python 2.6"
fi
## Take website name as command line argument ##
@@ -32,44 +32,13 @@ shift
if [[ -z "$SITE_NAME" ]]
then
- echo "Usage: $0 SITE_NAME"
- exit 1
+ critical "Usage: $0 SITE_NAME"
fi
ADMIN_EMAIL="admin@$SITE_NAME"
-APP_NAME="flask_application"
-
## Utilities ##
-# http://linuxtidbits.wordpress.com/2008/08/11/output-color-on-bash-scripts/
-txtred=$(tput setaf 1)
-txtgreen=$(tput setaf 2)
-txtyellow=$(tput setaf 3)
-txtreset=$(tput sgr0)
-txtunderline=$(tput sgr 0 1)
-
-common_prefix="! "
-
-function info
-{
- echo "$txtgreen$common_prefix$@$txtreset"
-}
-
-function warning
-{
- echo "$txtyellow$common_prefix$@$txtreset"
-}
-
-function critical
-{
- echo "$txtunderline$txtred$common_prefix$@$txtreset"
- exit 1
-}
-
-# /home/foo -> \/home\/foo ... so that sed does not get confused.
-HOME_ESCAPED=${HOME//\//\\/}
-
function install_apt_package
{
name=$1
@@ -79,10 +48,6 @@ function install_apt_package
[[ -z $(dpkg -l | fgrep -i $name) ]] && ( sudo apt-get install $name || critical "Could not apt-get $name package" )
}
-## Environment ##
-
-SITE_CODE_DIR=$PWD
-
## Assumptions ##
[[ -f "$SITE_CODE_DIR/$APP_NAME/__init__.py" ]] || critical "$SITE_CODE_DIR/$APP_NAME/__init__.py is missing"
@@ -126,20 +91,8 @@ then
easy_install pip
fi
-info "Installing essential Apache build packages and Python library dependencies"
-
-# Flask
-pip install Flask Flask-Assets cssmin Flask-WTF Flask-Script Flask-Mail Flask-Cache || critical "Could not install Flask and dependencies"
-
-# Fabric
-pip install Fabric
-
-# Memcache
-pip install python-memcached
-
-# Custom stuff
-info "Installing custom dependencies"
-bash "$SITE_CODE_DIR/setup/custom_setup.bash"
+info "Installing essential Python library dependencies and other packages"
+bash "$SITE_CODE_DIR/setup/env_setup.bash"
info "Checking static directory symlink in public folder"
if [[ ! -L "$SITE_PUBLIC_DIR/static" ]]
@@ -158,11 +111,11 @@ then
sudo a2enmod headers # Needed for some features of the .htaccess provided by the HTML5-boilerplate
sudo /etc/init.d/apache2 restart || critical "Apache restart failed"
fi
+cd "$SITE_CODE_DIR"
info "Fetching submodules"
bash $SITE_CODE_DIR/setup/copy_html5.bash $SITE_CODE_DIR
-cd "$SITE_CODE_DIR"
info "DONE"
#set +x

0 comments on commit ad07a33

Please sign in to comment.