Index: trunk/tools/editor_trends/configuration.py |
— | — | @@ -43,7 +43,23 @@ |
44 | 44 | pass |
45 | 45 | |
46 | 46 | |
| 47 | +class Singleton(type): |
| 48 | + ''' |
| 49 | + Recipe: http://stackoverflow.com/questions/31875/is-there-a-simple-elegant-way-to-define-singletons-in-python |
| 50 | + ''' |
| 51 | + def __init__(cls, name, bases, dict): |
| 52 | + super(Singleton, cls).__init__(name, bases, dict) |
| 53 | + cls.instance = None |
| 54 | + |
| 55 | + def __call__(cls, *args, **kw): |
| 56 | + if cls.instance is None: |
| 57 | + cls.instance = super(Singleton, cls).__call__(*args, **kw) |
| 58 | + return cls.instance |
| 59 | + else: |
| 60 | + return cls.instance |
| 61 | + |
47 | 62 | class Settings(object): |
| 63 | + __metaclass__ = Singleton |
48 | 64 | |
49 | 65 | def __init__(self, debug=True, process_multiplier=1, **kwargs): |
50 | 66 | self.debug = debug |