Add base singleton class definition
authorAndrew Gaffney <agaffney@gentoo.org>
Mon, 12 Jan 2009 22:04:37 +0000 (16:04 -0600)
committerAndrew Gaffney <agaffney@gentoo.org>
Mon, 12 Jan 2009 22:04:37 +0000 (16:04 -0600)
ChangeLog
modules/catalyst/__init__.py

index 3285b35f733d7a4e83e690b87883bfee080a2860..376df55773cfbc4138e210b02df93b0e176476bc 100644 (file)
--- 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 <agaffney@gentoo.org>
+  modules/catalyst/__init__.py:
+  Add base singleton class definition
+
   12 Jan 2009; Andrew Gaffney <agaffney@gentoo.org>
   modules/catalyst/lock.py:
   More replacements of print statement with msg()
index a7d2aaff40926dba8da6535d819649d7f8575b11..3b1ea8d18467601baf3bd85e841fbf1ba7c0ac59 100644 (file)
@@ -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
+