def runWebServer(host, port, quiet): """ Install the logger and run the webserver """ # add a logger wrapper for bottle (in order to log its activity) # See http://stackoverflow.com/questions/31080214/python-bottle-always-logs-to-console-no-logging-to-file def log_to_logger(fn): """ Wrap a Bottle request so that a log line is emitted after it's handled.""" @wraps(fn) def _log_to_logger(*_args, **_kwargs): actual_response = fn(*_args, **_kwargs) weblogger.info('%s %s %s %s' % (request.remote_addr, request.method, request.url, response.status)) return actual_response return _log_to_logger # update the template paths so that in priority, # it first looks in <gameName>/server/templates/ and then in CGS/server/templates TEMPLATE_PATH.append('games/' + Game.getTheGameName() + '/server/templates/') TEMPLATE_PATH.reverse() # add the base url to all the templates Jinja2Template.defaults['base_url'] = 'http://%s:%s/' % (host, port) # add the game name to all the templates (for page title) Jinja2Template.defaults['GameName'] = Game.getTheGameName() # Start the web server install(log_to_logger) weblogger.message('Run the web server on port %d...', port) default_app( ).catchall = True # all the exceptions/errors are catched, and re-routed to error500 run(host=host, port=port, quiet=quiet, server='gevent', handler_class=WebSocketHandler)
def new_tournament(): """ Page to create a new tournament Build from HTMLFormDict class method of TournamentMode (build from all the tournament modes) """ return Tournament.HTMLFormDict(Game.getTheGameName())