Skip to content

Instantly share code, notes, and snippets.

@zvoase
Forked from anonymous/__init__.py
Created February 13, 2009 18:40
Show Gist options
  • Save zvoase/64043 to your computer and use it in GitHub Desktop.
Save zvoase/64043 to your computer and use it in GitHub Desktop.
import os
def import_all_from(module_name, globals_):
# Calling it with the globals_ module provides a hook into the
# module-level globals; otherwise we'd get the function's globals
# (which might be different).
module_split = module_name.split('.')
while '__init__' in module_split:
module_split.remove('__init__')
while '__main__' in module_split:
module_split.remove('__main__')
module = __import__('.'.join(module_split), fromlist=module_split[:-1])
for attr in dir(module):
if not (attr.startswith('__') and attr.endswith('__')):
globals_[attr] = getattr(module, attr)
SETTINGS_MODE = os.environ.get('DJANGO_SETTINGS_MODE', None)
import_all_from(__name__ + '.common', globals())
try:
import_all_from(__name__ + '.modes', globals())
except ImportError:
pass
if 'SETTINGS_MODES' in dir():
for mode in SETTINGS_MODES:
import_all_from(__name__ + '.' + mode.lower(), globals())
elif SETTINGS_MODE:
import_all_from(__name__ + '.' + SETTINGS_MODE.lower(), globals())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment