Пример #1
0
def _to_fqdn(name, logger=None):
    """Helper to convert name into a FQDN URI reference. Works for devices
    and attributes.
    Prior to sardana 2.4.0 Pool element references were using not unique full
    names e.g. pc255:10000/motor/motctrl20/1. This helper converts them into
    FQDN URI references e.g. tango://pc255.cells.es:10000/motor/motctrl20/1.
    It is similarly solved for attribute names.
    """
    full_name = name
    # try to use Taurus 4 to retrieve FQDN URI name
    try:
        from taurus.core.tango.tangovalidator import TangoDeviceNameValidator
        try:
            full_name, _, _ = TangoDeviceNameValidator().getNames(name)
        # it is not a device try as an attribute
        except Exception:
            from taurus.core.tango.tangovalidator import \
                TangoAttributeNameValidator
            full_name, _, _ = TangoAttributeNameValidator().getNames(name)
    # if Taurus3 in use just continue
    except ImportError:
        pass
    if full_name != name and logger:
        msg = ("PQDN full name is deprecated in favor of FQDN full name. "
               "Re-apply pre-scan snapshot configuration in order to "
               "upgrade.")
        logger.warning(msg)
    return full_name
Пример #2
0
    def _build_elements(self):
        self._user_elements = []
        self._physical_elements = {}
        self._physical_elements_set = set()

        pool = self._get_pool()
        for user_element_id in self._user_element_ids:
            # an internal element
            internal = isinstance(user_element_id, int)
            if internal:
                try:
                    user_element = pool.get_element(id=user_element_id)
                except KeyError:
                    self._pending = True
                    self._user_elements = None

                    self._physical_elements = None
                    self._physical_elements_set = None
                    raise
                internal = self._is_managed_element(user_element)
                if not internal:
                    user_element_id = user_element.get_source()
            # a tango channel or non internal element (ex: ioregister or motor
            # in measurement group)
            if not internal:
                validator = TangoAttributeNameValidator()
                params = validator.getUriGroups(user_element_id)
                params['pool'] = self._get_pool()
                user_element = PoolExternalObject(**params)
            self.add_user_element(user_element)
        self._pending = False
Пример #3
0
    def on_message(self, json_data):
        """Executed when a message comes from the client through the websocket.

        It expected that json_data is a JSON encoded string.
        It should be a JSON object with *models* member. the value of *models*
        should be an array of strings, each representing a model name.
        Example:
            { models : [ "BO/S05/Pump5/Pressure",
                         "BO/S05/Pump5/Pressure#unit",
                         "sys/tg_test/1/double_scalar" ]
            }
            So far, only attributes and configuration parameters are supported.

            A TaurusWebXXX object will be created for each different model.
            This object subscribes itself to taurus events. The callback usually
            transforms such an event into a JSON encoded string which is sent
            back to the client through this same web socket.
        """
        data = json_decode(json_data)
        if 'models' in data:
            self.clear_models()
            model_names = set(data['models'])
            for model_name in model_names:
                model_name = str(model_name)
                if TangoAttributeNameValidator().isValid(model_name):
                    web_model = TaurusWebAttribute(self, model_name)
                elif TangoConfigurationNameValidator().isValid(model_name):
                    web_model = TaurusWebConfiguration(self, model_name)
                else:
                    continue
                self.models.add(web_model)
Пример #4
0
 def on_message(self, json_data):
     data = json_decode(json_data)
     if 'models' in data:
         self.clear_models()
         model_names = set(data['models'])
         for model_name in model_names:
             model_name = str(model_name)
             if TangoAttributeNameValidator().isValid(model_name):
                 web_model = TaurusWebAttribute(self, model_name)
             elif TangoConfigurationNameValidator().isValid(model_name):
                 web_model = TaurusWebConfiguration(self, model_name)
             else:
                 continue
             self.models.add(web_model)
 def __init__(self, event_callback, unsubscribe_callback, period=0.5):
     QtCore.QThread.__init__(self)
     self.listeners = CaselessDict()
     self.inverse_listeners = {}
     self.event_callback = event_callback
     self.unsubscribe_callback = unsubscribe_callback
     self.period = period
     self._attributes = None
     self._config = CaselessDict()
     self._last_event = TTLDict(default_ttl=10)
     self.attribute_validator = TangoAttributeNameValidator()
     self.device_validator = TangoDeviceNameValidator()
     self.eval_validator = EvaluationAttributeNameValidator()
     self.lock = Lock()
     self.stopped = Event()
Пример #6
0
    def create_measurement_group(self, **kwargs):
        name = kwargs['name']
        elem_ids = kwargs["user_elements"]

        kwargs['pool'] = self
        kwargs["pool_name"] = self.name

        td = TYPE_MAP_OBJ[ElementType.MeasurementGroup]
        klass = td.klass
        auto_full_name = td.auto_full_name

        full_name = kwargs.get("full_name", auto_full_name.format(**kwargs))
        kwargs.pop('pool_name')

        self.check_element(name, full_name)

        for elem_id in elem_ids:
            if isinstance(elem_id, int):
                self.pool.get_element(id=elem_id)
            else:
                tg_attr_validator = TangoAttributeNameValidator()
                params = tg_attr_validator.getUriGroups(elem_id)
                if params is None:
                    raise Exception("Invalid channel name %s" % elem_id)

        eid = kwargs.get('id')
        if eid is None:
            kwargs['id'] = eid = self.get_new_id()
        else:
            self.reserve_id(eid)

        elem = klass(**kwargs)

        ret = self.add_element(elem)
        self.fire_event(EventType("ElementCreated"), elem)
        return ret
Пример #7
0
NEXUS_SRC = re.compile(
    r'^((nxfile|nxdata):)(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*)(\[[0-9,: ]*?\]))?'
)
ASCII_SRC = re.compile(
    r'^((file):)(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*)(\[[0-9,: ]*?\]))?')

# set some named constants
# columns:
NUMCOLS = 4
X, Y, TITLE, VIS = range(NUMCOLS)
SRC_ROLE = Qt.Qt.UserRole + 1
PROPS_ROLE = Qt.Qt.UserRole + 2

# TODO: Tango-centric (use agnostic validation)
from taurus.core.tango.tangovalidator import TangoAttributeNameValidator
ATTRNAMEVALIDATOR = TangoAttributeNameValidator()


class Component(object):
    def __init__(self, src):
        self.src = src
        self.display = ''
        self.icon = Qt.QIcon()
        self.ok = True
        self._attrnamevalidator = ATTRNAMEVALIDATOR
        self._dbCache = taurus.Authority()
        self.setSrc(src)

    def update(self):
        self.setSrc(self.src)