public
Created

Bootstrap code for a fabfile module that automatically loads all .py files and makes all pre-loaded libraries available to them

  • Download Gist
__init__.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
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)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.