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

initial commit

# 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 import main
__version__ = '0.0.1'
#!/usr/bin/env python
# - The bet_server entry point.
import sys
import 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:`` function.
# TODO make this non blocking
cmd =**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
port = int(argv[0])
handlers = {
'input' : set_input,
'run' : run_bet,
fslserver.start_server(port=port, handlers=handlers)
if __name__ == '__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():
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)
if __name__ == '__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', '')) as f:
for line in f:
if line.startswith('__version__'):
exec(line, version)
return version['__version__']
def read_requirements():
return ['fsl-gui-core']
entry_points={'console_scripts' : ['bet_server =']})
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