# ***************************************************************************** # # This program is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free Software # Foundation; either version 2 of the License, or (at your option) any later # version. # # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # # You should have received a copy of the GNU General Public License along with # this program; if not, write to the Free Software Foundation, Inc., # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # Module authors: # Markus Zolliker # # ***************************************************************************** from nicos import session, config from nicos.utils import printTable from nicos.commands import helparglist, usercommand from servicemanager import FrappyManager SERVICES = FrappyManager.services @usercommand def set_se_list(): frappy_config = session.devices['frappy_config'] frappy_config.set_envlist() @usercommand @helparglist('main [, stick [, addons]]') def frappy(*args, main=None, stick=None, addons=None, force=False): """(re)start frappy server(s) with given configs and load setup if needed - without argument: list running frappy servers, restart failed frappy servers - frappy(''): if available, the standard stick is added too - frappy(''): the stick is removed too - addons are not changed when not given - frappy(main='') # main cfg is changed, but stick is kept - frappy('restart') # restart all frappy servers - frappy(stick='restart') # restart stick frappy server """ confirmed = FrappyManager().cfg_from_sea(config.instrument).get('confirmed') if args: if main is not None: raise TypeError('got multiple values for main') main = args[0] if len(args) == 1: # special case: main given as single argument if main == 'restart': stick = 'restart' addons = 'restart' elif stick is None: # auto stick if main == '': stick = '' # remove stick with main else: allsticks = FrappyManager().all_cfg(config.instrument, 'stick') stickcfg = main + 'stick' if stickcfg in allsticks: # if a default stick is available, start this also stick = stickcfg else: stick = '' # remove stick when main has changed else: if stick is not None: raise TypeError('got multiple values for stick') stick, *alist = args[1:] if alist: if addons is not None: raise TypeError('got multiple values for addons') addons = ','.join(alist) if confirmed and confirmed != main and main is not None and not force: session.log.warning('%r is plugged to the cryostat control rack', confirmed) session.log.warning('if you are sure, use frappy(..., force=True)', confirmed) raise TypeError('refuse to override plugged device') frappy_config = session.devices['frappy_config'] frappy_config.show_config(*frappy_config.check_or_start(main, stick, addons)) @usercommand @helparglist('') def frappy_list(service=None): """list available configuration files""" content = [] def prt(line): content.append(line) if service is None: prt('Available configuration files') prt('') prt('Hint: if no config file can be found which matches your needs exactly') prt('make a copy of an existing one, and change the description accordingly') prt('') prt('Usage (default argument "main"):') prt('') printTable(['command'], [['frappy_list(%r)' % s] for s in SERVICES], prt) FrappyManager().do_listcfg(config.instrument, service or 'main', prt) session.log.info('\n%s', '\n'.join(content)) @usercommand def frappy_changed(): session.devices['frappy_config'].changed()