def main(): global commands import logging from dmoj import judgeenv, executors judgeenv.load_env(cli=True) # Emulate ANSI colors with colorama if os.name == 'nt' and not judgeenv.no_ansi_emu: try: from colorama import init init() except ImportError as ignored: pass executors.load_executors() print 'Running local judge...' logging.basicConfig( filename=judgeenv.log_file, level=logging.INFO, format='%(levelname)s %(asctime)s %(module)s %(message)s') judge = LocalJudge() for warning in judgeenv.startup_warnings: print ansi_style('#ansi[Warning: %s](yellow)' % warning) del judgeenv.startup_warnings print for command in [ ListProblemsCommand, ListSubmissionsCommand, SubmitCommand, ResubmitCommand, RejudgeCommand, HelpCommand, QuitCommand ]: register(command(judge)) with judge: try: judge.listen() except: traceback.print_exc() finally: judge.murder() while True: command = raw_input( ansi_style("#ansi[dmoj](magenta)#ansi[>](green) ")).strip() line = command.split(' ') if line[0] in commands: cmd = commands[line[0]] try: cmd.execute(line[1:]) except InvalidCommandException: print else: print ansi_style('#ansi[Unrecognized command %s](red|bold)' % line[0]) print
def main(): judgeenv.load_env(cli=True, testsuite=True) # Emulate ANSI colors with colorama if os.name == 'nt' and not judgeenv.no_ansi_emu: try: from colorama import init init() except ImportError: pass logging.basicConfig( filename=judgeenv.log_file, level=logging.INFO, format='%(levelname)s %(asctime)s %(module)s %(message)s') executors.load_executors() 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(fails != 0))
def main(): logging.basicConfig(level=logging.INFO) sys.stdout = codecs.getwriter('utf-8')(os.fdopen(sys.stdout.fileno(), 'w', 0)) sys.stderr = codecs.getwriter('utf-8')(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(): judgeenv.load_env(cli=True, testsuite=True) # Emulate ANSI colors with colorama if os.name == 'nt' and not judgeenv.no_ansi_emu: try: from colorama import init init() except ImportError: pass logging.basicConfig(filename=judgeenv.log_file, level=logging.INFO, format='%(levelname)s %(asctime)s %(module)s %(message)s') executors.load_executors() 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(fails != 0))
def main(): 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(): # setup judge judgeenv.load_env(cli=True) executors.load_executors() print('Running grpc judge server ...') logging.basicConfig( filename=judgeenv.log_file, level=logging.INFO, format='%(levelname)s %(asctime)s %(module)s %(message)s') for warning in judgeenv.startup_warnings: print(ansi_style('#ansi[Warning: %s](yellow)' % warning)) del judgeenv.startup_warnings print() judge = LocalJudge() loop = asyncio.get_event_loop() server = Server([DmojService(judge)], loop=loop) host, port = '127.0.0.1', 5001 loop.run_until_complete(server.start(host, port)) print('Serving on {}:{}'.format(host, port)) try: loop.run_forever() except KeyboardInterrupt: pass server.close() loop.run_until_complete(server.wait_closed()) loop.close()
def main(): # pragma: no cover sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) 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() 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: 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(): logging.basicConfig(level=logging.INFO) sys.stdout = codecs.getwriter('utf-8')(os.fdopen(sys.stdout.fileno(), 'w', 0)) sys.stderr = codecs.getwriter('utf-8')(os.fdopen(sys.stderr.fileno(), 'w', 0)) judgeenv.load_env(cli=True, testsuite=True) judgeenv.env['id'] = 'testsuite' 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 cli_main(): import logging from dmoj import judgeenv, executors judgeenv.load_env(cli=True) executors.load_executors() print('Running local judge...') logging.basicConfig( filename=judgeenv.log_file, level=logging.INFO, format='%(levelname)s %(asctime)s %(module)s %(message)s') judge = LocalJudge() for warning in judgeenv.startup_warnings: print_ansi('#ansi[Warning: %s](yellow)' % warning) del judgeenv.startup_warnings print() from dmoj.commands import all_commands, commands, register_command for command in all_commands: register_command(command(judge)) def run_command(line): if not line: return 127 if line[0] in commands: cmd = commands[line[0]] try: return cmd.execute(line[1:]) except InvalidCommandException as e: if e.message: print_ansi("#ansi[%s](red|bold)\n" % e.message) print() return 1 else: print_ansi('#ansi[Unrecognized command %s](red|bold)' % line[0]) print() return 127 with judge: try: judge.listen() if judgeenv.cli_command: return run_command(judgeenv.cli_command) else: while True: command = input( ansi_style( "#ansi[dmoj](magenta)#ansi[>](green) ")).strip() run_command(shlex.split(command)) except (EOFError, KeyboardInterrupt): print() finally: judge.murder()
def main(): # pragma: no cover if six.PY2: sys.stdout = codecs.getwriter('utf-8')(os.fdopen( sys.stdout.fileno(), 'w', 0)) sys.stderr = codecs.getwriter('utf-8')(sys.stderr) else: sys.stdout = codecs.getwriter('utf-8')(open(sys.stdout.fileno(), 'wb', 0, closefd=False)) sys.stderr = codecs.getwriter('utf-8')(sys.stderr.detach()) 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(): global commands import logging from dmoj import judgeenv, executors judgeenv.load_env(cli=True) # Emulate ANSI colors with colorama if os.name == 'nt' and not judgeenv.no_ansi_emu: try: from colorama import init init() except ImportError as ignored: pass executors.load_executors() print 'Running local judge...' logging.basicConfig(filename=judgeenv.log_file, level=logging.INFO, format='%(levelname)s %(asctime)s %(module)s %(message)s') judge = LocalJudge() for warning in judgeenv.startup_warnings: print ansi_style('#ansi[Warning: %s](yellow)' % warning) del judgeenv.startup_warnings print for command in [ListProblemsCommand, ListSubmissionsCommand, SubmitCommand, ResubmitCommand, RejudgeCommand, HelpCommand, QuitCommand]: register(command(judge)) with judge: try: judge.listen() except: traceback.print_exc() finally: judge.murder() while True: command = raw_input(ansi_style("#ansi[dmoj](magenta)#ansi[>](green) ")).strip() line = command.split(' ') if line[0] in commands: cmd = commands[line[0]] try: cmd.execute(line[1:]) except InvalidCommandException: print else: print ansi_style('#ansi[Unrecognized command %s](red|bold)' % line[0]) print
def main(): judgeenv.load_env(cli=True, testsuite=True) logging.basicConfig(filename=judgeenv.log_file, level=logging.INFO, format='%(levelname)s %(asctime)s %(module)s %(message)s') executors.load_executors() contrib.load_contrib_modules() tester = Tester(judgeenv.problem_regex, judgeenv.case_regex) fails = tester.test_all() print() print('Test complete') if fails: print_ansi('#ansi[A total of %d case(s) failed](red|bold).' % fails) else: print_ansi('#ansi[All cases passed.](green|bold)') raise SystemExit(int(fails != 0))
def main(): judgeenv.load_env(cli=True) executors.load_executors() logging.basicConfig(filename=judgeenv.log_file, level=logging.INFO, format='%(levelname)s %(asctime)s %(module)s %(message)s') for warning in judgeenv.startup_warnings: print(ansi_style('#ansi[Warning: %s](yellow)' % warning)) del judgeenv.startup_warnings print() server = connexion.FlaskApp(__name__, specification_dir='api/') with server.app.app_context(): judge = get_judge() judge.listen() server.add_api('api.yaml') server.run(port=8080)
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(): sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) if not sanity_check(): return 1 import logging 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 as ignored: pass executors.load_executors() print 'Running live judge...' logging.basicConfig( filename=judgeenv.log_file, level=logging.INFO, format='%(levelname)s %(asctime)s %(module)s %(message)s') judge = ClassicJudge(judgeenv.server_host, judgeenv.server_port) for warning in judgeenv.startup_warnings: print ansi_style('#ansi[Warning: %s](yellow)' % warning) del judgeenv.startup_warnings print with judge: try: judge.listen() except KeyboardInterrupt: pass except: traceback.print_exc() finally: judge.murder()
def main(): sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) if not sanity_check(): return 1 import logging 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() print 'Running live judge...' logging.basicConfig(filename=judgeenv.log_file, level=logging.INFO, format='%(levelname)s %(asctime)s %(module)s %(message)s') judge = ClassicJudge(judgeenv.server_host, judgeenv.server_port) for warning in judgeenv.startup_warnings: print ansi_style('#ansi[Warning: %s](yellow)' % warning) del judgeenv.startup_warnings print with judge: try: judge.listen() except KeyboardInterrupt: pass except: traceback.print_exc() finally: judge.murder()
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() if hasattr(signal, 'SIGUSR2'): signal.signal(signal.SIGUSR2, signal.SIG_IGN) print('Running live judge...') for warning in judgeenv.startup_warnings: print_ansi('#ansi[Warning: %s](yellow)' % warning) del judgeenv.startup_warnings if '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(): judgeenv.load_env(cli=True, testsuite=True) # 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() 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(fails != 0))
def main(): load_env(cli=True) load_executors()
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()
def main(): global commands import logging from dmoj import judgeenv, executors judgeenv.load_env(cli=True) # 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() print('Running local judge...') logging.basicConfig( filename=judgeenv.log_file, level=logging.INFO, format='%(levelname)s %(asctime)s %(module)s %(message)s') judge = LocalJudge() for warning in judgeenv.startup_warnings: print(ansi_style('#ansi[Warning: %s](yellow)' % warning)) del judgeenv.startup_warnings print() from dmoj.commands import all_commands for command in all_commands: register(command(judge)) with judge: try: judge.listen() while True: command = input( ansi_style( "#ansi[dmoj](magenta)#ansi[>](green) ")).strip() line = command.split(' ') if line[0] in commands: cmd = commands[line[0]] try: cmd.execute(line[1:]) except InvalidCommandException as e: if e.message: print( ansi_style("#ansi[%s](red|bold)\n" % e.message)) print() else: print( ansi_style('#ansi[Unrecognized command %s](red|bold)' % line[0])) print() except (EOFError, KeyboardInterrupt): print() finally: judge.murder()
def main(): load_env(cli=True) load_executors()