Пример #1
0
  def _create_arena_controller(self):
    conn = None
    jnlp_xml = None
    try:
      conn = TCConnection()
      jnlp_xml = conn.get_arena_jnlp()
    finally:
      if conn:
        conn.close()

    return ArenaController(self.conf, jnlp_xml=jnlp_xml)
Пример #2
0
def create_conn_and_login():
  print ('Logging in...')

  conn = TCConnection()

  loginFailed = True
  while loginFailed:
    username = raw_input('Enter TC user name: ')
    password = getpass.getpass('Enter TC password: ')

    loginFailed = not conn.login(username, password)

  return conn
Пример #3
0
  def on_practice(self, action = None):
    # TODO: check for errors
    provider = None
    tcconn = None
    srm = None
    folder_name = None
    try:
      provider = Provider(self.conf.database_path)

      dlog = PickAnSRMDialog(self.win, provider)
      srm = dlog.run_and_return()

      if not srm:
        return

      srm.problems = provider.get_srm_problems(srm)
      provider.get_srm_test_cases(srm)

      if not srm.problems or len(srm.problems) == 0:
        tcconn = TCConnection()

        # TODO: username should be saved in configuration
        (username, pwd) = GetCredentialsDialog(self.win, tcconn).run_and_return()

        if not tcconn.logged_in:
          return

        try:
          # TODO: need to use future
          tcconn.fill_whole_srm(srm)
        except:
          display_error_msg(self.win, Errors.CANNOT_RETRIEVE)
          return
        
        provider.insert_srm_data(srm)

      # get folder name
      folder_name = provider.folder_for_srm(srm)
    finally:
      if tcconn:
        tcconn.close()
      if provider:
        provider.close()

    # make the srm folder
    folder_path = os.path.join(self.conf.srms_path, folder_name)
    if not os.path.exists(folder_path):
      os.makedirs(folder_path)

    # check if files exist, if they don't exist, generate them
    generator = SolutionGenerator(self.conf)
    paths = self._files_for_srm(srm, folder_path)
    for i in range(0, len(paths)):
      if not os.path.isfile(paths[i]):
        generator.generate(paths[i], 'cpp', srm, srm.problems[i])

    # generate a harness
    harness_path = os.path.join(folder_path, 'harness.cpp')
    if not os.path.isfile(harness_path):
      generator = HarnessGenerator(self.conf)
      generator.generate(harness_path, 'cpp', srm)

    # create a new tab
    stumped_text = DEFAULT_STUMPED_TEXT
    if self.conf.stumped_text:
      stumped_text = self.conf.stumped_text

    ctx = PracticingContext(self._console, self.conf, 'cpp', srm, folder_path)
    tab = SrmTab(ctx, paths, stumped_text)
    tab.add_to_window(self.win, True)