def main(): """Entry point for RWS. return (int): exit code (0 on success, 1 on error) """ parser = argparse.ArgumentParser(description="Ranking for CMS.") parser.add_argument("--config", type=argparse.FileType("rt"), help="override config file") parser.add_argument("-d", "--drop", action="store_true", help="drop the data already stored") args = parser.parse_args() config.load(args.config) if args.drop: ans = input("Are you sure you want to delete directory %s? [y/N]" % config.lib_dir).strip().lower() if ans in ['y', 'yes']: print("Removing directory %s." % config.lib_dir) shutil.rmtree(config.lib_dir) else: print("Not removing directory %s." % config.lib_dir) return 1 Contest.store.load_from_disk() Task.store.load_from_disk() Team.store.load_from_disk() User.store.load_from_disk() Submission.store.load_from_disk() Subchange.store.load_from_disk() Scoring.store.init_store() toplevel_handler = RoutingHandler( DataWatcher(), ImageHandler(os.path.join(config.lib_dir, '%(name)s'), os.path.join(config.web_dir, 'img', 'logo.png'))) wsgi_app = SharedDataMiddleware( DispatcherMiddleware( toplevel_handler, { '/contests': StoreHandler(Contest.store), '/tasks': StoreHandler(Task.store), '/teams': StoreHandler(Team.store), '/users': StoreHandler(User.store), '/submissions': StoreHandler(Submission.store), '/subchanges': StoreHandler(Subchange.store), '/faces': ImageHandler(os.path.join(config.lib_dir, 'faces', '%(name)s'), os.path.join(config.web_dir, 'img', 'face.png')), '/flags': ImageHandler(os.path.join(config.lib_dir, 'flags', '%(name)s'), os.path.join(config.web_dir, 'img', 'flag.png')), }), {'/': config.web_dir}) servers = list() if config.http_port is not None: http_server = WSGIServer((config.bind_address, config.http_port), wsgi_app) servers.append(http_server) if config.https_port is not None: https_server = WSGIServer((config.bind_address, config.https_port), wsgi_app, certfile=config.https_certfile, keyfile=config.https_keyfile) servers.append(https_server) try: gevent.joinall(list(gevent.spawn(s.serve_forever) for s in servers)) except KeyboardInterrupt: pass finally: gevent.joinall(list(gevent.spawn(s.stop) for s in servers)) return 0
def main(): """Entry point for RWS. return (bool): True if executed successfully. """ parser = argparse.ArgumentParser( description="Ranking for CMS.") parser.add_argument("--config", type=argparse.FileType("rt"), help="override config file") parser.add_argument("-d", "--drop", action="store_true", help="drop the data already stored") args = parser.parse_args() config.load(args.config) if args.drop: print("Are you sure you want to delete directory %s? [y/N]" % config.lib_dir, end='') ans = raw_input().lower() if ans in ['y', 'yes']: print("Removing directory %s." % config.lib_dir) shutil.rmtree(config.lib_dir) else: print("Not removing directory %s." % config.lib_dir) return False Contest.store.load_from_disk() Task.store.load_from_disk() Team.store.load_from_disk() User.store.load_from_disk() Submission.store.load_from_disk() Subchange.store.load_from_disk() Scoring.store.init_store() toplevel_handler = RoutingHandler(DataWatcher(), ImageHandler( os.path.join(config.lib_dir, '%(name)s'), os.path.join(config.web_dir, 'img', 'logo.png'))) wsgi_app = SharedDataMiddleware(DispatcherMiddleware( toplevel_handler, {'/contests': StoreHandler(Contest.store), '/tasks': StoreHandler(Task.store), '/teams': StoreHandler(Team.store), '/users': StoreHandler(User.store), '/submissions': StoreHandler(Submission.store), '/subchanges': StoreHandler(Subchange.store), '/faces': ImageHandler( os.path.join(config.lib_dir, 'faces', '%(name)s'), os.path.join(config.web_dir, 'img', 'face.png')), '/flags': ImageHandler( os.path.join(config.lib_dir, 'flags', '%(name)s'), os.path.join(config.web_dir, 'img', 'flag.png')), }), {'/': config.web_dir}) servers = list() if config.http_port is not None: http_server = WSGIServer( (config.bind_address, config.http_port), wsgi_app) servers.append(http_server) if config.https_port is not None: https_server = WSGIServer( (config.bind_address, config.https_port), wsgi_app, certfile=config.https_certfile, keyfile=config.https_keyfile) servers.append(https_server) try: gevent.joinall(list(gevent.spawn(s.serve_forever) for s in servers)) except KeyboardInterrupt: pass finally: gevent.joinall(list(gevent.spawn(s.stop) for s in servers)) return True