コード例 #1
0
def check_ans_spj(config_dict, i, score):
    '''
    在工作目录用 spj 进行测试(测试点编号为 [i] )
    以 [config_dict] 为配置
    返回得分
    '''
    if not os.path.exists('sp.log'):
        os.mknod('sp.log')
    spres = os.system( \
            'timeout {2} ./spj \
            {0}.in {0}.out {0}.ans {1} sp.get sp.log'                                                     .format( \
            i, score, config_dict['difftime']))
    # 评分过程超时
    if spres == TIMEOUT:
        info.print_info('OLE', i)
        print('Output too long', file=open('res{}'.format(i), 'a'))
    # 评分过程错误
    elif spres != 0:
        info.print_info('UKE', i)
    try:
        get = float(open('sp.get', 'r').readline()[:-1])
    except FileNotFoundError:
        info.error_exit('Spj doesn\'t output score')
    print('\nMessage from spj:', file=open('res{}'.format(i), 'a'))
    os.system('cat sp.log >> res{}'.format(i))
    return get
コード例 #2
0
ファイル: file_fun.py プロジェクト: Kewth/retest
def make_data(config_dict, path):
    '以 [config_dict] 配置制造数据'
    data = config_dict['data']
    config_dict['data'] = 'dp_data'
    # while os.path.exists(config_dict['data']):
    #     config_dict['data'] += '_'
    from retest import config  # 不能全局 import ,原因不详
    config.upd_config(data, {'times': 10}, require=['std', 'rand'])
    make_dir(config_dict['data'])
    compile_source(data['std'], 'std', '', path)
    compile_source(data['rand'], 'rand', '', path)
    for i in range(data['times']):
        print(i + 1, '/', data['times'])
        rand_res = os.system('{}/rand > {}/{}.in 2> /dev/null'.format( \
                path, config_dict['data'], i))
        if rand_res != 0:
            info.error_exit('Make data error: {} exit {}'.format( \
                    data['rand'], rand_res))
        std_res = os.system( \
                '{0}/std < {1}/{2}.in > {1}/{2}.out 2> /dev/null'.format( \
                path, config_dict['data'], i))
        if std_res != 0:
            info.error_exit('Make data error: {} exit {}'.format( \
                    data['std'], std_res))
        print(colorama.Cursor.UP(), end='')
コード例 #3
0
def get_config():
    '''
    获取配置信息
    返回一个字典
    '''
    # 获取全局配置
    try:
        config_file = open(XDG.xdg_data_home + '/retest/retest.yaml', 'r')
    except FileNotFoundError:
        info.error_exit( \
                'No global retest.yaml was found in \
                {}/retest/, \
                input ntest -l to get help'.format(XDG.xdg_data_home))
    global_config = yaml.load(config_file, Loader=yaml.FullLoader)
    # 获取当前配置
    try:
        config_file = open('retest.yaml', 'r')
    except FileNotFoundError:
        info.error_exit( \
                'No retest.yaml was found, \
                input ntest -l to get help')
    current_config = yaml.load(config_file, Loader=yaml.FullLoader)
    # 用全局配置更新局部配置
    if not global_config:
        info.warning('Global config file is empty!')
        global_config = {}
    if not current_config:
        info.warning('Config file is empty!')
        current_config = {}
    upd_config(current_config, global_config)
    return current_config
コード例 #4
0
ファイル: __init__.py プロジェクト: HNFMS-g2018/retest
def main():
    '主函数'
    args = init_args()
    if args.learn:
        learn.main()
        return 0
    if args.plugin:
        for i in plugin.list_plugin():
            print(i)
        return 0
    config_dict = config.get_config()
    while config_dict.get('cd'):
        os.chdir(config_dict['cd'])
        config_dict = config.get_config()
    config.upd_config(config_dict, {'plugin': 'default'})
    if config_dict.get('before'):
        os.system(config_dict['before'])
    plugin.get_plugins(config_dict['plugin'])
    if args.use:
        config_dict = config_dict.get(args.use[0])
        if not config_dict:
            info.error_exit('--use: No such a subconfig')
    try:
        plugin.plugin_start()
    except AttributeError as err:
        info.warning('PluginTooOld: {}'.format(err))
    now = 0
    while config_dict.get('T{}'.format(now + 1)):
        now += 1
    file_fun.make_dir()
    if now != 0:
        # 有多个程序待评测
        score = 0
        for i in range(1, now + 1):
            problem = 'T{}'.format(i)
            try:
                plugin.plugin_before_judge(problem)
            except AttributeError as err:
                info.warning('PluginTooOld: {}'.format(err))
            os.makedirs('retest_dir/' + problem)
            sub_config = config_dict[problem]
            for key in config_dict:
                # 用全局配置更新局部配置
                if not sub_config.get(key):
                    sub_config[key] = config_dict[key]
            score += judge.judge(sub_config, './retest_dir/' + problem)
    else:
        try:
            plugin.plugin_before_judge('')
        except AttributeError as err:
            info.warning('PluginTooOld: {}'.format(err))
        score = judge.judge(config_dict, './retest_dir')
    try:
        plugin.plugin_end(score)
    except AttributeError as err:
        info.warning('PluginTooOld: {}'.format(err))
    if config_dict.get('after'):
        os.system(config_dict['after'])
    return 0
コード例 #5
0
def upd_config(config_dict, default, require=[]):
    '''
    用 [default] 配置更新 [config_dict] 配置
    [require] 为必须的配置列表
    '''
    for key in default:
        if not config_dict.get(key):
            config_dict[key] = default[key]
    for key in require:
        if not config_dict.get(key):
            info.error_exit('No {} was read'.format(key))
コード例 #6
0
ファイル: plugin.py プロジェクト: HNFMS-g2018/retest
def get_plugin(name):
    '''
    获取插件 [name] 到全局变量 PRINT :-)
    变量 plugins 为已用的插件
    '''
    if name not in list_plugin():
        info.error_exit('No plugin named {}.\nTry ntest -p'.format(name))
    length = len(get_plugin.plugins)
    os.system( \
            'cp {}/retest/plugin/{}.py /tmp/ntest_plugin{}.py'.format( \
            XDG.xdg_data_home, name, length))
    sys.path.append('/tmp')
    if length == 0:
        import ntest_plugin0
        get_plugin.plugins.append(ntest_plugin0)
    elif length == 1:
        import ntest_plugin1
        get_plugin.plugins.append(ntest_plugin1)
    elif length == 2:
        import ntest_plugin2
        get_plugin.plugins.append(ntest_plugin2)
    elif length == 3:
        import ntest_plugin3
        get_plugin.plugins.append(ntest_plugin3)
    elif length == 4:
        import ntest_plugin4
        get_plugin.plugins.append(ntest_plugin4)
    elif length == 5:
        import ntest_plugin5
        get_plugin.plugins.append(ntest_plugin5)
    elif length == 6:
        import ntest_plugin6
        get_plugin.plugins.append(ntest_plugin6)
    elif length == 7:
        import ntest_plugin7
        get_plugin.plugins.append(ntest_plugin7)
    elif length == 8:
        import ntest_plugin8
        get_plugin.plugins.append(ntest_plugin8)
    elif length == 9:
        import ntest_plugin9
        get_plugin.plugins.append(ntest_plugin9)
コード例 #7
0
def compile_source(name, exe, option, path):
    '''
    将 [name:str] 转换为可执行文件到工作目录的 [exe:str]
    如果是编译,添加参数 [option:str]
    '''
    if not os.path.exists(name):
        info.error_exit('No source file {}, compile error'.format( \
                name))
    if len(name) > 4 and name[-4:] == '.cpp':
        res = os.system( \
                'g++ {} -o {}/{} {}'.format( \
                name, path, exe, option))
    elif len(name) > 2 and name[-2:] == '.c':
        res = os.system( \
                'gcc {} -o {}/{} {}'.format( \
                name, path, exe, option))
    else:
        res = os.system( \
                'cp {0} {1}/{2} ; chmod +x {1}/{2}'.format( \
                name, path, exe))
    if res != 0:
        info.error_exit('Compile Error')