def init_from_db(self,db=None,load_devices=False): """ Gets name, classes, devices, host, level information from Tango Database. """ self._db = db or (self._db if hasattr(self,'_db') else PyTango.Database()) #print ('init_from_db(%s,%s,%s)'%(self.name,get_tango_host(self._db),load_devices)) self.info = self._db.get_server_info(self.name) di = get_device_info('dserver/'+self.name,db=self._db) #get_server_info() must be combined with get_device_info to obtain the real name of the launcher self.name = di.server self.update_level(self.info.host,self.info.level) if load_devices: self.get_classes()
def init_from_db(self, db=None, load_devices=False): """ Gets name, classes, devices, host, level information from Tango Database. """ self._db = db or (self._db if hasattr(self, '_db') else PyTango.Database()) #print ('init_from_db(%s,%s,%s)'%(self.name,get_tango_host(self._db),load_devices)) self.info = self._db.get_server_info(self.name) di = get_device_info( 'dserver/' + self.name, db=self._db ) #get_server_info() must be combined with get_device_info to obtain the real name of the launcher self.name = di.server self.update_level(self.info.host, self.info.level) if load_devices: self.get_classes()
import fandango.excepts as f_excepts assert 1 == f_excepts.trial(lambda:1/1,lambda e:10,return_exception=True) assert 10 == f_excepts.trial(lambda:1/0,lambda e:10,return_exception=True) print m+': OK' except Skip:pass except Exception,e: traceback.print_exc() print m+': KO!' sys.exit(1) try: m = 'fandango.tango' if not fun.searchCl(a,m): raise Skip() import fandango.tango as f_tango assert isinstance(f_tango.get_proxy('sys/database/2'),fandango.tango.PyTango.DeviceProxy) assert isinstance(f_tango.get_proxy('sys/database/2/state'),fandango.tango.PyTango.AttributeProxy) assert isinstance(f_tango.TGet(),fandango.tango.PyTango.Database) assert isinstance(f_tango.TGet(f_tango.TGet('sys/database/*')[0]),fandango.tango.PyTango.DeviceProxy) assert isinstance(f_tango.TGet(f_tango.TGet('sys/database/*/st[a]te')[0]),int) assert f_tango.get_device_info('sys/database/2').dev_class == 'DataBase' assert fandango.isNaN(f_tango.TangoEval(trace=False).eval('da/do/di/du',_raise=fandango.NaN)) assert fandango.tango.TangoEval(trace=False).eval('sys/database/2',_raise=None) in (0,None) print m+': OK' except Skip:pass except Exception,e: traceback.print_exc() print m+': KO!' sys.exit(1) sys.exit(0)
def event_hook(self, src, type_, value, locked=False): """ EventListener.eventReceived will jump to this method Method to implement the event notification Source will be an object, type a PyTango EventType, evt_value an AttrValue """ tt0 = now() tsets = 0 array = {} try: # convert empty arrays to [] , pass exceptions rvalue = getAttrValue(value, Exception) error = (getattr(value, 'err', False) or isinstance(rvalue, (type(None), Exception, PyTango.DevError))) self.info('event_hook(\n\tsrc=%s,\n\ttype=%s)' % (src, type_)) ## eventReceived already log that error = error or check_multi_host(src.full_name, raise_=False) if locked is True: self.lock.acquire() if src.simple_name in self.api.alarms: av = self.get_alarm(src.full_name) alarms = [av.tag] else: m = parse_tango_model(src.device) d = m['devicename'] dev = self.api.get_device(d) assert dev, ('UnknownDevice:\n\n\t%s' % '\n\n\t'.join( "%s" % str(s) for s in (src.device, m, d, dev, self.api.devices.keys()))) alarms = dev.alarms.keys() check = check_device_cached(src.device) if check in (None, 'FAULT', 'UNKNOWN'): error = 'AlarmView[%s] returned %s state' % (src.device, check) self.warning(error) if not error: #self.debug('rvalue = %s(%s)'%(type(rvalue),str(rvalue))) r = rvalue[0] if rvalue else '' splitter = ';' if ';' in r else ':' array = dict( (l.split(splitter)[0].split('=')[-1], l) for l in rvalue) self.debug('%s.rvalue = %s' % (src, fd.log.pformat(array))) else: l = self.info #(self.info('ERROR','OOSRV') else self.info) devup = get_device_info(src.device).exported s = ('OOSRV', 'ERROR')[bool(devup)] if s == 'ERROR': self.warning('%s seems hung!' % (src.device)) l('event_hook(%s).Error(s=%s,%s): %s' % (src, s, devup, rvalue)) assert len(alarms), 'EventUnprocessed!' for a in alarms: av = self.get_alarm(a) #self.debug('event_hook() %s was %s since %s(%s)' #%(a,av._state,av._time, #time2str(av._time,us=True))) av.updated = now() if error: #['CantConnectToDevice' in str(rvalue)] s = ('OOSRV', 'ERROR')[bool(devup)] av.set_state(s) av.last_error = str(rvalue) elif isSequence(rvalue): try: EMPTY = '' row = array.get(av.tag, EMPTY) #self.debug('[%s]:\t"%s"'%(av.tag,row or EMPTY)) if not row: # Compatibility with PyAlarm < 6.2 if clsearch('activealarms', src.full_name): row = 'NORM' if av.get_enabled() else 'SHLVD' else: self.warning('%s Not found in %s(%s)' % (av.tag, src.full_name, splitter)) ts0 = now() #self.info('%s.set_state(%s)'%(a,row)) av.set_state(row) tsets += now() - ts0 #if av.active: #self.info('%s active since %s' #%(av.tag,fd.time2str(av.active or 0))) except: error = traceback.format_exc() av.last_error = error av.set_state('ERROR') self.warning(error) else: # Not parsing an array value av.set_active((rvalue and av.active) or rvalue) if av.get_model() not in self.values: self.values[av.get_model()] = None self.debug('%s cache initialized' % (av.get_model())) prev = self.values[av.get_model()] curr = av.active if not error else -1 if curr != prev: self.debug( #(self.info if self.verbose else self.debug)( 'event_hook(%s,%s): %s => %s' % (av.tag, av.get_state(), prev, curr)) self.values[av.get_model()] = curr tt, ts, ta = (1e3 * t for t in (now() - tt0, tsets, tsets / len(alarms))) self.info('event_hook() done in %.2e ms ' '(%.2e in set_state, %.2e per alarm)\n' % (tt, ts, ta)) except Exception, e: self.error('AlarmView(%s).event_hook(%s,%s,%s)' % (self.name, src, type_, shortstr(value))) self.error(traceback.format_exc()) self.error(array)
sys.exit(1) try: m = 'fandango.tango' if not fun.searchCl(a, m): raise Skip() import fandango.tango as f_tango assert isinstance(f_tango.get_proxy('sys/database/2'), fandango.tango.PyTango.DeviceProxy) assert isinstance(f_tango.get_proxy('sys/database/2/state'), fandango.tango.PyTango.AttributeProxy) assert isinstance(f_tango.finder(), fandango.tango.PyTango.Database) assert isinstance(f_tango.finder(f_tango.finder('sys/database/*')[0]), fandango.tango.PyTango.DeviceProxy) assert isinstance( f_tango.finder(f_tango.finder('sys/database/*/st[a]te')[0]), int) assert f_tango.get_device_info('sys/database/2').dev_class == 'DataBase' assert fandango.isNaN( f_tango.TangoEval(trace=False).eval('da/do/di/du', _raise=fandango.NaN)) assert fandango.tango.TangoEval(trace=False).eval('sys/database/2', _raise=None) in (0, None) print m + ': OK' except Skip: pass except Exception, e: traceback.print_exc() print m + ': KO!' sys.exit(1) sys.exit(0)