Beispiel #1
0
def init_run_server(ProjectModule):
    print "Starting Mojo tornado server."
    pm_path = os.path.dirname(ProjectModule.__file__) + '/'
    settings_path = pm_path + 'settings.py'
    sys.path.append(pm_path)
    sys.path.append(settings_path)

    module_name = get_module_name(os.path.dirname(ProjectModule.__file__))

    project_details_import_string = 'import settings as project_settings'  #% (module_name)
    exec(project_details_import_string)
    logging.basicConfig(level=log_level[project_settings.LOG_LEVEL.upper()])

    logging.debug('Setting up url routers:')
    routes = []
    for appName in project_settings.INSTALLED_APPS:
        urls_string = 'import Apps.%s.urls as urls' % (appName)
        exec(urls_string)
        routes.extend(urls.urlpatterns)
        logging.debug("--Added URL's for: %s" % (appName))

    loaded_ui_modules_list = []
    for appName in project_settings.INSTALLED_APPS:
        logging.debug("--Adding UI Modules for %s" % appName)
        ui_module_string = 'from Apps.%s import ui_modules' % (appName)
        exec(ui_module_string)

        #TODO: This won't work with multiple apps, as it is only imported once!!
        loaded_ui_modules_list.append(ui_modules)

    thisSocketRouter = setup_socket_handler_routers(
        module_name, project_settings.INSTALLED_APPS)

    db_session = None
    if project_settings.DATABASE:
        Session = None
        logging.debug('Found DATABASE setting - creating session for DB: %s' %
                      project_settings.DATABASE['name'])
        backend_import_str = 'from %s import Session, Collection' % (
            project_settings.DATABASE['backend'])
        exec(backend_import_str)

        global DATABASE
        DATABASE = Session(host=project_settings.DATABASE['host'],
                           port=project_settings.DATABASE['port'],
                           db_name=project_settings.DATABASE['name'])
        global BACKEND_COLLECTION
        BACKEND_COLLECTION = Collection

    application = DynaMojoTornadoApplication(project_settings,
                                             thisSocketRouter, routes,
                                             loaded_ui_modules_list,
                                             db_session)

    application.listen(project_settings.LISTEN_PORT)
    tornadio2.SocketServer(application)
Beispiel #2
0
def serve():
    """
    Run the NICE repeater, forwarding subscription streams to the web.
    """

    # Define the interface to the internal and external servers
    nice_router = MyRouter(NiceConnection, handler=BaseHandler)
    control_router = MyRouter(ControlConnection, handler=BaseHandler)
    web_router = MyRouter(WebConnection, handler=BaseHandler)
    web_routes = [
        (r"/", IndexHandler),
        # TODO: the following pattern is too generic it matches most /x/y/z
        # it only works because '.' is excluded from the matched patterns.
        (r"/(?P<instrument>[a-zA-Z0-9_]*)/(?P<channel>[a-z_]*)/(?P<resource>[a-z_]*)",
         RestHandler),
    ]

    # Point the servers to internal and external ports
    subscriber_app = web.Application(web_router.apply_routes(web_routes),
                                     socket_io_port=SUBSCRIBER_PORT,
                                     debug=DEBUG,
                                     **WEB_SETTINGS)
    controller_app = web.Application(control_router.apply_routes([]),
                                     socket_io_port=CONTROLLER_PORT,
                                     debug=DEBUG,
                                     **NICE_SETTINGS)
    publisher_app = web.Application(nice_router.apply_routes([]),
                                    socket_io_port=PUBLISHER_PORT,
                                    debug=DEBUG,
                                    **NICE_SETTINGS)

    # Server application
    loop = ioloop.IOLoop.instance()
    sio.SocketServer(subscriber_app, auto_start=False, io_loop=loop)
    sio.SocketServer(controller_app, auto_start=False, io_loop=loop)
    sio.SocketServer(publisher_app, auto_start=False, io_loop=loop)

    logging.info('Entering IOLoop...')
    loop.start()
Beispiel #3
0
	configuration.shutdown_managed_redis(redis_shutdown, redis_shutdown)

def redis_shutdown(message, exception=None):
	logger.info(message)
	if exception:
		logger.error("Exception:", exc_info=exception)

	on_actual_exit()

def on_actual_exit():
	# And really, really exit.
	logging.info("Exiting.")
	if os.path.exists(pid_path):
		os.unlink(pid_path)
	else:
		logging.error("No PID file exists, but exiting anyway.")
	sys.exit(0)

# Commence the application.
if __name__ == "__main__":
	# Add a callback to get started once the IO loop is up and running.
	tornado.ioloop.IOLoop.instance().add_callback(on_ioloop_started)

	# Start up the IO loop.
	with safeclose.section(on_exit_request):
		# This is the socket.io launcher, which routes between
		# socket.io requests and normal HTTP requests. It also
		# starts the IO loop for us.
		tornadio2.SocketServer(application)
Beispiel #4
0
    coffee2js('media/coffee/', 'media/js/')
    haml2html('haml/', 'templates/')
    sass2css('media/sass/', 'media/css/')
    application = tornado.web.Application(
        router.apply_routes([
            (r"/", IndexHandler),
            (r'/login/', VKHandler),
            (r'/logout/', LogoutHandler),
        ]),
        debug=getattr(settings, 'DEBUG', True),
        socket_io_port=getattr(settings, 'PORT', 8080),
        flash_policy_port=843,
        flash_policy_file=os.path.join(current, 'flashpolicy.xml'),
        db_host=getattr(settings, 'DB_HOST', 'localhost'),
        db_port=getattr(settings, 'DB_PORT', 27017),
        db_name=getattr(settings, 'DB_NAME', 'uglyweb'),
        static_path='media/',
        static_url_prefix='/media/',
        client_id=settings.VK_ID,
        vk_redirect=getattr(settings, 'VK_REDIRECT',
                            'http://127.0.0.1:8080/login/'),
        client_secret=settings.VK_SECRET,
        cookie_secret=getattr(settings, 'SECRET', 'IwannaUSElocalhost'),
    )
    BaseConnection.application = application
    application.pika = pc
    socket_server = tornadio2.SocketServer(application, auto_start=False)
    ioloop = tornado.ioloop.IOLoop.instance()
    ioloop.add_timeout(time.time() + 0.1, application.pika.connect)
    ioloop.start()
Beispiel #5
0
def launch_chatserver(bot, port=8888):
    ChatConnection.bot = bot
    chat_router = tornadio2.TornadioRouter(ChatConnection)
    application = tornado.web.Application(chat_router.urls,
                                          socket_io_port=port)
    return tornadio2.SocketServer(application, auto_start=False)