Permalink
Browse files

Added tornado as a module, and added an app to manage a 2 tornado

instances, 1 for django and another for static media
  • Loading branch information...
1 parent 2bfe828 commit cce9f43a78e47f59a4e7344c5946c3894784640d @rosarior committed Sep 27, 2010
No changes.
No changes.
@@ -0,0 +1,81 @@
+from django.core.management.base import BaseCommand, CommandError
+from optparse import make_option
+import os
+import sys
+
+class Command(BaseCommand):
+ option_list = BaseCommand.option_list + ()
+ help = "Starts a Tornado Web."
+ args = '[optional port number, or ipaddr:port]'
+
+ def handle(self, addrport='', *args, **options):
+ import django
+ from django.core.handlers.wsgi import WSGIHandler
+ from tornado import httpserver, wsgi, ioloop, web
+
+ sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
+ sys.stderr = os.fdopen(sys.stderr.fileno(), 'w', 0)
+
+ if args:
+ raise CommandError('Usage: runtornado %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)
+
+ quit_command = (sys.platform == 'win32') and 'CTRL-BREAK' or 'CONTROL-C'
+
+ def inner_run():
+ from django.conf import settings
+
+# class StaticHandler(web.RequestHandler):
+# def get(self):
+# self.write("Hello, world")
+
+ #static_settings = {
+ # "static_path":settings.MEDIA_ROOT,
+ # "cookie_secret": "61oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=",
+ # "login_url": "/login",
+ # "xsrf_cookies": True,
+ #}
+ #application = tornado.web.Application([
+ # (r"/", MainHandler),
+ # (r"/login", LoginHandler),
+ #], **settings)
+
+ #http_server.static_path=settings.MEDIA_ROOT
+
+
+ print "Validating models..."
+ self.validate(display_num_errors=True)
+ print "\nDjango version %s, using settings %r" % (django.get_version(), settings.SETTINGS_MODULE)
+ print "Server is running at http://%s:%s/" % (addr, port)
+ print "Quit the server with %s." % quit_command
+ django_application = WSGIHandler()
+ django_container = wsgi.WSGIContainer(django_application)
+ django_server = httpserver.HTTPServer(django_container)
+ django_server.listen(int(port), address=addr)
+
+ if 1:
+ static_address=addr
+ static_port=int(port)+1
+ settings.SERVE_STATIC_CONTENT=False
+ settings.MEDIA_URL = 'http://%s:%s/static/' % (static_address, static_port)
+ settings.ADMIN_MEDIA_PREFIX = settings.MEDIA_URL + 'admin_media/'
+ static_application = web.Application([], static_path=settings.MEDIA_ROOT)
+ static_server = httpserver.HTTPServer(static_application)
+ static_server.listen(static_port, address=addr)
+
+ ioloop.IOLoop.instance().start()
+
+ inner_run()
+
@@ -0,0 +1,20 @@
+#!/usr/bin/env python
+#
+# Copyright 2009 Facebook
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+"""The Tornado web server and tools."""
+
+version = "1.1"
+version_info = (1, 1, 0)
Oops, something went wrong.

0 comments on commit cce9f43

Please sign in to comment.