From a7a086e29bfc2fe02ee575630dc1459005cc3700 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 7 Oct 2011 16:01:02 +0200 Subject: [PATCH] only one instance of each named type Signed-off-by: Steven Armstrong --- lib/cdist/core/type.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/cdist/core/type.py b/lib/cdist/core/type.py index 309528ef..42a74398 100644 --- a/lib/cdist/core/type.py +++ b/lib/cdist/core/type.py @@ -46,6 +46,16 @@ class Type(object): return os.listdir(base_path) + _instances = {} + def __new__(cls, *args, **kwargs): + """only one instance of each named type may exist""" + # name is second argument + name = args[1] + if not name in cls._instances: + instance = super(Type, cls).__new__(cls, *args, **kwargs) + cls._instances[name] = instance + return cls._instances[name] + def __init__(self, base_path, name): self._base_path = base_path self.name = name @@ -64,7 +74,6 @@ class Type(object): self.__required_parameters = None self.__optional_parameters = None - def __repr__(self): return '' % self.name