Skip to content

Instantly share code, notes, and snippets.

@jdcantrell
Created December 8, 2011 18:50
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdcantrell/1448021 to your computer and use it in GitHub Desktop.
Save jdcantrell/1448021 to your computer and use it in GitHub Desktop.
FeDev Fabfile
from __future__ import with_statement
from fabric.api import task, local, lcd, run, cd
from fabric.colors import blue, green, red
username = 'jcantrell'
''' Updates the config files for directory so that they work correctly on
fedev.
Usage: fab setup:directory
'''
@task
def setup(directory):
#update .htaccesss
with lcd('./%s/' % directory):
print(blue('Updating .htaccess...', True))
local('sed -i "" -e "s/^RewriteBase/#RewriteBase/" .htaccess')
local('sed -i "" -e "s/^#RewriteBase \/~roger/RewriteBase \/~%s/" .htaccess' % username)
local('sed -i "" -e "s/cobrand_merge/%s/" .htaccess' % directory)
local('sed -i "" -e "s/roger/%s/" .htaccess' % username)
#update local.conf
print(blue('Updating local.conf...', True))
local('sed -i "" -e "s/\/\* BEGIN USER SETTINGS//" include/local.conf')
#update site.conf
print(blue('Updating site.conf...', True))
local('sed -i "" -e "s/base_path=%URI_PATH%/base_path=/" config/site.conf')
local('sed -i "" -e "s/%%TPL_PATH%%/\/home\/%s\/public_html\/%s\/cobrand\/sofia\/templates\//" config/site.conf' % (username, directory))
local('sed -i "" -e "s/%%URI_PATH%%/\/~%s\/%s\//" config/site.conf' % (username, directory))
lcd('../')
print(green('http://fedev.utah.trulia.com/~%s/%s/ should be ready to go.', True) % (username, directory))
''' Pulls code from svn and sets up config files for development on fedev
Usage: fab pull:branch,directory
'''
@task
def pull(branch, directory):
print(blue('Checking out %s into %s', True) % (branch, directory))
local('svn co svn+ssh://svn/usr/local/svnrepos/TRULIA/FE/www/branches/%s %s' % (branch, directory))
sync(directory, directory)
print(blue('Setting up development environment...', True))
setup(directory)
''' Pull code and sync to fedev:~/svn/
'''
@task
def pull_common(branch, directory):
print(blue('Checking out %s into %s', True) % (branch, directory))
if branch == "trunk":
local('svn co svn+ssh://svn/usr/local/svnrepos/TRULIA/COMMON/trunk %s' % directory)
else:
local('svn co svn+ssh://svn/usr/local/svnrepos/TRULIA/COMMON/branches/%s %s' % (branch, directory))
sync(directory, directory, 'common')
print(green('New common branch being synced to %s@~/svn/%s', True) % (username, directory))
''' Sync a directory to fedev
Usage: fab sync:localDir,remoteDir - puts localDir in ~/public_html
fab sync:localDir,remoteDir,common - puts localDir in ~/svn
'''
@task
def sync(localDir, directory, where='www'):
print(blue('Updating Guardfile...', True))
local('echo \' watch( %%r{^%s/.*} ) { |m| sync_%s("%s", "%s", m[0]) }\' >> Guardfile' % (localDir, where, localDir, directory))
local('sed -i "" -e "/^end/d" Guardfile')
local('echo "end" >> GuardFile')
print(green('New common branch being synced to %s@~/svn/%s', True) % (username, directory))
''' Merge cobrand_merge into other branches
Usage: fab merge_up
It expects to have clean checkouts in a folder called
./clean_checkouts. If svn status is not empty it will not attempt to
merge. As of the moment it will only merge, it does not yet commit.
'''
@task
def merge_up(path="",branch="cobrand_merge"):
print(blue("Merging up %s for branches in ./clean_checkouts/" % branch))
if path == "":
dirs = local('ls ./clean_checkouts', capture=True).split("\n")
else :
dirs = ['%s' % path]
print(green("These paths will be merged: %s" % ", ".join(dirs)))
for d in dirs:
with lcd('./clean_checkouts/%s' % d):
status = local('svn status', capture=True)
if len(status) > 1:
print(red('Uncommitted changes found in %s, skipping', True) % d)
else:
#svn up before we merge
print(blue('Updating working copy', True))
local('svn up')
#svn merge branch into ./
print(blue('Merging up %s into %s', True) % (branch, d))
merge = local('svn merge svn+ssh://svn/usr/local/svnrepos/TRULIA/FE/www/branches/%s ./ --accept postpone' % branch, capture=True)
if merge.find('conflicts:') == -1:
print(green('Merged cleanly (-:', True))
#TODO: warn about .htaccess, site.conf and local.conf
local('svn commit -m "Merged up from %s"' % branch)
else:
print(red('Conflicts found, please resolve and commit )-:', True))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment