Merge branch 'master' of ssh://naparuba@shinken.git.sourceforge.net/gitroot/shinken...
[shinken.git] / shinken / singleton.py
blobb8d41440705a1ef83ea2a1e4e4244982d1b8d76c
1 #!/usr/bin/env python
2 #Copyright (C) 2009-2010 :
3 # Gabes Jean, naparuba@gmail.com
4 # Gerhard Lausser, Gerhard.Lausser@consol.de
5 # Gregory Starck, g.starck@gmail.com
7 #This file is part of Shinken.
9 #Shinken is free software: you can redistribute it and/or modify
10 #it under the terms of the GNU Affero General Public License as published by
11 #the Free Software Foundation, either version 3 of the License, or
12 #(at your option) any later version.
14 #Shinken is distributed in the hope that it will be useful,
15 #but WITHOUT ANY WARRANTY; without even the implied warranty of
16 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 #GNU Affero General Public License for more details.
19 #You should have received a copy of the GNU Affero General Public License
20 #along with Shinken. If not, see <http://www.gnu.org/licenses/>.
23 #The classic Singleton class. So all instance of this class will be the same
24 #instance in fact.
26 class Singleton(type):
27 def __init__(cls, name, bases, dict):
28 print "Init de singleton"
29 super(Singleton, cls).__init__(name, bases, dict)
30 cls.instance = None
32 def __call__(cls, *args, **kw):
33 if cls.instance is None:
34 cls.instance = super(Singleton, cls).__call__(*args, **kw)
35 return cls.instance