Ejemplo n.º 1
0
def save():
 if application.get_host():
  if not os.path.isdir(config_dir):
   try:
    os.makedirs(config_dir)
   except Exception as e:
    return logger.exception(e)
  config_file = os.path.join(config_dir, make_filename())
  logger.info("Writing configuration for %s:%s to %s.", application.get_host(), application.get_port(), config_file)
  try:
   with open(config_file, "w") as f:
    json.dump(application.config.get_dump(), f, indent = 1)
  except Exception as e:
   logger.exception(e)
Ejemplo n.º 2
0
 def SetTitle(self, title = None):
  """Set the window title."""
  if not title:
   title = application.name
  if application.factory.transport.connected:
   connected = 'connected to %s (%s:%s)' % (application.config.get("world", "name"), application.get_host(), application.get_port())
  else:
   connected = 'not connected'
  super(MainFrame, self).SetTitle('%s [%s]' % (title, connected))
Ejemplo n.º 3
0
def load():
 if application.get_host() and os.path.isdir(config_dir):
  config_file = os.path.join(config_dir, make_filename())
  try:
   logger.info("Loading configuration data from %s.", config_file)
   with open(config_file, "r") as f:
    c = application.create_config()
    parse_json(c, json.load(f), create_sections = True, create_options = True)
    application.config = c
    application.config_file = config_file
    application.update_config()
  except IOError:
   logger.warning("No configuration file could be read.")
  except ValueError as v:
   logger.exception(e)
Ejemplo n.º 4
0
def connect(host, port, timeout = 30):
 """Connects to a server.
 
 Arguments:
  host - The host to connect to.
  port - The port to connect on.
  timeout - The time to wait before giving up.
 """
 if connected():
  logger.critical('Already connected to %s:%s.', application.get_host(), application.get_port())
 else:
  config.save()
  output('Connecting to %s:%s.' % (host, port))
  application.config.set("world", "host", host)
  application.config.set("world", "port", port)
  config.load()
  try:
   reactor.connectTCP(host, port, application.factory, timeout = timeout)
  except Exception as e:
   logger.exception(e)
Ejemplo n.º 5
0
def make_filename():
 return "%s-%s%s" % (application.get_host(), application.get_port(), config_ext)