Merge pull request #577 from rolandgeider/issue-592

Restart tornado on file changes, respect port and adress flags
This commit is contained in:
Oskar Hahn 2013-04-04 07:14:37 -07:00
commit dc65f5e349
2 changed files with 18 additions and 17 deletions

View File

@ -183,15 +183,15 @@ def _main(opts, database_path=None):
create_or_reset_admin_user()
# Start OpenSlides
reload = True
if opts.no_reload:
extra_args = ['--noreload']
else:
extra_args = []
reload = False
if opts.start_browser:
start_browser(url)
start_openslides(addr, port, extra_args=extra_args)
# Start the server
run_tornado(addr, port, reload)
def create_settings(settings_path, database_path=None):
@ -309,15 +309,6 @@ def create_or_reset_admin_user():
admin.save()
def start_openslides(addr, port, start_browser_url=None, extra_args=[]):
# Open the browser
if start_browser_url:
start_browser(start_browser_url)
# Start the server
run_tornado(addr, port)
def start_browser(url):
browser = webbrowser.get()

View File

@ -8,6 +8,7 @@
:license: GNU GPL, see LICENSE for more details.
"""
import sys
import posixpath
from urllib import unquote
@ -15,7 +16,7 @@ from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
from tornado.web import FallbackHandler, Application, StaticFileHandler
from tornado.wsgi import WSGIContainer
from tornado.options import options, define, parse_command_line
from tornado.options import options, parse_command_line
from django.core.handlers.wsgi import WSGIHandler as Django_WSGIHandler
from django.conf import settings
@ -36,13 +37,22 @@ class DjangoStaticFileHandler(StaticFileHandler):
return super(DjangoStaticFileHandler, self).get(absolute_path, include_body)
def run_tornado(addr, port):
parse_command_line()
def run_tornado(addr, port, reload=False):
# We need to add the no-browser option to argv, otherwise with each reload
# a new browser will be opened (tornado simply re-executes Python using
# sys.executable and sys.argv)
if '--no-browser' not in sys.argv:
sys.argv.append('--no-browser')
# Don't try to read the command line args from openslides
parse_command_line(args=[])
# Start the application
app = WSGIContainer(Django_WSGIHandler())
tornado_app = Application([
(r"%s(.*)" % settings.STATIC_URL, DjangoStaticFileHandler),
(r'%s(.*)' % settings.MEDIA_URL, StaticFileHandler, {'path': settings.MEDIA_ROOT}),
('.*', FallbackHandler, dict(fallback=app))])
('.*', FallbackHandler, dict(fallback=app))], debug=reload)
server = HTTPServer(tornado_app)
server.listen(port=port,