Example #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)
        lr = LoginRequest(cws_browser, username, password, base_url=base_url)
        lr.step()

    sr = SubmitRequest(cws_browser, task, base_url=base_url,
                       submission_format_element=submission_format_element,
                       filename=filename)
    sr.step()

    submission_id = sr.get_submission_id()

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

    return submission_id
Example #2
0
    def token(self, timestamp, username, password, t_id, t_short,
              submission_num):
        """Execute the request for releasing test 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.
        submission_num (string): id of the submission to release test.

        """
        logger.info("%s - Playing token for %s on task %s" %
                    (to_time(timestamp), username, t_short))
        browser = Browser()
        browser.set_handle_robots(False)
        step(
            LoginRequest(browser,
                         username,
                         password,
                         base_url=self.cws_address))
        step(
            TokenRequest(browser, (int(t_id), t_short),
                         submission_num=submission_num,
                         base_url=self.cws_address))
Example #3
0
    def act(self):
        # Start with logging in and checking to be logged in
        self.do_step(HomepageRequest(self.browser,
                                     self.username,
                                     loggedin=False,
                                     base_url=self.base_url))
        self.do_step(LoginRequest(self.browser,
                                  self.username,
                                  self.password,
                                  base_url=self.base_url))
        self.do_step(HomepageRequest(self.browser,
                                     self.username,
                                     loggedin=True,
                                     base_url=self.base_url))

        # Then keep forever stumbling across user pages
        while True:
            choice = random.random()
            task = random.choice(self.tasks)
            if choice < 0.1 and self.submissions_path is not None:
                self.do_step(SubmitRandomRequest(
                    self.browser,
                    task,
                    base_url=self.base_url,
                    submissions_path=self.submissions_path))
            elif choice < 0.6 and task[2] != []:
                self.do_step(TaskStatementRequest(self.browser,
                                                  task[1],
                                                  random.choice(task[2]),
                                                  base_url=self.base_url))
            else:
                self.do_step(TaskRequest(self.browser,
                                         task[1],
                                         base_url=self.base_url))
Example #4
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()
Example #5
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))

        submit_files = []
        for f in files:
            filename_to_send = f["filename"]
            if language != None:
                filename_to_send = f["filename"].replace("%%l", language)
            submit_files.append([ f["filename"],
                    filename_to_send,
                    os.path.join(self.import_source, "files", f["digest"])
                    ])

        browser = Browser()
        browser.set_handle_robots(False)
        step(LoginRequest(browser, username, password,
                          base_url=self.cws_address))
        step(SubmitMultifileRequest(browser,
                           (int(t_id), t_short),
                           files=files,
                           base_url=self.cws_address))
Example #6
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
Example #7
0
def release_test(username, password, task, submission_num, base_url=None):
    browser = mechanize.Browser()
    browser.set_handle_robots(False)

    LoginRequest(browser, username, password, base_url=base_url).execute()
    TokenRequest(browser,
                 task,
                 base_url=base_url,
                 submission_num=submission_num).execute()
Example #8
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]))
Example #9
0
def release_test(username, password, task, submission_id, 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(TokenRequest(browser, task, base_url=base_url, submission_num=submission_num))
Example #10
0
 def login(self):
     """Log in and check to be logged in."""
     self.do_step(
         HomepageRequest(self.browser,
                         self.username,
                         loggedin=False,
                         base_url=self.base_url))
     self.do_step(
         LoginRequest(self.browser,
                      self.username,
                      self.password,
                      base_url=self.base_url))
     self.do_step(
         HomepageRequest(self.browser,
                         self.username,
                         loggedin=True,
                         base_url=self.base_url))
Example #11
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)
Example #12
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()
def token(timestamp, username, t_id, t_short, submission_num, base_url):
    """Execute the request for releasing test 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.
    submission_num (string): id of the submission to release test.
    base_url (string): http address of CWS.

    """
    print("\n%s - Playing token 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()
    TokenRequest(browser, (int(t_id), t_short),
                 submission_num=submission_num,
                 base_url=base_url).execute()
Example #15
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