Esempio n. 1
0
 def experimentCallback(self, proposal, proptype):
     """Callback when the experiment has been changed."""
     NoninteractiveSession.experimentCallback(self, proposal, proptype)
     # reset cached messages when switching TO user experiment
     if proptype == 'user':
         del self.daemon_device._messages[:]
     self.emitfunc('experiment', (proposal, proptype))
Esempio n. 2
0
 def _deviceNotFound(self, devname, source=None):
     """Override "device not found" to be able to create PollerCacheReaders
     for devices noted as such in extended['poller_cache_reader'].
     """
     for setupname in self.loaded_setups:
         ext = self._setup_info[setupname]['extended']
         if devname in ext.get('poller_cache_reader', ()):
             return PollerCacheReader(devname)
     NoninteractiveSession._deviceNotFound(self, devname, source)
Esempio n. 3
0
 def _watchdogHandler(self, key, value, time, expired=False):
     """Handle a watchdog event."""
     if key.endswith('/scriptaction'):
         action, msg = value[1]
         controller = self.daemon_device._controller
         if action == 'stop':
             controller.script_stop(BREAK_AFTER_STEP, watchdog_user, msg)
         elif action == 'immediatestop':
             controller.script_immediate_stop(watchdog_user, msg)
     # handle other cases
     NoninteractiveSession._watchdogHandler(self, key, value, time, expired)
Esempio n. 4
0
 def checkAccess(self, required):
     if 'level' in required:
         script = self.daemon_device.current_script()
         rlevel = required['level']
         if isinstance(rlevel, str):
             for k, v in ACCESS_LEVELS.items():
                 if v == rlevel:
                     rlevel = k
                     break
             else:
                 raise AccessError('invalid access level name: %r' % rlevel)
         if script and rlevel > script.user.level:
             raise AccessError('%s access is not sufficient, %s access '
                               'is required' %
                               (ACCESS_LEVELS.get(script.user.level,
                                                  str(script.user.level)),
                                ACCESS_LEVELS.get(rlevel, str(rlevel))))
     return NoninteractiveSession.checkAccess(self, required)
Esempio n. 5
0
    def getDevice(self,
                  dev,
                  cls=None,
                  source=None,
                  replace_classes=[(DeviceAlias, PollerCacheReader, {})]):
        """Override device creation for the poller.

        With the "alias device" mechanism, aliases can point to any device in
        the currently loaded setups.  This leads to a problem with the poller,
        since the poller loads each setup in a different process, and in the
        process that polls the DeviceAlias, the pointee can be missing.

        Therefore, we replace devices that are not found by a CacheReader, in
        the hope that the actual pointee is contained in another setup that is
        polled by another process, and we can get current values for the device
        via the CacheReader.
        """
        return NoninteractiveSession.getDevice(self,
                                               dev,
                                               Device,
                                               source,
                                               replace_classes=replace_classes)
Esempio n. 6
0
 def _notify_systemd(cls, appname, msg):
     # can only notify systemd from the main poller process
     if appname == 'poller':
         NoninteractiveSession._notify_systemd(appname, msg)
Esempio n. 7
0
 def _initLogging(self, prefix=None, console=True):
     NoninteractiveSession._initLogging(self, prefix, console)
     sys.displayhook = self._displayhook
Esempio n. 8
0
 def setMode(self, mode):
     NoninteractiveSession.setMode(self, mode)
     self.emitfunc('mode', mode)