Example #1
0
    def put(self, dev, key, value, time=None, ttl=None, flag=''):
        """Put a value for a given device and subkey.

        The value is serialized by this method using `cache_dump()`.
        """
        if ttl == 0:
            # no need to process immediately-expired values
            return
        if time is None:
            time = currenttime()
        ttlstr = ttl and '+%s' % ttl or ''
        dbkey = ('%s/%s' % (dev, key)).lower()
        with self._dblock:
            self._db[dbkey] = (value, time)
        dvalue = cache_dump(value)
        msg = '%r%s@%s%s%s%s%s\n' % (time, ttlstr, self._prefix, dbkey, flag,
                                     OP_TELL, dvalue)
        # self.log.debug('putting %s=%s', dbkey, value)
        self._queue.put(msg)
        self._propagate((time, dbkey, OP_TELL, dvalue))
        if key == 'value' and session.experiment:
            session.experiment.data.cacheCallback(dbkey, value, time)
        # we have to check rewrites here, since the cache server won't send
        # us updates for a rewritten key if we sent the original key
        if str(dev).lower() in self._rewrites:
            for newprefix in self._rewrites[str(dev).lower()]:
                rdbkey = ('%s/%s' % (newprefix, key)).lower()
                with self._dblock:
                    self._db[rdbkey] = (value, time)
                self._propagate((time, rdbkey, OP_TELL, dvalue))
                if key == 'value' and session.experiment:
                    session.experiment.data.cacheCallback(rdbkey, value, time)
Example #2
0
 def __init__(self, parent, curvalue, allow_enter=False):
     QLineEdit.__init__(self, parent)
     self.setText(cache_dump(curvalue))
     self.textChanged.connect(lambda txt: self.valueModified.emit())
     if allow_enter:
         self.returnPressed.connect(
             lambda: self.valueChosen.emit(cache_load(self.text())))
Example #3
0
    def _create_device_item(self, devname, add_cat=False):
        ldevname = devname.lower()
        # get all cache keys pertaining to the device
        params = self.client.getDeviceParams(devname)
        if not params:
            return
        lowlevel_device = params.get('lowlevel') or False
        if lowlevel_device and not self._show_lowlevel:
            return
        if 'nicos.core.data.sink.DataSink' in params.get('classes', []) and \
           not self._show_lowlevel:
            return

        # remove still-existing previous item for the same device name
        if ldevname in self._devitems:
            self.on_client_device(('destroy', [devname]))

        cat = self._dev2setup.get(devname)
        if cat is None:  # device is not in any setup? reread setup info
            self._read_setup_info()
            cat = self._dev2setup.get(devname)
            if cat is None:  # still not there -> give up
                return

        if cat not in self._catitems:
            display_order = self._setupinfo[cat].get('display_order', 50)
            representative = self._setupinfo[cat].get('extended', {}).get(
                'representative', '').lower()
            catitem = SetupTreeWidgetItem(cat, display_order, representative)
            catitem.setToolTip(0, self._setupinfo[cat].get('description', ''))
            f = catitem.font(0)
            f.setBold(True)
            catitem.setFont(0, f)
            catitem.setIcon(0, self.groupIcon)
            self._catitems[cat] = catitem
            if add_cat:
                self.tree.addTopLevelItem(catitem)
                catitem.setExpanded(True)
        else:
            catitem = self._catitems[cat]

        # create a tree node for the device
        devitem = QTreeWidgetItem(catitem, [devname, '', ''], DEVICE_TYPE)

        devitem.setForeground(0, lowlevelBrush[lowlevel_device])
        devitem.setFont(0, lowlevelFont[lowlevel_device])

        if self.useicons:
            devitem.setIcon(0, self.statusIcon[OK])
        devitem.setToolTip(0, params.get('description', ''))
        self._devitems[ldevname] = devitem
        # fill the device info with dummy values, will be populated below
        self._devinfo[ldevname] = DevInfo(devname)

        # let the cache handler process all properties
        for key, value in iteritems(params):
            self.on_client_cache(
                (0, ldevname + '/' + key, OP_TELL, cache_dump(value)))
Example #4
0
 def storeSysInfo(self, service):
     """Store info about the service in the cache."""
     if not self._socket:
         return
     try:
         key, res = getSysInfo(service)
         msg = '%s@%s%s%s\n' % (currenttime(), key, OP_TELL,
                                cache_dump(res))
         self._socket.sendall(to_utf8(msg))
     except Exception:
         self.log.exception('storing sysinfo failed')
Example #5
0
    def put_raw(self, key, value, time=None, ttl=None, flag=''):
        """Put a key given by full name.

        The instance's key prefix is *not* prepended to the key.  This enables
        e.g. the session logger writing to ``logbook/message`` although the
        prefix is ``nicos/``.
        """
        if ttl == 0:
            # no need to process immediately-expired values
            return
        if time is None:
            time = currenttime()
        ttlstr = ttl and '+%s' % ttl or ''
        value = cache_dump(value)
        msg = '%r%s@%s%s%s%s\n' % (time, ttlstr, key, flag, OP_TELL, value)
        # self.log.debug('putting %s=%s', key, value)
        self._queue.put(msg)
Example #6
0
 def _put_message(self, msgtype, entry, message):
     if entry is not None:
         message = [currenttime(), message, entry.id]
     self._queue.put('watchdog/%s%s%s\n' %
                     (msgtype, OP_TELL, cache_dump(message)))