Example #1
0
def check_multi_host(model, host=None, raise_=False):
    """ returns True if tango_host in model does not match host """
    h0 = (host or fandango.get_tango_host().split(':')[0]).split('.')[0]
    h1 = parse_tango_model(model).host.split('.')[0]
    r = h0.lower() != h1.lower()
    assert not r or not raise_, '%s!=%s' % (h1, h0)
    return r
Example #2
0
    def setModel(self, model):
        print '*' * 80
        self.info('VaccaProfilePlot.setModel(%s)' % model)
        print '*' * 80
        try:
            #if self._profile_loaded: return
            if (fandango.isSequence(model)
                    or 'attributename' in parse_tango_model(
                        model.split('|')[0])):
                self.info('setting an attribute model')
                TaurusPlot.setModel(self, model)  # model = model[0]# str(
                # model).rsplit('/',1)[0]
            else:
                self.info('setting a composer model')
                assert fandango.check_device(model)
                dev = taurus.Device(model)
                if all(a in map(str.lower, dev.get_attribute_list())
                       for a in ('ccgaxxis', 'ccgpressures', 'ipaxxis',
                                 'ippressures', 'thermoaxxis', 'thermocouples',
                                 'axxispositions', 'axxislabels')):
                    TaurusPlot.setModel(self, [])
                    setup_profile_plot(self, model)
                else:
                    self.warning('%s has not all required attributes' % model)

            if len(self._positions) and len(self._labels):
                self.info('Setting CustomXLabels ...')
                self.setAxisCustomLabels(Qwt5.QwtPlot.xBottom,
                                         zip(self._positions, self._labels),
                                         60)
        except Exception, e:
            traceback.print_exc()
            self.warning('VaccaProfilePlot.setModel(%s) failed!: %s' %
                         (model, e))
Example #3
0
    def update_sources(self):
        self.info('update_sources(%d)' % len(self.alarms))
        olds = self.get_sources()
        news = [self.get_model(s) for s in self.alarms]
        devs = set(parse_tango_model(s)['devicename'] for s in news)
        news = [self.api.devices[d].get_model()
                for d in devs]  #discard single attributes

        for o in olds:
            if o not in news:
                self.remove_source(o)

        for s in news:
            if s not in olds:
                ta = self.add_source(s)

            d = self.api.get_device(parse_tango_model(s)['devicename'])
            if anyendswith(s, d.get_model()):
                d._actives = self.get_source(s)

        return news
Example #4
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)