Exemplo n.º 1
0
 def _getProposalInput(self):
     prop = self.proposalNum.text()
     title = self.expTitle.text()
     username = self.userName.text()
     remark = self.remark.text()
     proposaldir = self.proposalDir.text()
     if proposaldir and not os.path.isdir(proposaldir):
         QMessageBox.critical(
             self, 'Error', 'The provided proposal path '
             'does not exist!')
         raise ConfigurationError('')
     if not os.access(proposaldir, os.W_OK):
         QMessageBox.critical(
             self, 'Error', 'Don\'t have permission to '
             'write in the proposal path! Please choose '
             'a different one!')
         raise ConfigurationError('')
     try:
         useremail = mailaddress(self.userEmail.text())
     except ValueError:
         QMessageBox.critical(
             self, 'Error', 'The user email entry is '
             'not  a valid email address')
         raise ConfigurationError('') from None
     return prop, title, username, useremail, proposaldir, remark
Exemplo n.º 2
0
 def doInit(self, mode):
     self.valuetype = oneof(*sorted(self.presets, key=num_sort))
     self._waitdevs = []
     self._aliases = {}
     self._devpos = {}
     for setting, values in self.presets.items():
         values = dict(values)
         try:
             self._aliases[setting] = (values.pop('active_ap'),
                                       values.pop('active_x'),
                                       values.pop('active_y'))
         except KeyError:
             raise ConfigurationError(
                 self, 'setting %r needs active_ap, active_x and active_y '
                 'settings' % setting) from None
         try:
             for name in self._aliases[setting]:
                 session.getDevice(name)
         except NicosError as exc:
             raise ConfigurationError(
                 self,
                 'could not create/find alias targets for setting %r' %
                 setting) from exc
         for key in values:
             if key not in self.alloweddevs:
                 raise ConfigurationError(
                     self, 'device %s is not allowed '
                     'to be moved by sample_pos' % key)
         self._devpos[setting] = values
Exemplo n.º 3
0
 def doWriteRange(self, r):
     rmin, rmax = r
     umin, umax = self._attached_moveable.userlimits
     if rmin > rmax:
         raise ConfigurationError(self, 'minimum (%s) above the maximum '
                                  '(%s)' % (rmin, rmax))
     if rmin < umin - abs(umin * 1e-12):
         raise ConfigurationError(self, 'minimum (%s) below the moveable '
                                  'minimum (%s)' % (rmin, umin))
     if rmax > umax + abs(umax * 1e-12):
         raise ConfigurationError(self, 'maximum (%s) above the moveable '
                                  'maximum (%s)' % (rmax, umax))
Exemplo n.º 4
0
 def doPreinit(self, mode):
     BaseImageChannel.doPreinit(self, mode)
     if mode != SIMULATION:
         if self._getProperty('compact_readout') != 'True':
             raise ConfigurationError(self, 'server must be set to '
                                      'compact readout mode')
         if len(eval(self._getProperty('compact_foil_start'))) != \
            len(self.foilsorder):
             raise ConfigurationError(self, 'number of foils to read '
                                      'out from server does not match '
                                      'with "foilsorder" parameter')
         self._perfoil = int(self._getProperty('compact_per_foil'))
Exemplo n.º 5
0
 def doInit(self, mode):
     MappedMoveable.doInit(self, mode)
     for k, t in self.mapping.items():
         if len(t) != len(self.devices):
             raise ConfigurationError(self, 'Switcher state entry for key '
                                      '%r has different length than '
                                      'moveables list' % k)
     if self.precision:
         if len(self.precision) not in [1, len(self.devices)]:
             raise ConfigurationError(self, 'The precision list must either'
                                      ' contain only one element or have '
                                      'the same amount of elements as the '
                                      'moveables list')
Exemplo n.º 6
0
 def doReadRange(self):
     # check range against moveable user limits
     if 'range' in self._config:
         amin, amax = self._config['range']
         mmin, mmax = self._attached_moveable.userlimits
         if amin < mmin:
             raise ConfigurationError(self, 'min (%s) below the moveable'
                                      ' min (%s)' % (amin, mmin))
         if amax > mmax:
             raise ConfigurationError(self, 'max (%s) above the moveable'
                                      ' max (%s)' % (amax, mmax))
     else:
         amin, amax = self._attached_moveable.userlimits
     return amin, amax
Exemplo n.º 7
0
 def doReadAbslimits(self):
     mot_amin, mot_amax = self._attached_motor.abslimits
     # if abslimits are configured, use them, but they can only restrict,
     # not widen, the motor's abslimits
     if 'abslimits' in self._config:
         amin, amax = self._config['abslimits']
         if amin < mot_amin - abs(mot_amin * 1e-12):
             raise ConfigurationError(self, 'abslimits: min (%s) below '
                                      "motor's min (%s)" % (amin, mot_amin))
         if amax > mot_amax + abs(mot_amax * 1e-12):
             raise ConfigurationError(self, 'abslimits: max (%s) above '
                                      "motor's max (%s)" % (amax, mot_amax))
     else:
         amin, amax = mot_amin, mot_amax
     return amin, amax
Exemplo n.º 8
0
 def doInit(self, mode):
     if self.reflimits is not None:
         if not (0 <= self.reflimits[0] <= self.reflimits[1] <=
                 self.reflimits[2]):
             raise ConfigurationError(
                 self, 'reflimits must be in ascending'
                 ' order!')
Exemplo n.º 9
0
    def __get_param(self, attrname):
        # take first match
        tubeval = getattr(self._attached_tube, attrname)
        stickval = getattr(self._attached_stick, attrname)
        if tubeval == stickval:
            res = tubeval
        else:
            self.log.warning(
                '%s.%s (%r) != %s.%s (%r), please set %s.%s to '
                'the desired value!', self._attached_tube.name, attrname,
                tubeval, self._attached_stick.name, attrname, stickval,
                self.name, attrname)
            # try to take the 'more important' one
            if self._attached_stick.target is not None and \
               self._attached_stick.target > self._attached_tube.absmax:
                res = stickval
            else:
                if self.regulationmode == 'stick':
                    res = stickval
                elif self.regulationmode == 'tube':
                    res = tubeval
                else:
                    raise ConfigurationError(
                        self, 'Parameters %s.%s and %s.%s'
                        ' differ! please set them using '
                        '%s.%s only.' % (self._attached_tube.name, attrname,
                                         self._attached_stick.name, attrname,
                                         self.name, attrname))

        self.log.debug('param %s is %r', attrname, res)
        return res
Exemplo n.º 10
0
    def doInit(self, mode):
        # import server and serializer class
        servercls = importString(self.servercls)
        serialcls = importString(self.serializercls)

        self._stoprequest = False
        # the controller represents the internal script execution machinery
        if self.autosimulate and not config.sandbox_simulation:
            raise ConfigurationError('autosimulation configured but sandbox'
                                     ' deactivated')

        self._controller = ExecutionController(self.log, self.emit_event,
                                               'startup', self.simmode,
                                               self.autosimulate)

        # cache log messages emitted so far
        self._messages = []

        host, port = parseHostPort(self.server, DEFAULT_PORT)

        # create server (transport + serializer)
        self._server = servercls(self, (host, port), serialcls())

        self._watch_worker = createThread('daemon watch monitor',
                                          self._watch_entry)
Exemplo n.º 11
0
 def doUpdateCounter(self, name):
     for (i, value) in enumerate(self._attached_detector.valueInfo()):
         if value.name == name:
             self._vindex = i
             break
     else:
         raise ConfigurationError(self, "Counter '%s' not present" % name)
Exemplo n.º 12
0
 def doInit(self, mode):
     MultiSwitcher.doInit(self, mode)
     if len(self._attached_moveables) != 5:
         raise ConfigurationError(self, 'must have exactly 5 moveables')
     self._mot_rot, self._mot_xv, self._mot_yv, self._mot_xh, \
         self._mot_yh = self._attached_moveables
     self.valuetype = oneof(*sorted(self.mapping, key=num_sort))
Exemplo n.º 13
0
 def doInit(self, mode):
     self.valuetype = oneof(*sorted(self.mapping, key=num_sort))
     if len(self._attached_slits) != len(self.slitpos):
         raise ConfigurationError(
             self, 'number of elements in slitpos '
             'parameter must match number of attached '
             'slit devices')
Exemplo n.º 14
0
 def doInit(self, mode):
     if '.raw' not in self.filenametemplate[0]:
         raise ConfigurationError(
             self, 'first filenametemplate must '
             'contain .raw which is then exchanged '
             'to .header and .log for additional '
             'data files')
Exemplo n.º 15
0
 def _getRaw(self):
     if parse is None:
         raise NicosError(
             self, 'cannot parse web page, lxml is not '
             'installed on this system')
     url = 'http://%s/web?group=%d' % (self.hostname, self.group)
     try:
         tree = parse(url)
         names = [
             name.text.strip()
             for name in tree.findall('//font[@class="tagname"]')
         ]
         values = [
             value.text.strip()
             for value in tree.findall('//font[@class="pv"]')
         ]
         info = dict(zip(names, values))
         if self.valuename not in info:
             raise ConfigurationError(
                 self, 'value %r not found on '
                 'Memograph page (valid values are %s)' %
                 (self.valuename, ', '.join(map(repr, names))))
         return info[self.valuename]
     except ConfigurationError:  # pass through error raised above
         raise
     except Exception as err:
         raise CommunicationError(
             self, 'Memograph not responding or '
             'changed format: %s' % err)
Exemplo n.º 16
0
 def set(self, number, parameters):
     for key in ('name', 'aperture', 'position', 'timefactor', 'thickness',
                 'detoffset', 'comment'):
         if key not in parameters:
             raise ConfigurationError(
                 self, 'missing key %r in sample entry' % key)
     Sample.set(self, number, parameters)
Exemplo n.º 17
0
    def doPreinit(self, mode):
        # Don't create PVs in simulation mode
        self._pvs = {}
        self._pvctrls = {}
        if mode != SIMULATION:
            # in case we get started in a thread, make sure to use the global
            # CA context in that thread
            if epics.ca.current_context() is None:
                epics.ca.use_initial_context()

            # When there are standard names for PVs (see motor record), the PV
            # names may be derived from some prefix. To make this more flexible,
            # the pv_parameters are obtained via a method that can be overridden
            # in subclasses.
            pv_parameters = self._get_pv_parameters()
            for pvparam in pv_parameters:

                # Retrieve the actual PV-name from (potentially overridden) method
                pvname = self._get_pv_name(pvparam)
                if not pvname:
                    raise ConfigurationError(self, 'PV for parameter %s was '
                                                   'not found!' % pvparam)
                pv = self._pvs[pvparam] = epics.pv.PV(
                    pvname, connection_timeout=self.epicstimeout)
                pv.connect()
                if not pv.wait_for_connection(timeout=self.epicstimeout):
                    raise CommunicationError(self, 'could not connect to PV %r'
                                             % pvname)

                self._pvctrls[pvparam] = pv.get_ctrlvars() or {}
        else:
            for pvparam in self._get_pv_parameters():
                self._pvs[pvparam] = HardwareStub(self)
                self._pvctrls[pvparam] = {}
Exemplo n.º 18
0
 def doInit(self, mode):
     # switch off watchdog, important before doing any write access
     if mode != SIMULATION:
         self._dev.WriteOutputWord((WATCHDOG_REGISTER, WATCHDOG_DISABLE))
         # check 'dwordorder' is 'little'
         if self._getProperty('dwordorder') != 'little':
             raise ConfigurationError("dwordorder property must "
                                      "be set to 'little'!")
Exemplo n.º 19
0
 def doInit(self, mode):
     if self.fallback in self.mapping:
         raise ConfigurationError(
             self, 'Value of fallback parameter is '
             'not allowed to be in the mapping!')
     self._inverse_mapping = {}
     for k, v in self.mapping.items():
         self._inverse_mapping[v] = k
Exemplo n.º 20
0
 def _resolve_block(self, block):
     # exchange SetupBlock objects by their definition, or raise
     # a ConfigurationError if it doesn't exist.
     if not isinstance(block, SetupBlock):
         return block
     setup, bname = block._setupname, block._blockname
     setupinfo = session.getSetupInfo()
     if setup not in setupinfo:
         raise ConfigurationError(
             self, 'Setup "%s" required by '
             'SetupBlock() does not exist' % setup)
     blocks = setupinfo[setup]['monitor_blocks']
     if bname not in blocks:
         raise ConfigurationError(
             self, 'Setup "%s" does not define a  '
             'monitor block called "%s"' % (setup, bname))
     return blocks[bname]
Exemplo n.º 21
0
 def doWriteTimeconstant(self, value):
     if value not in TIMECONSTANTS:
         raise ConfigurationError(self, 'invalid time constant, valid ones '
                                  'are ' + ', '.join(map(str, TIMECONSTANTS)))
     value = TIMECONSTANTS.index(value)
     self._dev.WriteLine('OFLT %d' % value)
     if self.doReadTimeconstant() != value:
         raise NicosError(self, 'setting new time constant failed')
Exemplo n.º 22
0
 def doWriteRatio(self, value):
     if self._attached_ratio:
         if not self.isMaster:
             self._attached_ratio.start(value)
         else:
             raise UsageError(
                 'I am a master, ask my slave to set its ratio')
     else:
         raise ConfigurationError('No device attached to set the ratio')
Exemplo n.º 23
0
 def doWritePhase(self, value):
     if self._attached_phase:
         if not self.isMaster:
             self._attached_phase.start(value)
         else:
             raise UsageError(
                 'I am a master, ask my slave to set its phase')
     else:
         raise ConfigurationError('No device attached to set the phase')
Exemplo n.º 24
0
 def doWriteSpeed(self, value):
     if self._attached_speed:
         if self.isMaster:
             self._attached_speed.start(value)
         else:
             raise UsageError(
                 'A slave cannot set speed. Please ask my master')
     else:
         raise ConfigurationError('No device attached to set the speed')
Exemplo n.º 25
0
 def doInit(self, mode):
     if mode != SIMULATION:
         if self._attached_stick is None or self._attached_tube is None:
             raise ConfigurationError(
                 self, 'Both stick and tube needs to '
                 'be set for this device!')
         absmin = min(self._attached_tube.absmin,
                      self._attached_stick.absmin)
         absmax = self._attached_stick.absmax
         self._setROParam('abslimits', (absmin, absmax))
Exemplo n.º 26
0
 def __init__(self):
     try:
         if not session.experiment or not session.experiment.propdb:
             credpath = path.join(path.expanduser('~'), '.nicos',
                                  'credentials')
             credentials = readFile(credpath)
         else:
             credentials = readFile(session.experiment.propdb)
     except IOError as e:
         raise ConfigurationError('Can\'t read credentials '
                                  'for propdb-access from file: %s' % e)
     credentials = credentials[0]
     try:
         self.user, hostdb = credentials.split('@')
         self.host, self.db = hostdb.split(':')
     except ValueError:
         raise ConfigurationError('%r is an invalid credentials string '
                                  '("user@host:dbname")' % credentials)
     if DB is None:
         raise ConfigurationError('MySQL adapter is not installed')
Exemplo n.º 27
0
    def doInit(self, mode):
        if mode == SIMULATION:
            return
        intype = FTYPE_TO_VALUETYPE.get(self._pvs['readpv'].ftype, anytype)
        outtype = FTYPE_TO_VALUETYPE.get(self._pvs['writepv'].ftype, anytype)
        if intype != self.valuetype:
            raise ConfigurationError(self, 'Input PV %r does not have the '
                                           'correct data type' % self.readpv)
        if outtype != self.valuetype:
            raise ConfigurationError(self, 'Output PV %r does not have the '
                                           'correct data type' % self.writepv)

        if self.targetpv:
            target_type = FTYPE_TO_VALUETYPE.get(
                self._pvs['targetpv'].ftype, anytype)

            if target_type != self.valuetype:
                raise ConfigurationError(
                    self, 'Target PV %r does not have the '
                          'correct data type' % self.targetpv)
Exemplo n.º 28
0
    def doPreinit(self, mode):
        if mode != SIMULATION:
            host, port = self.host.split(':')
            self._client = ControlClient(host, port)
            remote_objects = self._client.get_object_collection()

            if self.remoteobj not in remote_objects.keys():
                raise ConfigurationError('No such object on {}: {}'.format(
                    self.host, self.remoteobj))

            self._obj = remote_objects[self.remoteobj]
Exemplo n.º 29
0
 def doInit(self, session_mode):
     Detector.doInit(self, session_mode)
     self._img = self._attached_images[0]
     if session_mode == MASTER:
         if not self._attached_images or \
            not isinstance(self._attached_images[0], (KWSImageChannel,
                                                      VirtualKWSImageChannel)):
             raise ConfigurationError(
                 self, 'KWSDetector needs a KWSChannel '
                 'as attached image')
         self.kwscounting = False
Exemplo n.º 30
0
 def doInit(self, mode):
     if self.__class__ is CacheDatabase:
         raise ConfigurationError(
             'CacheDatabase is abstract, use a derived device class')
     self._lock_lock = threading.Lock()
     self._locks = {}
     self._rewrite_lock = threading.Lock()
     # map incoming prefix -> set of new prefixes
     self._rewrites = {}
     # map new prefix -> incoming prefix
     self._inv_rewrites = {}