コード例 #1
0
def CreateAllDevices(**kwargs):
    """Try to create all possible devices in the current setup.

    This is useful when a setup failed to load many devices, and another
    attempt should be made.  Example:

    >>> CreateAllDevices()

    Note: Devices that are marked as lowlevel will not be automatically
    created, unless you set the lowlevel flag like:

    >>> CreateAllDevices(lowlevel=True)

    see also: `CreateDevice`, `RemoveDevice`
    """
    lowlevel = kwargs.get('lowlevel', False)
    if lowlevel and not session.checkUserLevel(ADMIN):
        session.log.error('Creating all lowlevel devices is only allowed '
                          'for admin users')
        lowlevel = False

    session.startMultiCreate()
    try:
        for devname, (_, devconfig) in iteritems(session.configured_devices):
            if devconfig.get('lowlevel', False) and not lowlevel:
                continue
            try:
                session.createDevice(devname, explicit=True)
            except NicosError:
                session.log.exception('error creating %s', devname)
    finally:
        session.endMultiCreate()
コード例 #2
0
def NewSetup(*setupnames):
    """Load the given setups instead of the current one.

    Example:

    >>> NewSetup('tas', 'psd')

    will clear the current setup and load the "tas" and "psd" setups at the
    same time.

    Without arguments, the current setups are reloaded.  Example:

    >>> NewSetup()

    You can use `ListSetups()` to find out which setups are available.

    see also: `AddSetup`, `RemoveSetup`, `ListSetups`
    """
    current_mode = session.mode
    # reload current setups if none given
    update_aliases = True
    if not setupnames:
        update_aliases = False
        setupnames = session.explicit_setups
    # refresh setup files first
    session.readSetups()
    session.checkSetupCompatibility(setupnames, set())
    session.unloadSetup()
    try:
        session.startMultiCreate()
        try:
            session.loadSetup(setupnames, update_aliases=update_aliases)
        finally:
            session.endMultiCreate()
    except Exception:
        session.log.warning(
            'could not load new setup, falling back to '
            'startup setup',
            exc=1)
        session.unloadSetup()
        session.loadSetup('startup')
    if current_mode == MASTER:
        # need to refresh master status
        session.setMode(MASTER)
コード例 #3
0
def AddSetup(*setupnames):
    """Load the given setups additional to the current one.

    Example:

    >>> AddSetup('gaussmeter')

    will load the "gaussmeter" setup in addition to the current setups.

    You can use `ListSetups()` to find out which setups are available.

    see also: `NewSetup`, `RemoveSetup`, `ListSetups`
    """
    if not setupnames:
        ListSetups()
        return
    session.readSetups()
    session.checkSetupCompatibility(setupnames, session.loaded_setups)
    session.startMultiCreate()
    try:
        session.loadSetup(setupnames)
    finally:
        session.endMultiCreate()