Skip to content

Commit

Permalink
add djangofab.api which imports common fabric and djangofab functions
Browse files Browse the repository at this point in the history
updated examples to simplify imports
  • Loading branch information
Harley Bussell committed Sep 22, 2009
1 parent 1f197a3 commit dbe0740
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 43 deletions.
7 changes: 2 additions & 5 deletions djangofab/decorator.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@
import sys import sys
import ConfigParser import ConfigParser
import subprocess import subprocess
from fabric.api import * from djangofab.util import apply_settings
from fabric.context_managers import *

from djangofab.util import _apply_settings


def user_settings(file='fab.cfg', group='default'): def user_settings(file='fab.cfg', group='default'):
"Decorator to load user settings from a config file into the env" "Decorator to load user settings from a config file into the env"
def wrap(f=None): def wrap(f=None):
def wrapped_f(*args): def wrapped_f(*args):
f(*args) f(*args)
_apply_settings(file,group) apply_settings(file,group)
return wrapped_f return wrapped_f
return wrap return wrap


Expand Down
6 changes: 2 additions & 4 deletions djangofab/django.py
Original file line number Original file line Diff line number Diff line change
@@ -1,8 +1,7 @@

from __future__ import with_statement from __future__ import with_statement
from fabric.context_managers import cd
from fabric.api import env, run, get, sudo
from djangofab.util import local as local
import os import os
from djangofab.api import *


def get_remote_db(): def get_remote_db():
"Download the latest database from the server and load it onto your local database" "Download the latest database from the server and load it onto your local database"
Expand Down Expand Up @@ -37,7 +36,6 @@ def put_local_db():
(settings.DATABASE_USER, settings.DATABASE_PASSWORD, settings.DATABASE_NAME)) (settings.DATABASE_USER, settings.DATABASE_PASSWORD, settings.DATABASE_NAME))


def get_db_settings(): def get_db_settings():
from fabric.operations import _handle_failure
try: try:
from fabfile import settings from fabfile import settings
except ImportError: except ImportError:
Expand Down
16 changes: 5 additions & 11 deletions djangofab/util.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,24 +2,18 @@
import sys import sys
import ConfigParser import ConfigParser
import subprocess import subprocess
#from fabric.api import * from djangofab.api import *
#from fabric.context_managers import *

from fabric.api import local as _local
from fabric.api import env


from fabric.state import env, connections, output
#def local_out(cmd):
# return local(cmd,False)


def local(cmd): def local(cmd):
if hasattr(env,'capture_default'): if hasattr(env,'capture_default'):
_local(cmd, env.capture_default) _local(cmd, env.capture_default)
else: else:
_local(cmd) _local(cmd)


def _apply_settings(file='fab.cfg', group='default'): def apply_settings(file='fab.cfg', group='default'):
if not os.path.exists(file):
_handle_failure(message='Configuration file %s does not exist' % file)
return
config = ConfigParser.ConfigParser() config = ConfigParser.ConfigParser()
config.readfp(open(file)) config.readfp(open(file))
user_settings = {} user_settings = {}
Expand Down
4 changes: 1 addition & 3 deletions djangofab/vcs/git.py
Original file line number Original file line Diff line number Diff line change
@@ -1,7 +1,5 @@
from __future__ import with_statement from __future__ import with_statement
from fabric.api import run, env from djangofab.api import *
from fabric.context_managers import cd
from djangofab.util import local as local, safe_local


def update_remote(): def update_remote():
"Update remote checkout to the latest version" "Update remote checkout to the latest version"
Expand Down
5 changes: 2 additions & 3 deletions djangofab/vcs/svn.py
Original file line number Original file line Diff line number Diff line change
@@ -1,7 +1,6 @@

from __future__ import with_statement from __future__ import with_statement
from fabric.api import run, env from djangofab.api import *
from fabric.context_managers import cd
from djangofab.util import local as local


def update_remote(): def update_remote():
"Update remote checkout to the latest version" "Update remote checkout to the latest version"
Expand Down
13 changes: 3 additions & 10 deletions examples/fabfile-git.py
Original file line number Original file line Diff line number Diff line change
@@ -1,18 +1,11 @@
from __future__ import with_statement from djangofab.api import *
import sys
from fabric.api import *
from fabric.context_managers import *
from django.conf import settings from django.conf import settings
from djangofab.vcs.git import update_remote, update_local, push, commit, add from djangofab.vcs.git import update_remote, update_local, push, commit, add
from djangofab.decorator import user_settings
from djangofab.util import local as local, _apply_settings
from djangofab.django import get_remote_db, put_local_db, change_ownership, touch_wsgi
env.capture_default = False env.capture_default = False



# apply the settings from fab.cfg default section # apply the settings from fab.cfg default section
# sets the DJANGO_SETTINGS which allows access to settings values # sets DJANGO_SETTINGS which allows access to django.conf.settings values
_apply_settings() apply_settings()


#use the default section of fab.cfg #use the default section of fab.cfg
@user_settings() @user_settings()
Expand Down
8 changes: 1 addition & 7 deletions examples/fabfile-svn.py
Original file line number Original file line Diff line number Diff line change
@@ -1,11 +1,5 @@
from __future__ import with_statement from djangofab.api import *
from fabric.api import *
from fabric.context_managers import *
from django.conf import settings
from djangofab.vcs.svn import update_remote, update_local, commit, add from djangofab.vcs.svn import update_remote, update_local, commit, add
from djangofab.decorator import user_settings
from djangofab.util import local as local
from djangofab.django import get_remote_db, put_local_db, change_ownership, touch_wsgi
env.capture_default = False env.capture_default = False


#use the default section of fab.cfg #use the default section of fab.cfg
Expand Down

0 comments on commit dbe0740

Please sign in to comment.