00001
00002
00003
00004
00005
00006
00007
00008 class iStatsSvc:
00009 "Python Interface to IStatisticsSvc"
00010 _statsSvc = None
00011 def __init__(self, alg, path = ""):
00012 self.alg = alg
00013 self.defaultPath = path
00014 self.data = {}
00015 return
00016
00017 def isInitialized(self):
00018 if self.__class__._statsSvc == None:
00019 return False
00020 return True
00021
00022 def initialize(self):
00023 if not self.isInitialized():
00024 statsSvc = self.alg.svc("IStatisticsSvc","StatisticsSvc")
00025 if statsSvc == None:
00026 self.alg.error("Failed to initialize statistics service")
00027 else:
00028
00029 self.__class__._statsSvc = statsSvc
00030 return
00031
00032 def _key2path(self,key):
00033 if key[0] != '/':
00034 key = self.defaultPath + '/' + key
00035 return key
00036
00037 def __setitem__(self,key,value):
00038 self.alg.debug('iStatsSvc.__setitem__(%s,%s)'%(key,value))
00039 if not self.isInitialized(): self.initialize()
00040 key = self._key2path(key)
00041 if self.data.has_key(key):
00042 raise KeyError, 'key "%s" already set'%key
00043 self.__class__._statsSvc.put(key,value)
00044 self.data[key] = value
00045 return
00046
00047 def __getitem__(self,key):
00048 self.alg.debug('iStatsSvc.__getitem__(%s)'%(key))
00049 if not self.isInitialized(): self.initialize()
00050 key = self._key2path(key)
00051 if self.data.has_key(key):
00052 return self.data[self._key2path(key)]
00053 return self.__class__._statsSvc.get(key)