1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
from django.core.management.base import BaseCommand, CommandError
from django.core.management.commands.runserver import BaseRunserverCommand
from django.core.handlers.wsgi import WSGIHandler
from django.core.servers.basehttp import WSGIRequestHandler, WSGIServer, AdminMediaHandler, WSGIServerException
import gtk
import gobject
import sys
import os
from insanityweb.runner import get_runner
from settings import DATA_PATH
class Command(BaseRunserverCommand):
args = ''
help = 'Start the Insanity integrated web + test runner'
def run(self, *args, **options):
os.chdir(DATA_PATH)
runner = get_runner()
try:
server = WSGIServer((self.addr, int(self.port)), WSGIRequestHandler)
except WSGIServerException, e:
sys.stderr.write("ERROR: " + str(e) + "\n")
runner.quit()
return
# validate models
sys.stdout.write("Validating models...\n")
self.validate(display_num_errors=True)
handler = AdminMediaHandler(WSGIHandler())
server.set_app(handler)
server.timeout = 0.1
orig_handle_timeout = server.handle_timeout
timeout_happened = [False]
def handle_timeout(*args, **kwargs):
orig_handle_timeout(*args, **kwargs)
timeout_happened[0] = True
server.handle_timeout = handle_timeout
def django_driver():
timeout_happened[0] = False
while not timeout_happened[0]:
try:
server.handle_request()
except KeyboardInterrupt:
sys.stdout.write("Stopping the server...\n")
runner.quit()
gtk.main_quit()
return False
except Exception, e:
sys.stderr.write("ERROR: " + str(e) + "\n")
return True
return True
gobject.idle_add(django_driver)
sys.stdout.write("Running the server...\n")
gtk.main()
|