def __init__(self, shard=0): signal.signal(signal.SIGINT, lambda unused_x, unused_y: self.exit()) self.name = self.__class__.__name__ self.shard = shard self._my_coord = ServiceCoord(self.name, self.shard) # Dictionaries of (to be) connected RemoteServiceClients. self.remote_services = {} self.initialize_logging() # We setup the listening address for services which want to # connect with us. try: address = get_service_address(self._my_coord) except KeyError: raise ConfigError("Unable to find address for service %r. " "Is it specified in core_services in cms.conf?" % (self._my_coord, )) self.rpc_server = StreamServer(address, self._connection_handler) self.backdoor = None
def __init__(self, shard, contest_id=None): parameters = { "template_path": pkg_resources.resource_filename("cms.server.contest", "templates"), "static_files": [("cms.server", "static"), ("cms.server.contest", "static")], "cookie_secret": base64.b64encode(config.secret_key), "debug": config.tornado_debug, "is_proxy_used": config.is_proxy_used, "num_proxies_used": config.num_proxies_used, "xsrf_cookies": True, } try: listen_address = config.contest_listen_address[shard] listen_port = config.contest_listen_port[shard] except IndexError: raise ConfigError("Wrong shard number for %s, or missing " "address/port configuration. Please check " "contest_listen_address and contest_listen_port " "in cms.conf." % __name__) self.contest_id = contest_id if self.contest_id is None: HANDLERS.append((r"", MainHandler)) handlers = [(r'/', BaseHandler)] for h in HANDLERS: handlers.append((r'/([^/]+)' + h[0], ) + h[1:]) else: HANDLERS.append((r"/", MainHandler)) handlers = HANDLERS super(ContestWebServer, self).__init__(listen_port, handlers, parameters, shard=shard, listen_address=listen_address) # This is a dictionary (indexed by username) of pending # notification. Things like "Yay, your submission went # through.", not things like "Your question has been replied", # that are handled by the db. Each username points to a list # of tuples (timestamp, subject, text). self.notifications = {} # Retrieve the available translations. self.langs = { lang_code: wrap_translations_for_tornado(trans) for lang_code, trans in get_translations().iteritems() } self.file_cacher = FileCacher(self) self.evaluation_services = [ self.connect_to(ServiceCoord("EvaluationService", i)) for i in range(get_service_shards("EvaluationService")) ] self.scoring_service = self.connect_to( ServiceCoord("ScoringService", 0)) ranking_enabled = len(config.rankings) > 0 self.proxy_service = self.connect_to(ServiceCoord("ProxyService", 0), must_be_present=ranking_enabled) printing_enabled = config.printer is not None self.printing_service = self.connect_to( ServiceCoord("PrintingService", 0), must_be_present=printing_enabled)
def __init__(self, shard, contest_id=None): parameters = { "static_files": [("cms.server", "static"), ("cms.server.contest", "static")], "cookie_secret": hex_to_bin(config.secret_key), "debug": config.tornado_debug, "is_proxy_used": config.is_proxy_used, "num_proxies_used": config.num_proxies_used, "xsrf_cookies": True, } try: listen_address = config.contest_listen_address[shard] listen_port = config.contest_listen_port[shard] except IndexError: raise ConfigError("Wrong shard number for %s, or missing " "address/port configuration. Please check " "contest_listen_address and contest_listen_port " "in cms.conf." % __name__) self.contest_id = contest_id if self.contest_id is None: HANDLERS.append((r"", MainHandler)) handlers = [(r'/', ContestListHandler)] for h in HANDLERS: handlers.append((r'/([^/]+)' + h[0], ) + h[1:]) else: HANDLERS.append((r"/", MainHandler)) handlers = HANDLERS super().__init__(listen_port, handlers, parameters, shard=shard, listen_address=listen_address) self.wsgi_app = SharedDataMiddleware( self.wsgi_app, {"/stl": config.stl_path}, cache=True, cache_timeout=SECONDS_IN_A_YEAR, fallback_mimetype="application/octet-stream") self.jinja2_environment = CWS_ENVIRONMENT # This is a dictionary (indexed by username) of pending # notification. Things like "Yay, your submission went # through.", not things like "Your question has been replied", # that are handled by the db. Each username points to a list # of tuples (timestamp, subject, text). self.notifications = {} # Retrieve the available translations. self.translations = get_translations() self.evaluation_service = self.connect_to( ServiceCoord("EvaluationService", 0)) self.scoring_service = self.connect_to( ServiceCoord("ScoringService", 0)) ranking_enabled = len(config.rankings) > 0 self.proxy_service = self.connect_to(ServiceCoord("ProxyService", 0), must_be_present=ranking_enabled) printing_enabled = config.printer is not None self.printing_service = self.connect_to( ServiceCoord("PrintingService", 0), must_be_present=printing_enabled)