Commit d25e6a7e authored by Taylor Hanayik's avatar Taylor Hanayik
Browse files

initial commit

parents
# FSL BET GUI server
This directory contains the `fsl-gui-bet` Python library, which provides the
`bet_server` command that runs the back-end for the BET GUI.
#!/usr/bin/env python
from fsl.gui.bet.bet import main
__version__ = '0.0.1'
#!/usr/bin/env python
#
# bet.py - The bet_server entry point.
#
import sys
import fsl.data.image as fslimage
import fsl.wrappers as wrappers
import fsl.gui.server as fslserver
async def set_input(sio, sid, msg):
"""This handler is called when a message of type ``'input'`` is received.
When the user selects an input file, a default output file name is
generated and emitted via a message of type ``'output'``.
"""
infile = msg['filename']
outfile = fslimage.removeExt(infile) + '_brain'
await sio.emit('output', {'filename' : outfile}, room=sid)
async def run_bet(sio, sid, msg):
"""This handler is called when a message of type ``'run'`` is received.
It expects to be passed all of the parameters required to run BET via the
:func:`fsl.wrappers.bet` function.
"""
# TODO make this non blocking
cmd = wrappers.bet(**msg, v=True, cmdonly=True)
await fslserver.run_command(sid, sio, cmd)
def main(argv=None):
"""Entry point. Starts the bet_server web server. Expects to be
given a HTTP port number to listen on as the sole command-line argument.
"""
if argv is None:
argv = sys.argv[1:]
if len(argv) == 0:
port = None
else:
port = int(argv[0])
handlers = {
'input' : set_input,
'run' : run_bet,
}
fslserver.start_server(port=port, handlers=handlers)
if __name__ == '__main__':
sys.exit(main())
#!/usr/bin/env python
import sys
import functools as ft
import socketio
def main():
server_url = sys.argv[1]
infile = sys.argv[2]
sio = socketio.Client()
def on_connect():
print('Connected - sending input file')
sio.emit('input', {'filename' : infile})
def on_output_image(data):
outfile = data['filename']
print(f'Received output event {data}')
sio.emit('run', {'input' : infile, 'output' : outfile})
def on_output(data, msgtype):
print(f'Received {msgtype} event:')
print(' ', data['data'])
def on_command(data):
print('Received command event:')
print(' ', data['command'])
def on_finished(data):
print('Received finished event')
print(' exit code: ', data['exitcode'])
print(' total time:', data['totaltime'])
# don't disconnect until we're sure that the
# server has received the shutdown event
sio.emit('shutdown', {}, callback=on_shutdown)
def on_shutdown():
sio.disconnect()
on_stdout = ft.partial(on_output, msgtype='stdout')
on_stderr = ft.partial(on_output, msgtype='stderr')
sio.on('connect', on_connect)
sio.on('output', on_output_image)
sio.on('stdout', on_stdout)
sio.on('stderr', on_stderr)
sio.on('command', on_command)
sio.on('success', on_finished)
sio.on('error', on_finished)
sio.connect(server_url)
sio.wait()
if __name__ == '__main__':
sys.exit(main())
#!/usr/bin/env python
import os.path as op
from setuptools import setup, find_packages
basedir = op.dirname(__file__)
def read_version():
version = {}
with open(op.join(basedir, 'fsl', 'gui', 'bet', '__init__.py')) as f:
for line in f:
if line.startswith('__version__'):
exec(line, version)
break
return version['__version__']
def read_requirements():
return ['fsl-gui-core']
setup(name='fsl-gui-bet',
description='',
author='',
version=read_version(),
packages=find_packages(),
install_requires=read_requirements(),
entry_points={'console_scripts' : ['bet_server = fsl.gui.bet:main']})
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment