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

  1. import sys
  2. sys.path.append("..")
  3. import os
  4. from ssh_config_utils.parser import parse_config_text
  5. from ssh_config_utils.host import Host, GlobalHost
  6. from constants import user_ssh_config_path
  7. with open(user_ssh_config_path) as your_ssh_config_file:
  8. text = your_ssh_config_file.read()
  9. data = parse_config_text(text)
  10. def from_parsed_config_file(data):
  11. global_host = None
  12. hosts = []
  13. for host_data in data:
  14. for key, values in host_data.items():
  15. if len(values) == 1:
  16. host_data[key] = values[0]
  17. if host_data["host"] == "*":
  18. if global_host is None:
  19. del host_data["host"]
  20. global_host = GlobalHost(host_data)
  21. else:
  22. name = host_data.pop("host")
  23. hosts.append(Host(name, host_data))
  24. return global_host, hosts
  25. global_host, hosts = from_parsed_config_file(data)