Пример #1
0
  def __init__(self,
               conf,
               host = DEFAULT_HOST,
               port = DEFAULT_PORT,
               tunnel = DEFAULT_TUNNEL,
               company = DEFAULT_COMPANY,
               max_heap_size = DEFAULT_MAX_HEAP_SIZE,
               jnlp_xml = None):
    if jnlp_xml:
      jar_output = None
      jar_input = None
      try:
        jnlp = parseString(jnlp_xml)

        resources = jnlp.getElementsByTagName('resources')[0]
        j2se = resources.getElementsByTagName('j2se')[0]
        jar = resources.getElementsByTagName('jar')[0]

        # j2se_version = 
        max_heap_size = j2se.getAttribute('max-heap-size')
        jar_url = jar.getAttribute('href')

        application_desc = jnlp.getElementsByTagName('application-desc')[0]
        args = application_desc.getElementsByTagName('argument')

        host = get_node_text(args[0])
        port = int(get_node_text(args[1]))
        tunnel = get_node_text(args[2])
        company = get_node_text(args[3])

        # TODO: This should only be done if no jar exists or the jar that does is more than one day old
        jar_output = open(conf.app_data_join('ContestApplet.jar'), 'wb')
        jar_input = urllib2.urlopen(jar_url)
        jar_output.write(jar_input.read())
      except:
        print 'Couldn\'t parse jnlp!'
      finally:
        if jar_input:
          jar_input.close()
        if jar_output:
          jar_output.close()

    class_path = conf.app_data_join('ContestApplet.jar')

    from libsrmtrainer_arena_controller import ArenaControllerImpl
    self._impl = ArenaControllerImpl(host=host,
                                     port=port,
                                     tunnel=tunnel,
                                     company=company,
                                     jvm_args=['-Djava.class.path=%s' % class_path,
                                               '-Xmx%s' % max_heap_size])
Пример #2
0
class ArenaController:

  def __init__(self,
               conf,
               host = DEFAULT_HOST,
               port = DEFAULT_PORT,
               tunnel = DEFAULT_TUNNEL,
               company = DEFAULT_COMPANY,
               max_heap_size = DEFAULT_MAX_HEAP_SIZE,
               jnlp_xml = None):
    if jnlp_xml:
      jar_output = None
      jar_input = None
      try:
        jnlp = parseString(jnlp_xml)

        resources = jnlp.getElementsByTagName('resources')[0]
        j2se = resources.getElementsByTagName('j2se')[0]
        jar = resources.getElementsByTagName('jar')[0]

        # j2se_version = 
        max_heap_size = j2se.getAttribute('max-heap-size')
        jar_url = jar.getAttribute('href')

        application_desc = jnlp.getElementsByTagName('application-desc')[0]
        args = application_desc.getElementsByTagName('argument')

        host = get_node_text(args[0])
        port = int(get_node_text(args[1]))
        tunnel = get_node_text(args[2])
        company = get_node_text(args[3])

        # TODO: This should only be done if no jar exists or the jar that does is more than one day old
        jar_output = open(conf.app_data_join('ContestApplet.jar'), 'wb')
        jar_input = urllib2.urlopen(jar_url)
        jar_output.write(jar_input.read())
      except:
        print 'Couldn\'t parse jnlp!'
      finally:
        if jar_input:
          jar_input.close()
        if jar_output:
          jar_output.close()

    class_path = conf.app_data_join('ContestApplet.jar')

    from libsrmtrainer_arena_controller import ArenaControllerImpl
    self._impl = ArenaControllerImpl(host=host,
                                     port=port,
                                     tunnel=tunnel,
                                     company=company,
                                     jvm_args=['-Djava.class.path=%s' % class_path,
                                               '-Xmx%s' % max_heap_size])

  def show(self):
    assert self._impl is not None

    self._impl.show()

  def login(self, username, password):
    assert self._impl is not None

    self._impl.login(username, password)

  @property
  def logged_in(self):
    assert self._impl is not None

    return self._impl.is_logged_in() == 1

  def set_connection_type(self, id):
    assert self._impl is not None

    self._impl.set_connection_type(id)

  def register(self, round):
    assert self._impl is not None

    print ('registering!')
    pass

  def get_active_rounds(self):
    assert self._impl is not None
  
    data = self._impl.get_active_rounds()

    result = []
    for row in data:
      result.append(ActiveRound(tcid=row[0], title=row[1]))

    return result

  def destroy(self):
    if not self._impl:
      return

    self._impl.destroy()
    
    self._impl = None