Exemplo n.º 1
0
 def onRefreshPressed(self):
     fkey = str(self.filterComboBox.currentText())
     fvalue = str(self.filterComboBox2.currentText())
     print 'onRefreshPressed(%s,%s)'%(fkey,fvalue)
     try:
         self.listWidget.blockSignals(True)
         self.listWidget.clear()
         self.listWidget.blockSignals(False)
         all_ctx = self.snapapi.get_contexts().values()
         if fkey!='Attributes':
             ctxs = [c for c in all_ctx if fandango.searchCl(fvalue, str(c.name) if fkey=='Name' else str(c.reason))]
         else:
             ctxs = [c for c in all_ctx if any(fandango.functional.searchCl(fvalue,a) \
                 for a in [c.name,c.reason,c.description]+[av['full_name'] for av in c.attributes.values()])] 
         if not len(ctxs):
             msg = QExceptionMessage(self,'Warning','No context in SnapDB is named like "%s"'%(fvalue))
             ctxs = all_ctx
         self.contextComboBox.blockSignals(True)
         self.contextComboBox.clear()
         current = self.getCurrentContext()
         if current in ctxs:
             ctxs.remove(current)
             ctxs.insert(0,current)
         for c in ctxs:
             self.contextComboBox.addItem("%s [%d]" % (c.name, c.ID), Qt.QVariant(c.ID))
         self.contextComboBox.blockSignals(False)
         if current is not None or len(ctxs)==1: self.onContextChanged()
     except: 
         msg = QExceptionMessage(self,"Error(%s,%s)"%(
             self.filterComboBox.currentText(),self.filterComboBox2.currentText()),traceback.format_exc())
Exemplo n.º 2
0
 def regExFiltering(self, source):
     alarms,regexp=[],str(self.regEx).lower().strip()
     exclude = regexp.startswith('!')
     if exclude: regexp = regexp.replace('!','').strip()
     for a in source:
         match = fandango.searchCl(regexp, a.receivers.lower()+' '+a.severity.lower()+' '+a.description.lower()+' '+a.tag.lower()+' '+a.formula.lower()+' '+a.device.lower())
         if (exclude and not match) or (not exclude and match): alarms.append(a)
     trace('\tregExFiltering(%d): %d alarms returned'%(len(source),len(alarms)))
     return alarms
Exemplo n.º 3
0
 def filterMatching(a,dct=AttributeFilters,p=printf):
     match = False
     if a.lower().endswith('/state'): return True
     elif a.lower().endswith('/status'): return False
     for k,l in dct.items():
         if fn.searchCl(k,a.rsplit('/',1)[0]):
             for t in l: #T is every declared Tab for panel (TabName,[attrlist]); or just attrname when not using tabs
                 p((k,t))
                 f = t[-1] if all(map(fn.isSequence,(t,t[-1]))) else [t]
                 if any(fn.matchCl(v,a.rsplit('/',1)[-1]) for v in f): 
                     match =True
     return match
Exemplo n.º 4
0
 def regExFiltering(self, source):
     msg = 'regExFiltering DEPRECATED by AlarmView'
     print(msg)
     raise Exception(msg)
     alarms, regexp = [], str(self.regEx).lower().strip().replace(' ', '*')
     exclude = regexp.startswith('!') or regexp.startswith('~')
     if exclude: regexp = regexp.replace('!', '').replace('~').strip()
     for a in source:
         match = fn.searchCl(
             regexp,
             a.receivers.lower() + ' ' + a.severity.lower() + ' ' +
             a.description.lower() + ' ' + a.tag.lower() + ' ' +
             a.formula.lower() + ' ' + a.device.lower())
         if (exclude and not match) or (not exclude and match):
             alarms.append(a)
     trace('\tregExFiltering(%d): %d alarms returned' %
           (len(source), len(alarms)))
     return alarms
Exemplo n.º 5
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
    def load_attributes(self,servfilter,devfilter,attrfilter,warn=True,
        exclude = ('dserver','tango*admin','sys*database','tmp','archiving')):
        
        servfilter = servfilter.replace(' ','*').strip()
        attrfilter = (attrfilter or 'state').replace(' ','*')
        devfilter = (devfilter or attrfilter).replace(' ','*')

        #Solve fqdn issues
        devfilter = devfilter.replace('tango://','')
        if ':' in devfilter:
            tracer('ArchivingBrowser ignores tango host filters')
            devfilter = fn.clsub(fn.tango.rehost,'',devfilter)
            
        tracer('In load_attributes(%s,%s,%s)'%(servfilter,devfilter,attrfilter))            

        archive = self.dbcheck.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 fn.matchCl(e,devfilter) for e in exclude)]

        if servfilter.strip('.*'):
            sdevs = map(str.lower,fn.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 
                    (fn.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 fn.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 fn.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.dbcheck.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 fn.searchCl(attrfilter,t,extend=True)]

                for t in sorted(tcs):
                    if not self.dbcheck.isChecked() or not matches: 
                        label = dp.get_attribute_config(t).label
                    else: 
                        label = t
                        
                    if t in matches or fn.searchCl(attrfilter,label,extend=True):
                        if self.archivecheck.isChecked() \
                                and not self.reader.is_attribute_archived(d+'/'+t):
                            continue
                        
                        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