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)
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)
def make_filename(): return "%s-%s%s" % (application.get_host(), application.get_port(), config_ext)
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))