from nicos.utils.loggers import ACTION, NicosLogger # The NICOS checkout directory, where to find modules. module_root = path.normpath(path.join(path.dirname(__file__), '..')) # The temporary root directory, where to put data/logs/pid files during test. runtime_root = os.environ.get('NICOS_TEST_ROOT', path.join(path.dirname(__file__), 'root')) # Addresses for services, ports can be allocated by Jenkins. cache_addr = 'localhost:%s' % os.environ.get('NICOS_CACHE_PORT', 14877) alt_cache_addr = 'localhost:%s' % os.environ.get('NICOS_CACHE_ALT_PORT', 14878) daemon_addr = 'localhost:%s' % os.environ.get('NICOS_DAEMON_PORT', 14874) pythonpath = None config.apply() config.user = None config.group = None config.nicos_root = runtime_root config.pid_path = path.join(runtime_root, 'pid') config.logging_path = path.join(runtime_root, 'log') def raises(exc, *args, **kwds): pytest.raises(exc, *args, **kwds) return True class approx(object): """ Ported from py.test v3.0, can use pytest.approx from then on.
def main(argv): global log # pylint: disable=global-statement userpath = path.join(path.expanduser('~'), '.config', 'nicos') # Set up logging for the GUI instance. initLoggers() log = NicosLogger('gui') log.parent = None log.setLevel(logging.INFO) log.addHandler(ColoredConsoleHandler()) log.addHandler( NicosLogfileHandler(path.join(userpath, 'log'), 'gui', use_subdir=False)) # set up logging for unhandled exceptions in Qt callbacks def log_unhandled(*exc_info): traceback.print_exception(*exc_info) log.exception('unhandled exception in QT callback', exc_info=exc_info) sys.excepthook = log_unhandled app = QApplication(argv, organizationName='nicos', applicationName='gui') opts = parseargs() if opts.configfile is None: try: config.apply() except RuntimeError: pass # If "demo" is detected automatically, let the user choose their # instrument configuration. need_dialog = config.instrument is None or \ (config.setup_package == 'nicos_demo' and config.instrument == 'demo' and 'INSTRUMENT' not in os.environ) if need_dialog: opts.configfile = InstrSelectDialog.select( 'Your instrument could not be automatically detected.') if opts.configfile is None: return else: opts.configfile = path.join(config.setup_package_path, config.instrument, 'guiconfig.py') with open(opts.configfile, 'rb') as fp: configcode = fp.read() gui_conf = processGuiConfig(configcode) gui_conf.stylefile = '' if gui_conf.options.get('facility') in ['ess', 'sinq']: gui_conf.stylefile = f"{config.nicos_root}" \ f"/nicos/clients/flowui/guiconfig.qss" stylefiles = [ path.join(userpath, 'style-%s.qss' % sys.platform), path.join(userpath, 'style.qss'), path.splitext(opts.configfile)[0] + '-%s.qss' % sys.platform, path.splitext(opts.configfile)[0] + '.qss', ] for stylefile in [gui_conf.stylefile] or stylefiles: if path.isfile(stylefile): try: with open(stylefile, 'r', encoding='utf-8') as fd: app.setStyleSheet(fd.read()) gui_conf.stylefile = stylefile break except Exception: log.warning('Error setting user style sheet from %s', stylefile, exc=1) mainwindow_cls = _mainwindow_cls.get( gui_conf.options.get('facility', 'default')) mainwindow = mainwindow_cls(log, gui_conf, opts.viewonly, opts.tunnel) log.addHandler(DebugHandler(mainwindow)) if opts.connect: parsed = parseConnectionString(opts.connect, DEFAULT_PORT) if parsed: cdata = ConnectionData(**parsed) cdata.viewonly = opts.viewonly mainwindow.setConnData(cdata) if cdata.password is not None: # we have a password, connect right away mainwindow.client.connect(mainwindow.conndata) else: # we need to ask for password, override last preset (uses given # connection data) and force showing connect window mainwindow.lastpreset = '' mainwindow.autoconnect = True mainwindow.startup() return app.exec_()