def djangoVsWsgi(options): # settings logic if not options['wsgi']: settings_mod = findSettingsModule() user_settings = options['settings'] if not settings_mod and not user_settings: msg = ( '\nEither specify:\n--settings mysettings.dot.path\nOR\n' 'export DJANGO_SETTINGS_MODULE="mysettings.dot.path"\nOR\n' 'in your manage.py file specify ' 'os.environ.setdefault("DJANGO_SETTINGS_MODULE", ' '"mysettings.dot.path")' ) raise SettingsError(chalk.format_red(msg), None, sys.exc_info()[2]) elif user_settings: # if the user specified the settings to use then these take # precedence options['settings'] = user_settings elif settings_mod: options['settings'] = settings_mod else: try: base.HendrixDeploy.importWSGI(options['wsgi']) except ImportError: raise ImportError("The path '%s' does not exist" % options['wsgi']) return options
def findSettingsModule(): "Find the settings module dot path within django's mnanage.py file" try: with open('manage.py', 'r') as manage: manage_contents = manage.read() search = re.search(r"([\"\'](?P<module>[a-z\.]+)[\"\'])", manage_contents) if search: # django version < 1.7 settings_mod = search.group("module") else: # in 1.7, manage.py settings declaration looks like: # os.environ.setdefault( # "DJANGO_SETTINGS_MODULE", "example_app.settings" # ) search = re.search("\".*?\"(,\\s)??\"(?P<module>.*?)\"\\)$", manage_contents, re.I | re.S | re.M) settings_mod = search.group("module") os.environ.setdefault('DJANGO_SETTINGS_MODULE', settings_mod) except IOError, e: msg = (str(e) + '\nPlease ensure that you are in the same directory ' 'as django\'s "manage.py" file.') raise IOError(chalk.format_red(msg)), None, sys.exc_info()[2]
def findSettingsModule(): "Find the settings module dot path within django's manage.py file" try: with open('manage.py', 'r') as manage: manage_contents = manage.read() search = re.search( r"([\"\'](?P<module>[a-z\.]+)[\"\'])", manage_contents ) if search: # django version < 1.7 settings_mod = search.group("module") else: # in 1.7, manage.py settings declaration looks like: # os.environ.setdefault( # "DJANGO_SETTINGS_MODULE", "example_app.settings" # ) search = re.search( "\".*?\"(,\\s)??\"(?P<module>.*?)\"\\)$", manage_contents, re.I | re.S | re.M ) settings_mod = search.group("module") os.environ.setdefault('DJANGO_SETTINGS_MODULE', settings_mod) except IOError as e: msg = ( str(e) + '\nPlease ensure that you are in the same directory ' 'as django\'s "manage.py" file.' ) raise IOError(chalk.format_red(msg), None, sys.exc_info()[2]) except AttributeError: settings_mod = '' return settings_mod
def djangoVsWsgi(options): # settings logic if not options['wsgi']: settings_mod = findSettingsModule() user_settings = options['settings'] if not settings_mod and not user_settings: msg = ('\nEither specify:\n--settings mysettings.dot.path\nOR\n' 'export DJANGO_SETTINGS_MODULE="mysettings.dot.path"\nOR\n' 'in your manage.py file specify ' 'os.environ.setdefault("DJANGO_SETTINGS_MODULE", ' '"mysettings.dot.path")') raise SettingsError(chalk.format_red(msg)), None, sys.exc_info()[2] elif user_settings: # if the user specified the settings to use then these take # precedence options['settings'] = user_settings elif settings_mod: options['settings'] = settings_mod else: try: base.HendrixDeploy.importWSGI(options['wsgi']) except ImportError: raise ImportError("The path '%s' does not exist" % options['wsgi']) return options
def findSettingsModule(): "Find the settings module dot path within django's mnanage.py file" try: with open("manage.py", "r") as manage: manage_contents = manage.read() search = re.search(r"([\"\'](?P<module>[a-z\.]+)[\"\'])", manage_contents) if search: # django version < 1.7 settings_mod = search.group("module") else: # in 1.7, manage.py settings declaration looks like: # os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example_app.settings") search = re.search('".*?"(,\\s)??"(?P<module>.*?)"\\)$', manage_contents, re.I | re.S | re.M) settings_mod = search.group("module") os.environ.setdefault("DJANGO_SETTINGS_MODULE", settings_mod) except IOError, e: msg = str(e) + "\nPlease ensure that you are in the same directory " 'as django\'s "manage.py" file.' raise IOError(chalk.format_red(msg)), None, sys.exc_info()[2]
def djangoVsWsgi(options): # settings logic if not options["wsgi"]: settings_mod = findSettingsModule() user_settings = options["settings"] if not settings_mod and not user_settings: msg = ( "\nEither specify:\n--settings mysettings.dot.path\nOR\n" 'export DJANGO_SETTINGS_MODULE="mysettings.dot.path"\nOR\n' "in your manage.py file specify " 'os.environ.setdefault("DJANGO_SETTINGS_MODULE", ' '"mysettings.dot.path")' ) raise SettingsError(chalk.format_red(msg)), None, sys.exc_info()[2] elif user_settings: # if the user specified the settings to use then these take # precedence options["settings"] = user_settings elif settings_mod: options["settings"] = settings_mod return options
def djangoVsWsgi(options): # settings logic if not options['wsgi']: user_settings = options['settings'] settings_module = os.environ.get('DJANGO_SETTINGS_MODULE') if not settings_module and not user_settings: msg = ( '\nEither specify:\n--settings mysettings.dot.path\nOR\n' 'export DJANGO_SETTINGS_MODULE="mysettings.dot.path"' ) raise SettingsError(chalk.format_red(msg)), None, sys.exc_info()[2] elif user_settings: options['settings'] = user_settings elif settings_module: options['settings'] = settings_module else: try: HendrixDeploy.importWSGI(options['wsgi']) except ImportError: raise ImportError("The path '%s' does not exist" % options['wsgi']) return options
def formatException(self, ei): exception = super(ChalkFormatter, self).formatException(ei) return chalk.format_red(exception)