def on_save(self, args=None): host_info = HostInfo(self.connection_name.edit_text) host_info.ip = self.ip.edit_text host_info.username = self.username.edit_text host_info.port = self.port.edit_text host_info.identity_file = self.id_file.edit_text host_info.dynamic_forward = self.dynamic_forward.edit_text host_info.local_forward = (self.local_forward_from.edit_text, self.local_forward_to.edit_text) host_info.remote_forward = (self.remote_forward_from.edit_text, self.remote_forward_to.edit_text) self.target.name = self.connection_name.edit_text self.target.hostinfo = host_info self.parent.add_child(self.target) self.on_close(self.target)
def load_from_file(): hosts = [] with open(Config.__get_or_create_config_file(), "r") as file: host_info = None for f_line in file: line = f_line.strip() if line.startswith('#') or not line: continue kv = list(filter(None, line.split(' '))) key = kv[0].lower() # SSH config file keys are case insensitive try: if key == "host": if host_info is not None: hosts.append(host_info) if len(kv) == 1: host_info = None else: host_info = HostInfo(kv[1]) if key == "hostname" and host_info: host_info.ip = kv[1] if key == "user" and host_info: host_info.username = kv[1] if key == "port" and host_info: host_info.port = kv[1] if key == "identityfile" and host_info: host_info.identity_file = kv[1] if key == "dynamicforward" and host_info: host_info.dynamic_forward = kv[1] if key == "localforward" and host_info: host_info.local_forward = (kv[1], kv[2]) if key == "remoteforward" and host_info: host_info.remote_forward = (kv[1], kv[2]) except IndexError: continue if host_info is not None: hosts.append(host_info) return Config.__construct_tree(hosts)