Ejemplo n.º 1
0
    def handle(self, addrport='', *args, **options):
        if args:
            raise CommandError('Usage is runserver %s' % self.args)
        if not addrport:
            addr = ''
            port = '8000'
        else:
            try:
                addr, port = addrport.split(':')
            except ValueError:
                addr, port = '', addrport
        if not addr:
            addr = '127.0.0.1'
 
        if not port.isdigit():
            raise CommandError("%r is not a valid port number." % port)
 
        admin_media_path = options.get('admin_media_path', '')
        workers = int(options.get('workers', '1'))
        daemon = options.get('daemon')
        quit_command = (sys.platform == 'win32') and 'CTRL-BREAK' or 'CONTROL-C'
        pidfile = options.get('pidfile') or None
 
        print "Validating models..."
        self.validate(display_num_errors=True)
        print "\nDjango version %s, using settings %r" % (django.get_version(), settings.SETTINGS_MODULE)
        print "Development server is running at http://%s:%s/" % (addr, port)
        print "Quit the server with %s." % quit_command
 
        # django.core.management.base forces the locale to en-us.
        translation.activate(settings.LANGUAGE_CODE)
 
        try:
            handler = AdminMediaHandler(WSGIHandler(), admin_media_path)
            arbiter = Arbiter((addr, int(port)), workers, handler,
                pidfile=pidfile)
            if daemon:
                daemonize()
            arbiter.run()
        except WSGIServerException, e:
            # Use helpful error messages instead of ugly tracebacks.
            ERRORS = {
                13: "You don't have permission to access that port.",
                98: "That port is already in use.",
                99: "That IP address can't be assigned-to.",
            }
            try:
                error_text = ERRORS[e.args[0].args[0]]
            except (AttributeError, KeyError):
                error_text = str(e)
            sys.stderr.write(self.style.ERROR("Error: %s" % error_text) + '\n')
            sys.exit(1)
Ejemplo n.º 2
0
    def handle(self, addrport='', *args, **options):
        if args:
            raise CommandError('Usage is runserver %s' % self.args)
            
        options['bind'] = addrport or '127.0.0.1'
        
        options['default_proc_name'] =settings.SETTINGS_MODULE
        conf = Config(options, options.get('gconfig'))

        admin_media_path = options.get('admin_media_path', '')
        quit_command = (sys.platform == 'win32') and 'CTRL-BREAK' or 'CONTROL-C'

        print "Validating models..."
        self.validate(display_num_errors=True)
        print "\nDjango version %s, using settings %r" % (django.get_version(), 
                                            settings.SETTINGS_MODULE)
        print "Development server is running at %s" % str(conf.address)
        print "Quit the server with %s." % quit_command
 
        # django.core.management.base forces the locale to en-us.
        translation.activate(settings.LANGUAGE_CODE)
        
        try:
            handler = AdminMediaHandler(WSGIHandler(), admin_media_path)
            arbiter = Arbiter(conf.address, conf.workers, handler,
                pidfile=conf['pidfile'], config=conf)
            if conf['daemon']:
                daemonize()
            else:
                os.setpgrp()
            configure_logging(conf)
            arbiter.run()
        except WSGIServerException, e:
            # Use helpful error messages instead of ugly tracebacks.
            ERRORS = {
                13: "You don't have permission to access that port.",
                98: "That port is already in use.",
                99: "That IP address can't be assigned-to.",
            }
            try:
                error_text = ERRORS[e.args[0].args[0]]
            except (AttributeError, KeyError):
                error_text = str(e)
            sys.stderr.write(self.style.ERROR("Error: %s" % error_text) + '\n')
            sys.exit(1)