Exemple #1
0
def cws_submit(contest_id, task_id, user_id, submission_format_element,
               filename, language):
    username = created_users[user_id]['username']
    password = created_users[user_id]['password']
    base_url = 'http://localhost:8888/'
    task = (task_id, created_tasks[task_id]['name'])

    global cws_browser
    if cws_browser is None:
        cws_browser = mechanize.Browser()
        cws_browser.set_handle_robots(False)
        cws_browser.set_handle_redirect(False)
        LoginRequest(
            cws_browser, username, password, base_url=base_url).execute()

    sr = SubmitRequest(cws_browser, task, base_url=base_url,
                       submission_format_element=submission_format_element,
                       filename=filename)
    sr.execute()
    submission_id = sr.get_submission_id()

    if submission_id is None:
        raise FrameworkException("Failed to submit solution.")

    return submission_id
Exemple #2
0
def cws_submit(contest_id, task_id, user_id, submission_format_element,
               filename, language):
    username = created_users[user_id]['username']
    password = created_users[user_id]['password']
    base_url = 'http://localhost:8888/'
    task = (task_id, created_tasks[task_id]['name'])

    global cws_browser
    if cws_browser is None:
        cws_browser = mechanize.Browser()
        cws_browser.set_handle_robots(False)
        cws_browser.set_handle_redirect(False)
        LoginRequest(cws_browser, username, password,
                     base_url=base_url).execute()

    sr = SubmitRequest(cws_browser,
                       task,
                       base_url=base_url,
                       submission_format_element=submission_format_element,
                       filename=filename)
    sr.execute()
    submission_id = sr.get_submission_id()

    if submission_id is None:
        raise FrameworkException("Failed to submit solution.")

    return submission_id
Exemple #3
0
def cws_submit(contest_id, task_id, user_id, submission_format, filenames, language):
    task = (task_id, created_tasks[task_id]["name"])

    browser = get_cws_browser(user_id)
    sr = SubmitRequest(browser, task, base_url=CWS_BASE_URL, submission_format=submission_format, filenames=filenames)
    sr.execute()
    submission_id = sr.get_submission_id()

    if submission_id is None:
        raise FrameworkException("Failed to submit solution.")

    return submission_id
Exemple #4
0
    def cws_submit(self, task_id, user_id,
                   submission_format, filenames, language):
        task = (task_id, self.created_tasks[task_id]['name'])

        browser = self.get_cws_browser(user_id)
        sr = SubmitRequest(browser, task, base_url=self.CWS_BASE_URL,
                           submission_format=submission_format,
                           filenames=filenames, language=language)
        sr.execute()
        submission_id = sr.get_submission_id()

        if submission_id is None:
            raise TestException("Failed to submit solution.")

        return submission_id
Exemple #5
0
def submit_solution(username, password, task, files, base_url=None):
    browser = mechanize.Browser()
    browser.set_handle_robots(False)

    LoginRequest(browser, username, password, base_url=base_url).execute()
    SubmitRequest(browser, task, base_url=base_url,
                  filename=files[0]).execute()
Exemple #6
0
def cws_submit(contest_id, task_id, user_id, submission_format_element,
               filename, language):
    task = (task_id, created_tasks[task_id]['name'])

    browser = get_cws_browser(user_id)
    sr = SubmitRequest(browser,
                       task,
                       base_url=CWS_BASE_URL,
                       submission_format_element=submission_format_element,
                       filename=filename)
    sr.execute()
    submission_id = sr.get_submission_id()

    if submission_id is None:
        raise FrameworkException("Failed to submit solution.")

    return submission_id
Exemple #7
0
def submit_solution(username, password, task, files, base_url=None):
    def step(request):
        request.prepare()
        request.execute()

    browser = mechanize.Browser()
    browser.set_handle_robots(False)

    step(LoginRequest(browser, username, password, base_url=base_url))
    step(SubmitRequest(browser, task, base_url=base_url, filename=files[0]))
Exemple #8
0
def cws_submit(contest_id, task_id, user_id, filename, language):
    username = created_users[user_id]['username']
    password = created_users[user_id]['password']
    base_url = 'http://localhost:8888/'
    task = (task_id, created_tasks[task_id]['name'])

    def step(request):
        request.prepare()
        request.execute()

    browser = mechanize.Browser()
    browser.set_handle_robots(False)

    lr = LoginRequest(browser, username, password, base_url=base_url)
    step(lr)
    sr = SubmitRequest(browser, task, base_url=base_url, filename=filename)
    step(sr)

    submission_id = sr.get_submission_id()

    if submission_id is None:
        raise FrameworkException("Failed to submit solution.")

    return submission_id
Exemple #9
0
def cws_submit(contest_id, task_id, user_id, filename, language):
    username = created_users[user_id]['username']
    password = created_users[user_id]['password']
    base_url = 'http://localhost:8888/'
    task = (task_id, created_tasks[task_id]['name'])

    def step(request):
        request.prepare()
        request.execute()

    browser = mechanize.Browser()
    browser.set_handle_robots(False)

    lr = LoginRequest(browser, username, password, base_url=base_url)
    step(lr)
    sr = SubmitRequest(browser, task, base_url=base_url, filename=filename)
    step(sr)

    submission_id = sr.get_submission_id()

    if submission_id is None:
        raise FrameworkException("Failed to submit solution.")

    return submission_id
Exemple #10
0
    def submit(self, timestamp, username, password, t_id, t_short, files,
               language):
        """Execute the request for a submission.

        timestamp (int): seconds from the start.
        username (string): username issuing the submission.
        password (string): password of username.
        t_id (string): id of the task.
        t_short (string): short name of the task.
        files ([dict]): list of dictionaries with keys 'filename' and
                        'digest'.
        language (string): the extension the files should have.

        """
        logger.info("%s - Submitting for %s on task %s." %
                    (to_time(timestamp), username, t_short))
        if len(files) != 1:
            logger.error("We cannot submit more than one file.")
            return

        # Copying submission files into a temporary directory with the
        # correct name. Otherwise, SubmissionRequest does not know how
        # to interpret the file (and which language are they in).
        temp_dir = tempfile.mkdtemp(dir=config.temp_dir)
        for file_ in files:
            temp_filename = os.path.join(
                temp_dir, file_["filename"].replace("%l", language))
            shutil.copy(
                os.path.join(self.import_source, "files", files[0]["digest"]),
                temp_filename)
            file_["filename"] = temp_filename

        filename = os.path.join(files[0]["filename"])
        browser = Browser()
        browser.set_handle_robots(False)
        step(
            LoginRequest(browser,
                         username,
                         password,
                         base_url=self.cws_address))
        step(
            SubmitRequest(browser, (int(t_id), t_short),
                          filename=filename,
                          base_url=self.cws_address))
        shutil.rmtree(temp_dir)
Exemple #11
0
def submit(timestamp, username, password, t_id, t_short, files, language,
           session, cws_address):
    """Execute the request for a submission.

    timestamp (int): seconds from the start.
    username (string): username issuing the submission.
    password (string): password of username.
    t_id (string): id of the task.
    t_short (string): short name of the task.
    files ([dict]): list of files.
    language (string): the extension the files should have.
    cws_address (string): http address of CWS.
    """
    logger.info("%s - Submitting for %s on task %s.", to_time(timestamp),
                username, t_short)

    # Copying submission files into a temporary directory with the
    # correct name. Otherwise, SubmissionRequest does not know how
    # to interpret the file (and which language are they in).
    temp_dir = tempfile.mkdtemp(dir=config.temp_dir)
    file_name = []
    submission_format = []
    for file_ in files:
        name = file_.filename
        filename = os.path.join(temp_dir, name)
        fso = FSObject.get_from_digest(file_.digest, session)
        assert fso is not None
        with fso.get_lobject(mode="rb") as file_obj:
            data = file_obj.read()
            with open(filename, "wb") as f_out:
                f_out.write(data)
        file_name.append(filename)
        submission_format.append(name)

    browser = Browser()
    lr = LoginRequest(browser, username, password, base_url=cws_address)
    browser.login(lr)
    SubmitRequest(browser=browser,
                  task=(int(t_id), t_short),
                  submission_format=submission_format,
                  filenames=file_name,
                  language=language,
                  base_url=cws_address).execute()
    shutil.rmtree(temp_dir)
def submit(timestamp, username, t_id, t_short, files, base_url):
    """Execute the request for a submission.

    timestamp (int): seconds from the start.
    username (string): username issuing the submission.
    t_id (string): id of the task.
    t_short (string): short name of the task.
    files ([string]): list of filenames of submitted files.
    base_url (string): http address of CWS.

    """
    print("\n%s - Submitting for %s on task %s" %
          (to_time(timestamp), username, t_short),
          end='')
    browser = Browser()
    browser.set_handle_robots(False)
    LoginRequest(browser, username, "", base_url=base_url).execute()
    SubmitRequest(browser, (int(t_id), t_short),
                  filename=files[0],
                  base_url=base_url).execute()