From b841ca3d2e457a48e34a55cfd5dca9eec126fef2 Mon Sep 17 00:00:00 2001 From: Raphael Roberts Date: Wed, 20 Nov 2019 00:30:10 -0600 Subject: [PATCH] Added a HostAlias class based off wrapt.ObjectProxy. Will use this to handle multiple `Host` in config --- requirements.txt | 1 + ssh_config_utils/host.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/requirements.txt b/requirements.txt index e69de29..ba11553 100644 --- a/requirements.txt +++ b/requirements.txt @@ -0,0 +1 @@ +wrapt diff --git a/ssh_config_utils/host.py b/ssh_config_utils/host.py index 6a7b78c..ce3db20 100644 --- a/ssh_config_utils/host.py +++ b/ssh_config_utils/host.py @@ -1,11 +1,46 @@ +import wrapt + from ssh_config_utils.serializer import serialize_host, get_proper_name from ssh_config_utils.parser import CamelCase_to_snake, KEYWORDS_LOWER_TRANSLATE +class HostAlias(wrapt.ObjectProxy): + def __init__(self, name, host): + super().__init__(host) + self._self_name = name + host.aliases.append(self) + + @property + def name(self): + return self._self_name + + @name.setter + def name(self, name): + self._self_name = name + + @name.deleter + def name(self): + del self._self_name + + @property + def target(self): + return self.__wrapped__ + + @target.setter + def target(self, target): + try: + self.aliases.remove(self) + except ValueError: + pass + self.__wrapped__ = target + self.aliases.append(self) + + class Host: __ignore__ = {"aliases", "name", "options", "parent"} def __init__(self, name: str, options): + self.aliases = [] self.name = name self.options = options self.parent = None