def main(): unicode_stdout_stderr() logging.basicConfig(level=logging.INFO) sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) sys.stderr = os.fdopen(sys.stderr.fileno(), 'w', 0) judgeenv.load_env(cli=True, testsuite=True) executors.load_executors() executor_fail = not all(name in executors.executors for name in required_executors) if executor_fail: print(ansi_style('#ansi[A required executor failed to load.](red|bold)')) else: print(ansi_style('#ansi[All required executors loaded successfully.](green|bold)')) print() tester = Tester(judgeenv.problem_regex, judgeenv.case_regex) fails = tester.test_all() print() print('Test complete') if fails: print(ansi_style('#ansi[A total of %d case(s) failed](red|bold).') % fails) else: print(ansi_style('#ansi[All cases passed.](green|bold)')) raise SystemExit(int(executor_fail or fails != 0))
def main(): # pragma: no cover unicode_stdout_stderr() if not sanity_check(): return 1 from dmoj import judgeenv, executors judgeenv.load_env() # Emulate ANSI colors with colorama if os.name == 'nt' and not judgeenv.no_ansi_emu: try: from colorama import init init() except ImportError: pass executors.load_executors() if hasattr(signal, 'SIGUSR2'): signal.signal(signal.SIGUSR2, signal.SIG_IGN) print('Running live judge...') for warning in judgeenv.startup_warnings: print(ansi_style('#ansi[Warning: %s](yellow)' % warning)) del judgeenv.startup_warnings if os.name == 'posix' and 'judges' in env: logfile = judgeenv.log_file try: logfile = logfile % 'master' except TypeError: pass logging.basicConfig( filename=logfile, level=logging.INFO, format= '%(filename)s %(levelname)s %(asctime)s %(process)d %(name)s %(message)s' ) if env.pidfile: with open(env.pidfile) as f: f.write(str(os.getpid())) manager = JudgeManager(env.judges) manager.run() else: return judge_proc(need_monitor=True)
def main(): # pragma: no cover unicode_stdout_stderr() if not sanity_check(): return 1 from dmoj import judgeenv, executors judgeenv.load_env() # Emulate ANSI colors with colorama if os.name == 'nt' and not judgeenv.no_ansi_emu: try: from colorama import init init() except ImportError: pass executors.load_executors() if hasattr(signal, 'SIGUSR2'): signal.signal(signal.SIGUSR2, signal.SIG_IGN) print('Running live judge...') for warning in judgeenv.startup_warnings: print(ansi_style('#ansi[Warning: %s](yellow)' % warning)) del judgeenv.startup_warnings if os.name == 'posix' and 'judges' in env: logfile = judgeenv.log_file try: logfile = logfile % 'master' except TypeError: pass logging.basicConfig(filename=logfile, level=logging.INFO, format='%(levelname)s %(asctime)s %(process)d %(name)s %(message)s') if env.pidfile: with open(env.pidfile) as f: f.write(str(os.getpid())) manager = JudgeManager(env.judges) manager.run() else: return judge_proc(need_monitor=True)
def main(): # pragma: no cover unicode_stdout_stderr() if not sanity_check(): return 1 from dmoj import judgeenv, contrib, executors judgeenv.load_env() executors.load_executors() contrib.load_contrib_modules() print('Running live judge...') for warning in judgeenv.startup_warnings: print_ansi('#ansi[Warning: %s](yellow)' % warning) del judgeenv.startup_warnings logfile = judgeenv.log_file try: logfile = logfile % env['id'] except TypeError: pass logging.basicConfig( filename=logfile, level=logging.INFO, format='%(levelname)s %(asctime)s %(process)d %(module)s %(message)s') setproctitle('DMOJ Judge %s on %s' % (env['id'], make_host_port(judgeenv))) judge = ClassicJudge( judgeenv.server_host, judgeenv.server_port, secure=judgeenv.secure, no_cert_check=judgeenv.no_cert_check, cert_store=judgeenv.cert_store, ) monitor = Monitor() monitor.callback = judge.update_problems if hasattr(signal, 'SIGUSR2'): def update_problem_signal(signum, frame): judge.update_problems() signal.signal(signal.SIGUSR2, update_problem_signal) if judgeenv.api_listen: judge_instance = judge class Handler(JudgeControlRequestHandler): judge = judge_instance api_server = HTTPServer(judgeenv.api_listen, Handler) thread = threading.Thread(target=api_server.serve_forever) thread.daemon = True thread.start() else: api_server = None print() with monitor: try: judge.listen() except KeyboardInterrupt: pass except Exception: traceback.print_exc() finally: judge.murder() if api_server: api_server.shutdown()