Exemplo n.º 1
0
 def is_attribute_archived(self, attribute, active=None, cached=True):
     # @TODO active argument not implemented
     model = parse_tango_model(attribute, fqdn=True)
     d = self.get_manager()
     if d and cached:
         self.get_archived_attributes()
         if any(
                 fn.inCl(m, self.attributes)
                 for m in (attribute, model.fullname, model.normalname)):
             return model.fullname
         else:
             return False
     elif d:
         attributes = d.AttributeSearch(model.fullname)
         a = [
             a for a in attributes if a.lower().endswith(attribute.lower())
         ]
         if len(attributes) > 1:
             raise Exception('MultipleAttributesMatched!')
         if len(attributes) == 1:
             return attributes[0]
         else:
             return False
     else:
         for a in self.get_attributes():
             index = '[' + attribute.split(
                 '[', 1)[-1] if '[' in attribute else ''
             if a.endswith('/' + attribute.split('[')[0].lower()):
                 return a + index
         return False
Exemplo n.º 2
0
 def get_periodic_attribute_archiver(self, attribute):
     attribute = fn.tango.get_full_name(attribute, fqdn=True)
     archivers = self.get_periodic_archivers_attributes()
     for a, v in archivers.items():
         if fn.inCl(attribute, v):
             return a
     return ''
Exemplo n.º 3
0
    def get_attribute_subscriber(self, attribute):
        if not self.dedicated:
            [self.get_archiver_attributes(d) for d in self.get_archivers()]

        #m = parse_tango_model(attribute,fqdn=True).fullname
        m = get_full_name(attribute, fqdn=True)
        for k, v in self.dedicated.items():
            for l in v:
                if fn.inCl(m, l.split(';')):
                    return k

        return None
Exemplo n.º 4
0
def get_hdbpp_databases(archivers=[],dbs={}):
    """
    Method to obtain list of dbs/archivers; it allows to match any 
    archiver list against existing dbs.
    
    This method can be used in cached mode executed like:
    
        dbs = get_hdbpp_databases()
        for a in archivers:
            db = get_hdbpp_databases(a,dbs).keys()[0]
      
    """
    if not dbs:
        dbs = {}
        print('Loading databases from Tango')
        cms = ft.get_class_devices('HdbConfigurationManager')
        for c in cms:
            try:
                props = ['LibConfiguration','ArchiverList']
                props = ft.get_database().get_device_property(c,props)
                db = dict(t.split('=') 
                          for t in props['LibConfiguration'])['dbname']
                dbs[db] = {c:None}
                for c in props['ArchiverList']:
                    dbs[db][c] =  ft.get_device_property(c,'AttributeList')
            except:
                print('Unable to load %s config' % str(c))
                traceback.print_exc()
    else:
        dbs = dbs.copy()
            
    if archivers:
        archivers = list(archivers) #Don't use toList here!
        targets = []
        for a in archivers:
            m = fn.parse_tango_model(a,fqdn=True)
            targets.extend((m.fullname, m.devicename, m.devicemodel))
            
        print(targets)

        for db,archs in dbs.items():
            narchs = {}
            for a in archs.keys():
                if fn.inCl(a,targets):
                    m = fn.parse_tango_model(a,fqdn=True).fullname
                    narchs[m] = archs[a]
            if not narchs:
                dbs.pop(db)
            else:
                dbs[db] = narchs
            
    return dbs
def check(filename, device='', brief=False):
    """ compare .json files to a real device """
    if not device:
        device = file2dev(filename)

    data = json.load(open(filename))
    vals = dict((str(k), v['value']) for k, v in data['attributes'].items())
    for k, v in vals.items():
        if type(v) == unicode:
            vals[k] = str(v)

    diff = []
    dp = ft.get_device(device)
    attrs = dp.get_attribute_list()
    for k, v in vals.items():
        if not fn.inCl(k, attrs):
            diff.append((device, k, v, None))
        else:
            try:
                w = dp.read_attribute(k).value
                if w != v:
                    diff.append((device, k, v, w))
            except Exception, e:
                diff.append((device, k, v, e))