# ssh_manager/edit_host.py import os from collections import OrderedDict from .utils import print_error, print_warning, print_info def load_config_file(file_path): """ Parse the given config file into a list of host blocks (OrderedDict). """ blocks = [] host_data = None try: with open(file_path, 'r') as f: lines = f.readlines() except Exception as e: print_error(f"Error reading SSH config file {file_path}: {e}") return blocks for line in lines: stripped_line = line.strip() if not stripped_line or stripped_line.startswith('#'): continue if stripped_line.lower().startswith('host '): host_labels = stripped_line.split()[1:] for label in host_labels: if '*' not in label: if host_data: blocks.append(host_data) host_data = OrderedDict({'Host': label}) break elif host_data: if ' ' in stripped_line: key, value = stripped_line.split(None, 1) host_data[key] = value.strip() if host_data: blocks.append(host_data) return blocks def edit_host(conf_dir): """ Let the user update fields for an existing host in ~/.ssh/conf/