forked from ungleich-public/cdist
only one instance of each named type
Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
This commit is contained in:
parent
b505eb1af8
commit
a7a086e29b
1 changed files with 10 additions and 1 deletions
|
@ -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 '<Type %s>' % self.name
|
||||
|
||||
|
|
Loading…
Reference in a new issue