Created
November 30, 2010 17:50
-
-
Save galvez/722059 to your computer and use it in GitHub Desktop.
Bootstrap code for a fabfile module that automatically loads all .py files and makes all pre-loaded libraries available to them
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import with_statement | |
from fabric.api import * | |
from code import interact | |
import os | |
import sys | |
import time | |
APP_ROOT = os.path.abspath(os.path.dirname(__file__)) | |
sys.path += [APP_ROOT, os.path.join(APP_ROOT, 'lib')] | |
from support import ( | |
config, | |
get_db_handler, | |
sqlwitch, | |
sha1, | |
re, | |
simplejson, | |
jshash | |
) | |
def do(): | |
interact(local=locals()) | |
def shell(init_globals=None): | |
if init_globals is None: | |
init_globals = globals() | |
interact(local=init_globals) | |
import glob | |
import types | |
pre_globals = dict([(key, value) for key, value in globals().items()]) | |
for fabfile in [py for py in glob.glob('fabfile/*.py') if not py.endswith('__init__.py')]: | |
module_name = os.path.splitext(os.path.split(fabfile)[1])[0] | |
module = __import__(module_name, globals(), locals(), ['*'], -1) | |
for key in pre_globals.keys(): | |
setattr(module, key, pre_globals[key]) | |
for key in dir(module): | |
if not re.match('^__.+__$', key): | |
globals()[key] = getattr(module, key) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment