- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
class DataModel(dict):
_SCHEME_VERSION = 0
_transform = dict()
_additional = dict()
_migration = None
def __init__(self, data=None, network=None, conf=None):
if network and conf:
_scheme = map(lambda x: x.strip(), conf.get(network).keys())
_map = map(lambda x: x.strip(), conf.get(network).values())
self._scheme = int(conf._scheme)
map(lambda x: setattr(self, x[0], data.get(x[1], None)),
[(_scheme[i], _map[i]) for i in xrange(0,len(_map))])
if self._transform.get(network, False):
map(lambda x: setattr(self, x, getattr(self._transform[network], x)(getattr(self, x))),
[k for k in self._transform[network].__dict__.keys() if not k.startswith('__')])
else:
dict.__init__(self, data)
if self.get('_scheme', 0)<self._SCHEME_VERSION and self._migration is not None:
k = [int(k.split('_')[1]) for k in self._migration.__dict__.keys() if not k.startswith('__')]
k.sort()
[k.remove(x) for x in k if x<=self.get('_scheme', 0)]
map(lambda x: getattr(self._migration, 'scheme_%s' % x)(self), k)
self._scheme = self._SCHEME_VERSION
map(lambda x: setattr(self, x, getattr(self._additional, x)(self)),
[k for k in self._additional.__dict__.keys() if not k.startswith('__')])
def __setattr__(self, name, val):
if name in self.__dict__:
self.__dict__[name]= val
else:
self[name] = val
def __getattr__(self, name):
if name in self.__dict__:
return self.__dict__[name]
else:
return self[name]