Exemple #1
0
    def getNames(self, fullname, factory=None, queryAuth=True):
        '''reimplemented from :class:`TaurusDeviceNameValidator`. It accepts an
        extra keyword arg `queryAuth` which, if set to False, will prevent the
        validator from trying to query a TaurusAuthority to obtain missing info
        such as the devslashname <--> devalias correspondence.
        '''
        groups = self.getUriGroups(fullname)
        if groups is None:
            return None

        default_authority = None
        if factory is None:
            from taurus import Factory
            factory = Factory(scheme=self.scheme)
        default_authority = factory.get_default_tango_host()

        if default_authority is None:
            import PyTango
            default_authority = "//" + PyTango.ApiUtil.get_env_var('TANGO_HOST')

        authority = groups.get('authority')
        if authority is None:
            groups['authority'] = authority = default_authority

        db = None
        if queryAuth:
            try:
                db = factory.getAuthority('tango:%s' % authority)
            except:
                pass

        # note, since we validated, we either have alias or slashname (not
        # both)
        _devalias = groups.get('_devalias')
        _devslashname = groups.get('_devslashname')

        if _devslashname is None and db is not None:
            # get _devslashname from the alias using the DB
            _devslashname = db.getElementFullName(_devalias)
            groups['_devslashname'] = _devslashname

        if _devslashname is None:
            # if we still do not have a slashname, we can only give the short
            return None, None, _devalias

        # we can now construct everything. First the complete:
        complete = 'tango:%(authority)s/%(_devslashname)s' % groups

        # then the normal
        if authority.lower() == default_authority.lower():
            normal = '%(_devslashname)s' % groups
        else:
            normal = '%(authority)s/%(_devslashname)s' % groups

        # and finally the short
        if _devalias is not None:
            short = _devalias
        else:
            if db is not None:
                # get the alias from the DB (if it is defined)
                short = db.getElementAlias(_devslashname) or _devslashname
            else:
                short = _devslashname

        return complete, normal, short
Exemple #2
0
    def getNames(self, fullname, factory=None, queryAuth=True):
        '''reimplemented from :class:`TaurusDeviceNameValidator`. It accepts an
        extra keyword arg `queryAuth` which, if set to False, will prevent the
        validator from trying to query a TaurusAuthority to obtain missing info
        such as the devslashname <--> devalias correspondence.
        '''
        groups = self.getUriGroups(fullname)
        if groups is None:
            return None

        import PyTango
        default_authority = '//' + PyTango.ApiUtil.get_env_var('TANGO_HOST')

        authority = groups.get('authority')
        if authority is None:
            groups['authority'] = authority = default_authority

        db = None
        if queryAuth:
            # attempt to get an Authority object
            if factory is None:
                from taurus import Factory
                factory = Factory(scheme=self.scheme)
            try:
                db = factory.getAuthority('tango:%s' % authority)
            except:
                pass

        # note, since we validated, we either have alias or slashname (not
        # both)
        _devalias = groups.get('_devalias')
        _devslashname = groups.get('_devslashname')

        if _devslashname is None and db is not None:
            # get _devslashname from the alias using the DB
            _devslashname = db.getElementFullName(_devalias)
            groups['_devslashname'] = _devslashname

        if _devslashname is None:
            # if we still do not have a slashname, we can only give the short
            return None, None, _devalias

        # we can now construct everything. First the complete:
        complete = 'tango:%(authority)s/%(_devslashname)s' % groups

        # then the normal
        if authority.lower() == default_authority.lower():
            normal = '%(_devslashname)s' % groups
        else:
            normal = '%(authority)s/%(_devslashname)s' % groups

        # and finally the short
        if _devalias is not None:
            short = _devalias
        else:
            if db is not None:
                # get the alias from the DB (if it is defined)
                short = db.getElementAlias(_devslashname) or _devslashname
            else:
                short = _devslashname

        return complete, normal, short