def test_initialise(): # Assuming that initialise() # has not yet been called assert settings.read('nothing') is None assert settings.read('nothing', 'default') == 'default' settings.write('nothing', 'nothing') settings.delete('nothing') assert settings.readFile('nothing') is None settings.writeFile('nothing', 'nothing') settings.deleteFile('nothing') assert settings.filePath() is None assert settings.readAll() == {} assert settings.listFiles() == [] settings.clear() with tests.testdir() as testdir: settings.initialise(cfgid='test', cfgdir=testdir, writeOnExit=False) assert settings.settings.configID == 'test' assert settings.settings.configDir == testdir settings.write('setting', 'value') assert settings.read('setting') == 'value' assert settings.read('nothing') is None
def send(line): """If a cli server is running (see :func:`runserver` and :func:`_serverloop`), the given ``args`` are sent to it. A :exc:`NotRunningError` is raised if a server loop is not running. """ if not isRunning(): raise NotRunningError() with fslsettings.use(fslsettings.Settings('fsleyes', writeOnExit=False)): port = int(fslsettings.readFile('cliserver.txt').strip()) line = (line + '\n').encode() sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect(('localhost', port)) log.debug('Sending to port %i: %s...', port, line[:50]) sock.sendall(line)
def isRunning(): """Returns ``True`` if (it looks like) a server is running, ``False`` otherwise. """ return fslsettings.readFile('cliserver.txt') is not None