Add : child_dependencies/ parent_dependencies in livestatus module.
[shinken.git] / shinken / autoslots.py
blob08d979a5ed87ab36d5ca52c261b8197809eaae66
1 #!/usr/bin/env python
3 # Copyright (C) 2009-2010 :
4 # Gabes Jean, naparuba@gmail.com
5 # Gerhard Lausser, Gerhard.Lausser@consol.de
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/>.
22 """The AutoSlots Class is a MetaClass : it manage how other classes
23 are created (Classes, not instances of theses classes).
24 Here it's role is to create the __slots__ list of the class with
25 all properties of Class.properties and Class.running_properties
26 so we do not have to add manually all properties to the __slots__
27 list when we add a new entry"""
29 class AutoSlots(type):
30 # new is call when we create a new Class
31 # that have metaclass = AutoSlots
32 # CLS is AutoSlots
33 # name is s tring of the Class (like Service)
34 # bases are the Classes of which Class inherits (like SchedulingItem)
35 # dct is the new Class dict (like all method of Service)
36 # Some properties name are not alowed in __slots__ like 2d_coords of
37 # Host, so we must tag them in properties with no_slots
38 def __new__(cls, name, bases, dct):
39 # Thanks to Bertrand Mathieu to the set idea
40 slots = dct.get('__slots__', set())
41 # Now get properties from properties and running_properties
42 if 'properties' in dct:
43 props = dct['properties']
44 slots.update((p for p in props
45 if not props[p].no_slots))
46 if 'running_properties' in dct:
47 props = dct['running_properties']
48 slots.update((p for p in props
49 if not props[p].no_slots))
50 dct['__slots__'] = tuple(slots)
51 return type.__new__(cls, name, bases, dct)