def get_app(self): ctconfig.define_options() self.db = db2.Connection("cutthroat_test.db").db settings = dict(cookie_secret="I am a secret cookie.", ) return Application(routes=mod_routes.assemble_routes(), settings=settings, db_conn=self.db)
def get_app(self): ctconfig.define_options() self.db = db2.Connection("cutthroat_test.db").db settings = dict( cookie_secret="I am a secret cookie.", ) return Application( routes=mod_routes.assemble_routes(), settings=settings, db_conn=self.db )
def main(): """ - Get options from config file - Gather all routes - Create the server - Start the server """ global http_server print("Getting ready . . .") ctconfig.define_options() # Define options with defaults # Attempt to load config from config file try: tornado.options.parse_config_file(options.conf_file_path) except IOError as e: errmsg = ("{} doesn't exist or couldn't be opened. Using defaults." .format(options.conf_file_path)) logging.error(errmsg) routes = mod_routes.assemble_routes() settings = dict( template_path=os.path.join( os.path.dirname(__file__), "templates"), static_path=os.path.join(os.path.dirname(__file__), "static"), gzip=True, cookie_secret=options.cookie_secret if options.cookie_secret else uuid.uuid4().hex, login_url="/signin/signin" ) # If asked to write routes, do so if options.output_routes: with open("routes.json", "w+") as f: f.write( json.dumps( [(route, jsonpickle.encode(rh)) for route, rh in routes], indent=4 ) ) http_server = tornado.httpserver.HTTPServer( Application( routes=routes, settings=settings, db_conn=db.Connection(options.sqlite_db), ) ) http_server.listen(options.port) signal.signal(signal.SIGTERM, sig_handler) signal.signal(signal.SIGINT, sig_handler) # Add periodic callback to mark stale games every minute p = tornado.ioloop.PeriodicCallback( http_server.request_callback.db_conn.mark_stale_games, 60000) p.start() print("Welcome to cutthroat-server") tornado.ioloop.IOLoop.instance().start() logging.info("Exit...")
def main(): """ - Get options from config file - Gather all routes - Create the server - Start the server """ global http_server # NOTE: There should be NO logging done before options are loaded # as logging handlers are not yet created ctconfig.define_options() # Define options with defaults # Attempt to load config from config file try: tornado.options.parse_config_file(options.conf_file_path) except IOError as e: errmsg = ("{} doesn't exist or couldn't be opened. Using defaults." .format(options.conf_file_path)) logging.error(errmsg) logging.info("Getting any static dependencies . . .") deps = [ ("https://raw.github.com/daneden/animate.css/master/animate.min.css", "src/static/animate.css"), ("https://raw.githubusercontent.com/cowboy/jquery-throttle-debounce/v1.1/jquery.ba-throttle-debounce.min.js", "src/static/debounce.js") ] map(retrieve_static_dep, deps) routes = mod_routes.assemble_routes() settings = dict( template_path=os.path.join( os.path.dirname(__file__), "templates"), static_path=os.path.join(os.path.dirname(__file__), "static"), gzip=True, cookie_secret=options.cookie_secret if options.cookie_secret else uuid.uuid4().hex, login_url="/signin/signin" ) # If asked to write routes, do so if options.output_routes: with open("routes.json", "w+") as f: f.write( json.dumps( [(route, jsonpickle.encode(rh)) for route, rh in routes], indent=4 ) ) http_server = tornado.httpserver.HTTPServer( Application( routes=routes, settings=settings, db_conn=db2.Connection(options.sqlite_db).db, ) ) for port in options.ports: try: logging.debug("Attempting to bind on {}.".format(port)) http_server.listen(port) logging.info("Listening on {}.".format(port)) break except socket.error: logging.debug("Could not bind on {}.".format(port)) else: raise StandardError("Ran out of ports to try.") signal.signal(signal.SIGTERM, sig_handler) signal.signal(signal.SIGINT, sig_handler) tornado.ioloop.IOLoop.instance().start() logging.info("Exit...")