コード例 #1
0
ファイル: serve.py プロジェクト: bearstech/DjangoDevKit
def main(*args, **kwargs):
    args = sys.argv
    config = None
    conf = {}

    config = utils.get_config_file()
    parser = OptionParser()
    parser.add_option("-t", "--debug-toolbar", dest="toolbar",
                      action="store_true", default=False)
    parser.add_option("-i", "--non-interactive", dest="interactive",
                      action="store_true", default=False)
    parser.add_option("-m", "--no-media", dest="no_media",
                      action="store_true", default=False)
    parser.add_option("--host", dest="host",
                      action="store", default="0.0.0.0")
    parser.add_option("-p", "--port", dest="port",
                      action="store", default="8000")
    parser.add_option("--threads", dest="threads",
                      action="store", default="2")
    options, args = parser.parse_args()

    if options.toolbar:
        conf['toolbar'] = True

    if options.interactive:
        conf['no_error'] = True

    if options.no_media:
        conf['no_media'] = True

    if config is None:
        config = utils.get_config_file()

    if 'request' in args:
        app = make_app({}, no_error=True)
        req = webob.Request.blank(args[1])
        try:
            resp = req.get_response(app)
        except:
            raise
        else:
            if resp.charset:
                body = resp.text
            else:
                body = resp.body
            if not isinstance(body, str):
                body = body.decode('utf8')
            print(body)
    else:
        config = utils.get_config_file()
        app = make_app(conf)
        from django.utils import autoreload
        autoreload.main(serve, (app,), {
            'expose_tracebacks': True,
            'host': options.host,
            'port': options.port,
            'threads': options.threads,
        })
        return
コード例 #2
0
ファイル: scripts.py プロジェクト: pombredanne/DjangoDevKit
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)
コード例 #3
0
ファイル: scripts.py プロジェクト: cyberj/DjangoDevKit
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)
コード例 #4
0
ファイル: serve.py プロジェクト: cyberj/DjangoDevKit
def main(*args, **kwargs):
    args = sys.argv

    if 'help' in args:
        pass
    elif 'request' in args:
        config = utils.get_config_file()
        sys.argv[2:2] = [config]
    elif 'post' in args:
        config = utils.get_config_file()
        sys.argv[2:2] = [config]
    elif 'serve' not in args:
        config = utils.get_config_file()
        parser = OptionParser()
        parser.add_option("-t", "--debug-toolbar", dest="toolbar",
                          action="store_true", default=False)
        parser.add_option("-i", "--non-interactive", dest="interactive",
                          action="store_true", default=False)
        parser.add_option("-m", "--no-media", dest="no_media",
                          action="store_true", default=False)
        options, args = parser.parse_args()

        if options.toolbar:
            print 'Including django-debug-toolbar'
            sys.argv.append('toolbar=true')

        if options.interactive:
            sys.argv.append('no_error=true')
        else:
            print 'Including WebError middleware'

        if options.no_media:
            print 'Do not serve media files'
            sys.argv.append('no_media=true')

        sys.argv = [a for a in sys.argv if a not in ('-t', '-i', '-m')]
        sys.argv[1:1] = ['serve', '--reload', config]
    paste.script.command.run()
コード例 #5
0
def main(*args, **kwargs):
    args = sys.argv
    config = None
    conf = {}

    config = utils.get_config_file()
    parser = OptionParser()
    parser.add_option("-t",
                      "--debug-toolbar",
                      dest="toolbar",
                      action="store_true",
                      default=False)
    parser.add_option("-i",
                      "--non-interactive",
                      dest="interactive",
                      action="store_true",
                      default=False)
    parser.add_option("-m",
                      "--no-media",
                      dest="no_media",
                      action="store_true",
                      default=False)
    parser.add_option("--host", dest="host", action="store", default="0.0.0.0")
    parser.add_option("-p",
                      "--port",
                      dest="port",
                      action="store",
                      default="8000")
    parser.add_option("--threads", dest="threads", action="store", default="2")
    options, args = parser.parse_args()

    if options.toolbar:
        conf['toolbar'] = True

    if options.interactive:
        conf['no_error'] = True

    if options.no_media:
        conf['no_media'] = True

    if config is None:
        config = utils.get_config_file()

    if 'request' in args:
        app = make_app({}, no_error=True)
        req = webob.Request.blank(args[1])
        try:
            resp = req.get_response(app)
        except:
            raise
        else:
            if resp.charset:
                body = resp.text
            else:
                body = resp.body
            if not isinstance(body, str):
                body = body.decode('utf8')
            print(body)
    else:
        config = utils.get_config_file()
        app = make_app(conf)
        from django.utils import autoreload
        autoreload.main(
            serve, (app, ), {
                'expose_tracebacks': True,
                'host': options.host,
                'port': options.port,
                'threads': options.threads,
            })
        return