Exemple #1
0
def manage(*args):
    settings = utils.get_settings(
        apps=('django_extensions',),
        DEBUG_PROPAGATE_EXCEPTIONS=False)
    del settings.DEBUG
    from django.core import management
    if utils.get_version() < (1, 4):
        # django < 1.6
        def run(argv=None):
            return management.execute_manager(settings)
        management.setup_environ = lambda *args: os.getcwd
    else:
        def run(argv=None):
            return management.execute_from_command_line(argv=argv)
    if utils.get_version() < (1, 7):
        from django.conf import settings as sets  # NOQA
    args = args or sys.argv[1:]

    if not args:
        return sys.exit(run())

    cmd = args[0]
    config = ConfigParser()
    config.read(os.path.expanduser('~/.djangodevkitrc'))
    try:
        alias = config.get('aliases', cmd)
    except:
        cmds = [args]
    else:
        sargs = ' '.join(args[1:])
        cmds = [a.replace('[]', sargs) for a in alias.split('\n') if a.strip()]
        cmds = [a.split() for a in cmds]
    for cmd in cmds:
        sys.argv[1:] = cmd
        run(argv=sys.argv)
Exemple #2
0
def make_app(global_conf, **local_conf):

    conf = local_conf.copy()
    conf.update(global_conf)

    if 'request' in sys.argv or 'post' in sys.argv:
        conf['no_error'] = True

    apps = middlewares =()
    if conf.get('toolbar', False):
        apps = ('debug_toolbar',)
        middlewares = ('debug_toolbar.middleware.DebugToolbarMiddleware',)

    mod_name = conf.get('settings', os.environ.get('DJANGO_SETTINGS_MODULE', 'settings'))
    os.environ['DJANGO_SETTINGS_MODULE'] = mod_name
    if 'django_settings_module' not in global_conf:
        global_conf['django_settings_module'] = mod_name
    if 'debug' not in global_conf:
        global_conf['debug'] = 'true'

    settings = utils.get_settings(apps=apps, middlewares=middlewares)

    django_app = django.core.handlers.wsgi.WSGIHandler()
    def app(environ, start_response):
        if 'request' in sys.argv or 'post' in sys.argv:
            req = Request(environ)
            try:
                resp = req.get_response(django_app)
            except Exception, e:
                resp = Response(content_type='text/plain')
                traceback.print_exc(file=resp.body_file)
            return resp(environ, start_response)
        return django_app(environ, start_response)
Exemple #3
0
def manage(*args):
    settings = utils.get_settings(apps=('django_extensions',))
    del settings.DEBUG
    config = utils.get_config_file()
    app = loadapp('config:%s' % config) # NOQA
    from django.core import management
    management.setup_environ = lambda *args: os.getcwd
    loadapp('config:%s' % config)
    from django.conf import settings as sets # NOQA
    args = args or sys.argv[1:]

    if not args:
        return sys.exit(management.execute_manager(settings))

    cmd = args[0]
    config = ConfigParser()
    config.read(os.path.expanduser('~/.djangodevkitrc'))
    try:
        alias = config.get('aliases', cmd)
    except:
        cmds = [args]
    else:
        sargs = ' '.join(args[1:])
        cmds = [a.replace('[]', sargs) for a in alias.split('\n') if a.strip()]
        cmds = [a.split() for a in cmds]
    for cmd in cmds:
        sys.argv[1:] = cmd
        management.execute_manager(settings)
Exemple #4
0
def manage(*args):
    settings = utils.get_settings(apps=('django_extensions',))
    del settings.DEBUG
    config = utils.get_config_file()
    app = loadapp('config:%s' % config)
    from django.core import management
    management.setup_environ = lambda *args: os.getcwd
    loadapp('config:%s' % config)
    from django.core.management import execute_manager
    from django.conf import settings as sets
    sys.argv[1:1] = args
    management.execute_manager(settings)
Exemple #5
0
def make_app(global_conf, **local_conf):

    conf = local_conf.copy()
    conf.update(global_conf)

    if 'request' in sys.argv or 'post' in sys.argv:
        conf['no_error'] = True

    apps = middlewares = ()
    if conf.get('toolbar', False):
        apps = ('debug_toolbar', )
        middlewares = ('debug_toolbar.middleware.DebugToolbarMiddleware', )

    mod_name = conf.get('settings',
                        os.environ.get('DJANGO_SETTINGS_MODULE', 'settings'))
    os.environ['DJANGO_SETTINGS_MODULE'] = mod_name
    if 'django_settings_module' not in global_conf:
        global_conf['django_settings_module'] = mod_name
    if 'debug' not in global_conf:
        global_conf['debug'] = 'true'

    settings = utils.get_settings(apps=apps, middlewares=middlewares)

    try:
        from django.core.wsgi import get_wsgi_application
    except ImportError:
        import django.core.handlers.wsgi
        app = django.core.handlers.wsgi.WSGIHandler()
    else:
        app = get_wsgi_application()

    if 'no_media' not in conf:
        app = Cascade(app, MediaMap(settings))
    else:
        app = Cascade(app, None)
    if 'no_error' not in conf:
        app = backlash.DebuggedApplication(app)
    return app
Exemple #6
0
def make_app(global_conf, **local_conf):

    conf = local_conf.copy()
    conf.update(global_conf)

    if 'request' in sys.argv or 'post' in sys.argv:
        conf['no_error'] = True

    apps = middlewares = ()
    if conf.get('toolbar', False):
        apps = ('debug_toolbar',)
        middlewares = ('debug_toolbar.middleware.DebugToolbarMiddleware',)

    mod_name = conf.get('settings',
                        os.environ.get('DJANGO_SETTINGS_MODULE', 'settings'))
    os.environ['DJANGO_SETTINGS_MODULE'] = mod_name
    if 'django_settings_module' not in global_conf:
        global_conf['django_settings_module'] = mod_name
    if 'debug' not in global_conf:
        global_conf['debug'] = 'true'

    settings = utils.get_settings(apps=apps, middlewares=middlewares)

    try:
        from django.core.wsgi import get_wsgi_application
    except ImportError:
        import django.core.handlers.wsgi
        app = django.core.handlers.wsgi.WSGIHandler()
    else:
        app = get_wsgi_application()

    if 'no_media' not in conf:
        app = Cascade(app, MediaMap(settings))
    else:
        app = Cascade(app, None)
    if 'no_error' not in conf:
        app = backlash.DebuggedApplication(app)
    return app
Exemple #7
0
def manage(*args):
    settings = utils.get_settings(apps=('django_extensions', ),
                                  DEBUG_PROPAGATE_EXCEPTIONS=False)
    del settings.DEBUG
    from django.core import management
    if utils.get_version() < (1, 4):
        # django < 1.6
        def run(argv=None):
            return management.execute_manager(settings)

        management.setup_environ = lambda *args: os.getcwd
    else:

        def run(argv=None):
            return management.execute_from_command_line(argv=argv)

    if utils.get_version() < (1, 7):
        from django.conf import settings as sets  # NOQA
    args = args or sys.argv[1:]

    if not args:
        return sys.exit(run())

    cmd = args[0]
    config = ConfigParser()
    config.read(os.path.expanduser('~/.djangodevkitrc'))
    try:
        alias = config.get('aliases', cmd)
    except:
        cmds = [args]
    else:
        sargs = ' '.join(args[1:])
        cmds = [a.replace('[]', sargs) for a in alias.split('\n') if a.strip()]
        cmds = [a.split() for a in cmds]
    for cmd in cmds:
        sys.argv[1:] = cmd
        run(argv=sys.argv)