예제 #1
0
파일: TaskType.py 프로젝트: kennyboy/cms
def create_sandbox(task_type):
    """Create a sandbox, and return it.

    task_type (TaskType): a task type instance.

    return (Sandbox): a sandbox.

    raise: JobException

    """
    try:
        sandbox = Sandbox(task_type.file_cacher)
    except (OSError, IOError):
        err_msg = "Couldn't create sandbox."
        logger.error("%s\n%s" % (err_msg, traceback.format_exc()))
        raise JobException(err_msg)
    return sandbox
예제 #2
0
def create_sandbox(file_cacher):
    """Create a sandbox, and return it.

    file_cacher (FileCacher): a file cacher instance.

    return (Sandbox): a sandbox.

    raise (JobException): if the sandbox cannot be created.

    """
    try:
        sandbox = Sandbox(file_cacher)
    except (OSError, IOError):
        err_msg = "Couldn't create sandbox."
        logger.error(err_msg, exc_info=True)
        raise JobException(err_msg)
    return sandbox
예제 #3
0
파일: TaskType.py 프로젝트: saadmahboob/cms
def create_sandbox(file_cacher):
    """Create a sandbox, and return it.

    file_cacher (FileCacher): a file cacher instance.

    return (Sandbox): a sandbox.

    raise (JobException): if the sandbox cannot be created.

    """
    try:
        sandbox = Sandbox(file_cacher)
    except (OSError, IOError):
        err_msg = "Couldn't create sandbox."
        logger.error("%s\n%s" % (err_msg, traceback.format_exc()))
        raise JobException(err_msg)
    return sandbox
예제 #4
0
파일: TaskType.py 프로젝트: mengjieying/cms
def create_sandbox(file_cacher, multithreaded=False, name=None):
    """Create a sandbox, and return it.

    file_cacher (FileCacher): a file cacher instance.
    multithreaded (boolean): whether the sandbox should allow multithreading.

    return (Sandbox): a sandbox.

    raise (JobException): if the sandbox cannot be created.

    """
    try:
        sandbox = Sandbox(multithreaded, file_cacher, name=name)
    except (OSError, IOError):
        err_msg = "Couldn't create sandbox."
        logger.error(err_msg, exc_info=True)
        raise JobException(err_msg)
    return sandbox
예제 #5
0
파일: util.py 프로젝트: kevinwangl/cms
def create_sandbox(file_cacher, name=None):
    """Create a sandbox, and return it.

    file_cacher (FileCacher): a file cacher instance.
    name (str): name to include in the path of the sandbox.

    return (Sandbox): a sandbox.

    raise (JobException): if the sandbox cannot be created.

    """
    try:
        sandbox = Sandbox(file_cacher, name=name)
    except OSError:
        err_msg = "Couldn't create sandbox."
        logger.error(err_msg, exc_info=True)
        raise JobException(err_msg)
    return sandbox
예제 #6
0
def build_sols_list(base_dir, task_type, in_out_files, yaml_conf):
    if yaml_conf.get('only_gen', False):
        return []

    sol_dir = os.path.join(base_dir, SOL_DIRNAME)
    entries = map(lambda x: os.path.join(SOL_DIRNAME, x), os.listdir(sol_dir))
    sources = filter(lambda x: endswith2(x, SOL_EXTS), entries)

    actions = []
    test_actions = []
    for src in sources:
        exe, lang = basename2(src, SOL_EXTS)
        # Delete the dot
        lang = lang[1:]

        # Ignore things known to be auxiliary files
        if exe == os.path.join(SOL_DIRNAME, GRAD_BASENAME):
            continue
        if lang == 'pas' and exe.endswith('lib'):
            continue

        srcs = []
        # The grader, when present, must be in the first position of
        # srcs; see docstring of get_compilation_command().
        if task_type == ['Batch', 'Grad'] or \
                task_type == ['Batch', 'GradComp']:
            srcs.append(
                os.path.join(SOL_DIRNAME, GRAD_BASENAME + '.%s' % (lang)))
        srcs.append(src)

        test_deps = [exe] + in_out_files
        if task_type == ['Batch', 'Comp'] or \
                task_type == ['Batch', 'GradComp']:
            test_deps.append('cor/correttore')

        box_path = Sandbox().detect_box_executable()

        def compile_src(srcs, exe, lang):
            if lang != 'pas' or len(srcs) == 1:
                call(
                    base_dir,
                    get_compilation_command(lang,
                                            srcs,
                                            exe,
                                            for_evaluation=False))

            # When using Pascal with graders, file naming conventions
            # require us to do a bit of trickery, i.e., performing the
            # compilation in a separate temporary directory
            else:
                tempdir = tempfile.mkdtemp()
                task_name = detect_task_name(base_dir)
                new_srcs = [os.path.split(srcs[0])[1], '%s.pas' % (task_name)]
                new_exe = os.path.split(srcs[1])[1][:-4]
                shutil.copyfile(srcs[0], os.path.join(tempdir, new_srcs[0]))
                shutil.copyfile(srcs[1], os.path.join(tempdir, new_srcs[1]))
                lib_filename = '%slib.pas' % (task_name)
                if os.path.exists(os.path.join(SOL_DIRNAME, lib_filename)):
                    shutil.copyfile(os.path.join(SOL_DIRNAME, lib_filename),
                                    os.path.join(tempdir, lib_filename))
                call(
                    tempdir,
                    get_compilation_command(lang,
                                            new_srcs,
                                            new_exe,
                                            for_evaluation=False))
                shutil.copyfile(os.path.join(tempdir, new_exe),
                                os.path.join(SOL_DIRNAME, new_exe))
                shutil.copymode(os.path.join(tempdir, new_exe),
                                os.path.join(SOL_DIRNAME, new_exe))
                shutil.rmtree(tempdir)

        def test_src(exe, input_num, task_type):
            print "Testing solution %s" % (exe)
            cormgr = ''
            if task_type == ['Batch', 'Comp'] or \
                    task_type == ['Batch', 'GradComp']:
                cormgr = 'cor/correttore'
            test_testcases(input_num,
                           box_path,
                           exe,
                           yaml_conf['timeout'],
                           yaml_conf['memlimit'],
                           task_type[0],
                           task_type[1],
                           cormgr=cormgr)

        actions.append(
            (srcs, [exe], functools.partial(compile_src, srcs, exe,
                                            lang), 'compile solution'))

        input_num = len(in_out_files) / 2
        test_actions.append((test_deps, ['test_%s' % (os.path.split(exe)[1])],
                             functools.partial(test_src, exe, input_num,
                                               task_type), 'test solution'))

    return actions + test_actions