From f491afaeeff097e975365e4c7771b4220ea21e6c Mon Sep 17 00:00:00 2001 From: Andrew Gaffney Date: Mon, 12 Jan 2009 16:04:37 -0600 Subject: [PATCH] Add base singleton class definition --- ChangeLog | 4 ++++ modules/catalyst/__init__.py | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/ChangeLog b/ChangeLog index 3285b35f..376df557 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,10 @@ # Copyright 2002-2009 Gentoo Foundation; 2008-2009 Various authors (see AUTHORS) # Distributed under the GPL v2 + 12 Jan 2009; Andrew Gaffney + modules/catalyst/__init__.py: + Add base singleton class definition + 12 Jan 2009; Andrew Gaffney modules/catalyst/lock.py: More replacements of print statement with msg() diff --git a/modules/catalyst/__init__.py b/modules/catalyst/__init__.py index a7d2aaff..3b1ea8d1 100644 --- a/modules/catalyst/__init__.py +++ b/modules/catalyst/__init__.py @@ -15,3 +15,16 @@ error = catalyst.error spawn = catalyst.spawn target = catalyst.target config = catalyst.config + +""" +This class implements a proper singleton. This is useful for having a "global" +var with config and spec values instead of passing them around between objects +and functions +""" +class Singleton(object): + + def __new__(type): + if not '_the_instance' in type.__dict__: + type._the_instance = object.__new__(type) + return type._the_instance + -- 2.26.2