Exemplo n.º 1
0
    def GetAttDataBetweenDates(self, argin):
        """
        Arguments to be AttrName, StartDate, StopDate, Synchronous
        
        If Synchronous is missing or False, data is buffered into attributes, which names are returned
        If True or Yes, all the data is returned when ready
        
        Data returned will be (rows,[t0,v0,t1,v1,t2,v2,...])
        """
        print time.ctime() + "In ", self.get_name(
        ), "::GetAttDataBetweenDates(%s)" % argin
        #    Add your own code here
        size = 0
        aname = argin[0]
        tag = self.attr2tag(aname)
        dates = self.dates2times(argin[1:3])
        RW = False
        synch = fn.searchCl('yes|true', str(argin[3:4]))
        attrs = [tag, tag + '_r', tag + '_w', tag +
                 '_t'] if RW else [tag, tag + '_r', tag + '_w', tag + '_t']

        self.reader.get_attribute_values(
            aname, (lambda v: self.reader_hook(aname, v)),
            dates[0],
            dates[1],
            decimate=True,
            cache=self.UseApiCache)
        self.counter += 1
        print(self.counter)

        argout = [fn.shape(attrs), [a for a in attrs]]

        if not synch:
            print '\t%s' % argout
            return argout

        else:
            while not self.IsDataReady(aname):
                fandango.wait(0.1)
            data = self.AttrData[aname][-1]
            for t, v in data:
                argout.append(t)
                argout.extend(fn.toSequence(v))
            return [fn.shape(data), argout]
Exemplo n.º 2
0
 def GetAttDataBetweenDates(self, argin):
     """
     Arguments to be AttrName, StartDate, StopDate, Synchronous
     
     If Synchronous is missing or False, data is buffered into attributes, which names are returned
     If True or Yes, all the data is returned when ready
     
     Data returned will be (rows,[t0,v0,t1,v1,t2,v2,...])
     """
     print time.ctime()+"In ", self.get_name(), "::GetAttDataBetweenDates(%s)"%argin
     #    Add your own code here
     size = 0
     aname = argin[0]
     tag = self.attr2tag(aname)
     dates = self.dates2times(argin[1:3])
     RW = False
     synch = fn.searchCl('yes|true',str(argin[3:4]))
     attrs = [tag,tag+'_r',tag+'_w',tag+'_t'] if RW else [tag,tag+'_r',tag+'_w',tag+'_t']
     
     self.reader.get_attribute_values(aname,
         (lambda v: self.reader_hook(aname,v)),dates[0],dates[1],
         decimate=True, cache=self.UseApiCache)
     self.counter+=1
     print(self.counter)
     
     argout = [fn.shape(attrs),[a for a in attrs]]
     
     if not synch:
       print '\t%s'%argout
       return argout
   
     else:
       while not self.IsDataReady(aname):
         fandango.wait(0.1)
       data = self.AttrData[aname][-1]
       for t,v in data:
         argout.append(t)
         argout.extend(fn.toSequence(v))
       return [fn.shape(data),argout]
Exemplo n.º 3
0
    def load_attributes(self,
                        servfilter,
                        devfilter,
                        attrfilter,
                        warn=True,
                        exclude=('dserver', 'tango*admin', 'sys*database',
                                 'tmp', 'archiving')):
        tracer('In load_attributes(%s,%s,%s)' %
               (servfilter, devfilter, attrfilter))

        servfilter, devfilter, attrfilter = servfilter.replace(
            ' ',
            '*').strip(), devfilter.replace(' ',
                                            '*'), attrfilter.replace(' ', '*')
        attrfilter = attrfilter or 'state'
        devfilter = devfilter or attrfilter
        archive = self.archivecheck.isChecked()
        all_devs = self.all_devices if not archive else self.archdevs
        all_devs = [
            d for d in all_devs
            if not any(d.startswith(e) for e in exclude) or any(
                d.startswith(e) and fun.matchCl(e, devfilter) for e in exclude)
        ]
        if servfilter.strip('.*'):
            sdevs = map(str.lower,
                        fandango.Astor(servfilter).get_all_devices())
            all_devs = [d for d in all_devs if d in sdevs]
        #print('In load_attributes(%s,%s,%s): Searching through %d %s names'
        #%(servfilter,devfilter,attrfilter,len(all_devs),
        #'server' if servfilter else 'device'))
        if devfilter.strip().strip('.*'):
            devs = [
                d for d in all_devs
                if (fandango.searchCl(devfilter, d, extend=True))
            ]
            print('\tFound %d devs, Checking alias ...' % (len(devs)))
            alias, alias_devs = [], []
            if '&' in devfilter:
                alias = self.all_alias
            else:
                for df in devfilter.split('|'):
                    alias.extend(
                        self.tango.get_device_alias_list('*%s*' % df.strip()))
            if alias:
                print('\t%d alias found' % len(alias))
                alias_devs.extend(self.alias_devs[a] for a in alias
                                  if fun.searchCl(devfilter, a, extend=True))
                print('\t%d alias_devs found' % len(alias_devs))
                #if not self.alias_devs:
                #self.alias_devs =  dict((str(self.tango.get_device_alias(a)).lower(),a) for a in self.all_alias)
                #devs.extend(d for d,a in self.alias_devs.items() if fandango.searchCl(devfilter,a) and (not servfilter or d in all_devs))
                devs.extend(d for d in alias_devs
                            if not servfilter.strip('.*') or d in all_devs)
        else:
            devs = all_devs

        devs = sorted(set(devs))
        self.matching_devs = devs
        print('In load_attributes(%s,%s,%s): %d devices found' %
              (servfilter, devfilter, attrfilter, len(devs)))

        if False and not len(devs) and not archive:
            #Devices do not actually exist, but may exist in archiving ...
            #Option disabled, was mostly useless
            self.archivecheck.setChecked(True)
            return self.load_attributes(servfilter,
                                        devfilter,
                                        attrfilter,
                                        warn=False)

        if len(devs) > self.MAX_DEVICES and warn:
            Qt.QMessageBox.warning(
                self, "Warning",
                "Your search (%s,%s) matches too many devices!!! (%d); please refine your search\n\n%s\n..."
                % (devfilter, attrfilter, len(devs), '\n'.join(devs[:30])))
            return {}
        elif warn and len(devs) > 15:
            r = Qt.QMessageBox.warning(
                self, "Message", "Your search (%s,%s) matches %d devices." %
                (devfilter, attrfilter, len(devs)),
                Qt.QMessageBox.Ok | Qt.QMessageBox.Cancel)
            if r == Qt.QMessageBox.Cancel:
                return {}

        self.matching_attributes = {
        }  #{attribute: (device,alias,attribute,label)}
        failed_devs = []
        for d in sorted(devs):
            try:
                dp = taurus.Device(d)
                if not archive:
                    dp.ping()
                    tcs = [t for t in dp.get_attribute_list()]
                else:
                    tcs = [
                        a.split('/')[-1] for a in self.archattrs
                        if a.startswith(d + '/')
                    ]
                matches = [
                    t for t in tcs
                    if fandango.searchCl(attrfilter, t, extend=True)
                ]
                for t in sorted(tcs):
                    if not self.archivecheck.isChecked() or not matches:
                        label = dp.get_attribute_config(t).label
                    else:
                        label = t
                    if t in matches or fandango.searchCl(
                            attrfilter, label, extend=True):
                        if d in self.alias_devs: alias = self.alias_devs[d]
                        else:
                            try:
                                alias = str(self.tango.get_alias(d))
                            except:
                                alias = ''
                        self.matching_attributes['%s/%s' % (d, t)] = (d, alias,
                                                                      t, label)
                        if warn and len(self.matching_attributes
                                        ) > self.MAX_ATTRIBUTES:
                            Qt.QMessageBox.warning(
                                self, "Warning",
                                "Your search (%s,%s) matches too many attributes!!! (%d); please refine your search\n\n%s\n..."
                                % (devfilter, attrfilter,
                                   len(self.matching_attributes), '\n'.join(
                                       sorted(self.matching_attributes.keys())
                                       [:30])))
                            return {}
            except:
                print('load_attributes(%s,%s,%s => %s) failed!' %
                      (servfilter, devfilter, attrfilter, d))
                failed_devs.append(d)
                if attrfilter in ('state', '', '*', '**'):
                    self.matching_attributes[d + '/state'] = (
                        d, d, 'state', None
                    )  #A None label means device-not-readable

        if warn and len(self.matching_attributes) > 30:
            r = Qt.QMessageBox.warning(
                self, "Message", "(%s) matches %d attributes." %
                (attrfilter, len(self.matching_attributes)),
                Qt.QMessageBox.Ok | Qt.QMessageBox.Cancel)
            if r == Qt.QMessageBox.Cancel:
                return {}
        if not len(self.matching_attributes):
            Qt.QMessageBox.warning(
                self, "Warning",
                "No matching attribute has been found in %s." %
                ('Archiving DB'
                 if archive else 'Tango DB (try Archiving option)'))
        if failed_devs:
            print('\t%d failed devs!!!: %s' % (len(failed_devs), failed_devs))
            if warn:
                Qt.QMessageBox.warning(
                    self, "Warning",
                    "%d devices were not running:\n" % len(failed_devs) +
                    '\n'.join(failed_devs[:10] +
                              (['...'] if len(failed_devs) > 10 else [])))

        tracer('\t%d attributes found' % len(self.matching_attributes))
        return self.matching_attributes
Exemplo n.º 4
0
    import fandango
    print 'ReleaseNumber = %s'%str(fandango.RELEASE)
    from fandango import *
    import fandango.functional as fun
    print '\n\n'+m+': OK'
except Exception,e:
    traceback.print_exc()
    print m+': KO!'
    sys.exit(1)

#Testing fandango.$module passed as argument
a = fun.first(sys.argv[1:],'*')

try:
    m = 'fandango.functional'
    if not fun.searchCl(a,m): raise Skip()

    assert fun.searchCl('id24eu & xbpm','id24eu_XBPM_naaa',extend=True)
    assert not fun.searchCl('id24eu & !xbpm','id24eu_XBPM_naaa',extend=True)
    assert fun.searchCl('id24eu & !xbpm','id24eu_PM_naaa',extend=True)
    assert not fun.searchCl('id24eu & xbpm','id24eu_PM_naaa',extend=True)
    assert None is fun.first([],None)
    assert 1 is fun.first((i for i in range(1,3)))
    assert 2 is fun.last((i for i in range(1,3)))
    assert 0 is fun.last([],default=0)
    print m+': OK'
except Skip:pass
except Exception,e: 
    traceback.print_exc()
    print m+': KO!'
    sys.exit(1)
Exemplo n.º 5
0
    import fandango
    print 'ReleaseNumber = %s' % str(fandango.RELEASE)
    from fandango import *
    import fandango.functional as fun
    print '\n\n' + m + ': OK'
except Exception, e:
    traceback.print_exc()
    print m + ': KO!'
    sys.exit(1)

#Testing fandango.$module passed as argument
a = fun.first(sys.argv[1:], '*')

try:
    m = 'fandango.functional'
    if not fun.searchCl(a, m): raise Skip()

    assert fun.searchCl('id24eu & xbpm', 'id24eu_XBPM_naaa', extend=True)
    assert not fun.searchCl('id24eu & !xbpm', 'id24eu_XBPM_naaa', extend=True)
    assert fun.searchCl('id24eu & !xbpm', 'id24eu_PM_naaa', extend=True)
    assert not fun.searchCl('id24eu & xbpm', 'id24eu_PM_naaa', extend=True)
    assert None is fun.first([], None)
    assert 1 is fun.first((i for i in range(1, 3)))
    assert 2 is fun.last((i for i in range(1, 3)))
    assert 0 is fun.last([], default=0)
    print m + ': OK'
except Skip:
    pass
except Exception, e:
    traceback.print_exc()
    print m + ': KO!'