Ejemplo n.º 1
0
def get_task_id(contest_id, user_id, task_module):
    name = task_module.task_info['name']

    # Have we done this before? Pull it out of our cache if so.
    if task_module in task_id_map:
        # Ensure we don't have multiple modules with the same task name.
        assert task_id_map[task_module][1] == task_module

        return task_id_map[name][0]

    task_create_args = {
        "token_mode": "finite",
        "token_max_number": "100",
        "token_min_interval": "0",
        "token_gen_initial": "100",
        "token_gen_number": "0",
        "token_gen_interval": "1",
        "token_gen_max": "100",
        "max_submission_number": "100",
        "max_user_test_number": "100",
        "min_submission_interval": None,
        "min_user_test_interval": None,
    }
    task_create_args.update(task_module.task_info)

    # Find if the task already exists in the contest.
    tasks = get_tasks(contest_id)
    if name in tasks:
        # Then just use the existing one.
        task = tasks[name]
        task_id = task['id']
        task_id_map[name] = (task_id, task_module)
        add_existing_task(contest_id, task_id, **task_create_args)
        return task_id

    # Otherwise, we need to add the task ourselves.
    task_id = add_task(contest_id, **task_create_args)

    # add any managers
    code_path = os.path.join(os.path.dirname(task_module.__file__), "code")
    if hasattr(task_module, 'managers'):
        for manager in task_module.managers:
            mpath = os.path.join(code_path, manager)
            add_manager(task_id, mpath)

    # add the task's test data.
    data_path = os.path.join(os.path.dirname(task_module.__file__), "data")
    for num, (input_file, output_file, public) \
            in enumerate(task_module.test_cases):
        ipath = os.path.join(data_path, input_file)
        opath = os.path.join(data_path, output_file)
        add_testcase(task_id, num, ipath, opath, public)

    task_id_map[name] = (task_id, task_module)

    info("Created task %s as id %d" % (name, task_id))

    # We need to restart ProxyService to ensure it reinitializes,
    # picking up the new task and sending it to RWS.
    restart_service("ProxyService", contest=contest_id)

    return task_id
Ejemplo n.º 2
0
    def create_or_get_task(self, task_module):
        """Create a new task if it does not exist.

        task_module (module): a task as in task/<name>.

        return (int): task id of the new (or existing) task.

        """
        name = task_module.task_info['name'] + str(self.rand)

        # Have we done this before? Pull it out of our cache if so.
        if name in self.task_id_map:
            # Ensure we don't have multiple modules with the same task name.
            assert self.task_id_map[name][1] == task_module

            return self.task_id_map[name][0]

        task_create_args = {
            "token_mode": "finite",
            "token_max_number": "100",
            "token_min_interval": "0",
            "token_gen_initial": "100",
            "token_gen_number": "0",
            "token_gen_interval": "1",
            "token_gen_max": "100",
            "max_submission_number": None,
            "max_user_test_number": None,
            "min_submission_interval": None,
            "min_user_test_interval": None,
        }
        task_create_args.update(task_module.task_info)

        # Update the name with the random bit to avoid conflicts.
        task_create_args["name"] = name

        # Find if the task already exists (the name make sure that if it
        # exists, it is already in out contest).
        tasks = get_tasks()
        if name in tasks:
            # Then just use the existing one.
            task = tasks[name]
            task_id = task['id']
            self.task_id_map[name] = (task_id, task_module)
            add_existing_task(task_id, contest_id=str(self.contest_id),
                              **task_create_args)
            return task_id

        # Otherwise, we need to add the task ourselves.
        task_id = add_task(contest_id=str(self.contest_id), **task_create_args)

        # add any managers
        code_path = os.path.join(
            os.path.dirname(task_module.__file__),
            "code")
        if hasattr(task_module, 'managers'):
            for manager in task_module.managers:
                mpath = os.path.join(code_path, manager)
                add_manager(task_id, mpath)

        # add the task's test data.
        data_path = os.path.join(
            os.path.dirname(task_module.__file__),
            "data")
        for num, (input_file, output_file, public) \
                in enumerate(task_module.test_cases):
            ipath = os.path.join(data_path, input_file)
            opath = os.path.join(data_path, output_file)
            add_testcase(task_id, num, ipath, opath, public)

        self.task_id_map[name] = (task_id, task_module)

        logging.info("Created task %s as id %s", name, task_id)

        return task_id
Ejemplo n.º 3
0
def get_task_id(contest_id, user_id, task_module):
    name = task_module.task_info['name']

    # Have we done this before? Pull it out of our cache if so.
    if task_module in task_id_map:
        # Ensure we don't have multiple modules with the same task name.
        assert task_id_map[task_module][1] == task_module

        return task_id_map[name][0]

    task_create_args = {
        "token_mode": "finite",
        "token_max_number": "100",
        "token_min_interval": "0",
        "token_gen_initial": "100",
        "token_gen_number": "0",
        "token_gen_interval": "1",
        "token_gen_max": "100",
        "max_submission_number": "100",
        "max_user_test_number": "100",
        "min_submission_interval": None,
        "min_user_test_interval": None,
    }
    task_create_args.update(task_module.task_info)

    # Find if the task already exists in the contest.
    tasks = get_tasks(contest_id)
    if name in tasks:
        # Then just use the existing one.
        task = tasks[name]
        task_id = task['id']
        task_id_map[name] = (task_id, task_module)
        add_existing_task(contest_id, task_id, **task_create_args)
        return task_id

    # Otherwise, we need to add the task ourselves.
    task_id = add_task(contest_id, **task_create_args)

    # add any managers
    code_path = os.path.join(
        os.path.dirname(task_module.__file__),
        "code")
    if hasattr(task_module, 'managers'):
        for manager in task_module.managers:
            mpath = os.path.join(code_path, manager)
            add_manager(task_id, mpath)

    # add the task's test data.
    data_path = os.path.join(
        os.path.dirname(task_module.__file__),
        "data")
    for num, (input_file, output_file, public) \
            in enumerate(task_module.test_cases):
        ipath = os.path.join(data_path, input_file)
        opath = os.path.join(data_path, output_file)
        add_testcase(task_id, num, ipath, opath, public)

    task_id_map[name] = (task_id, task_module)

    info("Created task %s as id %d" % (name, task_id))

    # We need to restart ProxyService to ensure it reinitializes,
    # picking up the new task and sending it to RWS.
    restart_service("ProxyService", contest=contest_id)

    return task_id
Ejemplo n.º 4
0
    def create_or_get_task(self, task_module):
        """Create a new task if it does not exist.

        task_module (module): a task as in task/<name>.

        return (int): task id of the new (or existing) task.

        """
        name = task_module.task_info['name'] + str(self.rand)

        # Have we done this before? Pull it out of our cache if so.
        if name in self.task_id_map:
            # Ensure we don't have multiple modules with the same task name.
            assert self.task_id_map[name][1] == task_module

            return self.task_id_map[name][0]

        task_create_args = {
            "token_mode": "finite",
            "token_max_number": "100",
            "token_min_interval": "0",
            "token_gen_initial": "100",
            "token_gen_number": "0",
            "token_gen_interval": "1",
            "token_gen_max": "100",
            "max_submission_number": None,
            "max_user_test_number": None,
            "min_submission_interval": None,
            "min_user_test_interval": None,
        }
        task_create_args.update(task_module.task_info)

        # Update the name with the random bit to avoid conflicts.
        task_create_args["name"] = name

        # Find if the task already exists (the name make sure that if it
        # exists, it is already in out contest).
        tasks = get_tasks()
        if name in tasks:
            # Then just use the existing one.
            task = tasks[name]
            task_id = task['id']
            self.task_id_map[name] = (task_id, task_module)
            add_existing_task(task_id, contest_id=str(self.contest_id),
                              **task_create_args)
            return task_id

        # Otherwise, we need to add the task ourselves.
        task_id = add_task(contest_id=str(self.contest_id), **task_create_args)

        # add any managers
        code_path = os.path.join(
            os.path.dirname(task_module.__file__),
            "code")
        if hasattr(task_module, 'managers'):
            for manager in task_module.managers:
                mpath = os.path.join(code_path, manager)
                add_manager(task_id, mpath)

        # add the task's test data.
        data_path = os.path.join(
            os.path.dirname(task_module.__file__),
            "data")
        for num, (input_file, output_file, public) \
                in enumerate(task_module.test_cases):
            ipath = os.path.join(data_path, input_file)
            opath = os.path.join(data_path, output_file)
            add_testcase(task_id, num, ipath, opath, public)

        self.task_id_map[name] = (task_id, task_module)

        logging.info("Created task %s as id %s", name, task_id)

        return task_id