You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
896 B

import sys
sys.path.append("..")
import os
from ssh_config_utils.parser import parse_config_text
from ssh_config_utils.host import Host, GlobalHost
from constants import user_ssh_config_path
with open(user_ssh_config_path) as your_ssh_config_file:
text = your_ssh_config_file.read()
data = parse_config_text(text)
def from_parsed_config_file(data):
global_host = None
hosts = []
for host_data in data:
for key, values in host_data.items():
if len(values) == 1:
host_data[key] = values[0]
if host_data["host"] == "*":
if global_host is None:
del host_data["host"]
global_host = GlobalHost(host_data)
else:
name = host_data.pop("host")
hosts.append(Host(name, host_data))
return global_host, hosts
global_host, hosts = from_parsed_config_file(data)