def main_run(args): filename = get_filename(args) mission = args.mission[0] domain_data = conf.default_domain_data print() print('Start running...') print() if 'executable' in domain_data: return os.system(' '.join((domain_data['executable'], filename))) with open(filename, encoding="utf-8") as fh: data = run_solution(code_for_check(fh.read())) ret = False while data: block = data.pop(0) com = block[0] if com == 'err': print(block[1], end='') ret = True elif com == 'out': print(str(block[1]), end='') elif com == 'wait': data = restore(block[1]) else: print(block) print() return ret
def main_run_cio(args): if getattr(args, 'check', False): args.check = False # to avoid recursion return main(args) mission = args.mission[0] filename = get_filename(args) if filename is None: init_single_mission(mission) domain_data = conf.default_domain_data if 'executable' in domain_data: return subprocess.call((domain_data['executable'], filename)) with open(filename, encoding="utf-8") as fh: data = run_solution(code_for_check(fh.read())) ret = False while data: block = data.pop(0) com = block[0] if com == 'err': print(block[1], end='') ret = True elif com == 'out': print(str(block[1]), end='') elif com == 'wait': data = restore(block[1]) else: print(block) print() return ret
def main_check_cio(args): filename = get_filename(args) mission = args.mission[0] domain_data = conf.default_domain_data if main_run(args): return print() print('Start checking...') print() mission_info = get_mission_info(mission) mission_id = mission_info['id'] with open(filename, encoding="utf-8") as fh: data = check_solution(code_for_check(fh.read()), mission_id) while data: block = data.pop(0) com = block[0] if com == 'start_in': print('*** ' + block[1] + ' ***') elif com == 'in': print('->' + str(block[1])) elif com == 'out': print('<-' + str(block[1])) elif com == 'ext': res = block[1] if not res['result']: print('!!' + str(res['answer'])) elif com == 'check': if block[1]: print() print('!!! Congratulation !!!') print() print( 'Link for checking solution of other users: {}/mission/{}/publications/' .format(domain_data['url_main'], mission)) print() print( 'Link for sharing solution: {}/mission/{}/publications/add/' .format(domain_data['url_main'], mission)) print() else: print('!! Failed !!') elif com == 'wait': print('Waiting for the next piece of data...') time.sleep(block[2]) print('Restore checking...') data = restore(block[1]) else: print(block)
def main_check_cio(args): filename = get_filename(args) mission = args.mission[0].replace('_', '-') domain_data = conf.default_domain_data if main_run(args): return print() print('Start checking...') print() mission_info = get_mission_info(mission) mission_id = mission_info['id'] with open(filename, encoding="utf-8") as fh: data = check_solution(code_for_check(fh.read()), mission_id) while data: block = data.pop(0) com = block[0] if com == 'start_in': print('*** ' + block[1] + ' ***' ) elif com == 'in': print('->' + str(block[1])) elif com == 'out': print('<-' + str(block[1])) elif com == 'ext': res = block[1] if not res['result']: print('!!' + str(res['answer'])) elif com == 'check': if block[1]: system_data = { 'info': 'passed', 'solutions_link': '{}/mission/{}/publications/'.format( domain_data['url_main'], mission ), 'add_link': '{}/mission/{}/publications/add/'.format( domain_data['url_main'], mission ) } print() print('!!! Congratulation !!!') print() print('Link for checking solution of other users: ' + system_data['solutions_link']) print() print('Link for sharing solution: ' + system_data['add_link']) print() if args.sysinfo: print(SYSTEM_BLOCK_START) print(json.dumps(system_data, indent=1)) print(SYSTEM_BLOCK_END) else: print('!! Failed !!') elif com == 'wait': print('Waiting for the next piece of data...') time.sleep(block[2]) print('Restore checking...') data = restore(block[1]) else: print(block)