Example:
db = SQLDB("sqlite://storage.sqlite") #@DEPLOY:db = SQLDB('postgres://mydb:mys3cr3tpassword@localhost/mydb')
# on the server side the code will be just
db = SQLDB('postgres://mydb:mys3cr3tpassword@localhost/mydb')
You may also easily add directories to be excluded in the syncing process. This works better with if you have previously transferred your SSH key so you don't have to type your password all the time.
Just edit the commented lines and put this content in a bash script:
!/bin/sh
# you should only have to edit lines with comments
SOURCE_APP="myapp_dev" # local
TARGET_APP="myapp_prod" # remote
SOURCE_APP_PATH="/whatever/path_to/web2py/applications/${SOURCE_APP}/" #change here
TARGET_APP_PATH="webapps/w2py_prod_folder_app/web2py/applications/${TARGET_APP}/" #change here
SOURCE_APP_PATH_STATIC="/whatever/path_to/web2py/applications/${SOURCE_APP}/static/" #change here
TARGET_APP_PATH_STATIC="webapps/folder_for_static_data" #change here
TARGET_SERVER="web94.webfaction.com" # change it to your hoster's hostname
TARGET_USER="user" # replace with your user
REGEX_FILE_EXT='\.\*\(py\|html\)$'
FIND_FILTER="-type f -name \*.html -o -name \*.py"
EXCLUDE_DIR="static"
EXCLUDE_DIR2="databases"
EXCLUDE_DIR3="setup"
TOKEN="`date \"+%y%m%d%H%M%S\"`_${SOURCE_APP}_${TARGET_APP}"
TEMP_DIR="$HOME/$TOKEN"
echo "generating processed server files…"
rm -rf ${TEMP_DIR}
mkdir -p ${TEMP_DIR}
cp -R ${SOURCE_APP_PATH} ${TEMP_DIR}
find ${TEMP_DIR} -type f \( -iname '*.py' -o -iname '*.html' \) -exec sed -i '' 's/.*#@DEPLOY:[[:space:]]*//g' {} \; # for Mac OS X and BSD derived
#find ${TEMP_DIR} -type f \( -iname '*.py' -o -iname '*.html' \) -exec sed -i 's/.*#@DEPLOY:[[:space:]]*//g' {} \; # for GNU/Linux
# you shouldn't have to change anything from now on...
echo "syncing app files…"
rsync -rah --delete --progress ${TEMP_DIR} ${TARGET_USER}@${TARGET_SERVER}:${TARGET_APP_PATH} --exclude "${EXCLUDE_DIR}" --exclude "${EXCLUDE_DIR2}" --exclude "${EXCLUDE_DIR3}"
echo "syncing static files…"
rsync -rah --compress --progress ${SOURCE_APP_PATH_STATIC} ${TARGET_USER}@${TARGET_SERVER}:${TARGET_APP_PATH_STATIC}
Comments (0)