diff --git a/doc/fsl.utils.callfsl.rst b/doc/fsl.utils.callfsl.rst new file mode 100644 index 0000000000000000000000000000000000000000..2db08b4a686526c05d91bebfe25670a9db373945 --- /dev/null +++ b/doc/fsl.utils.callfsl.rst @@ -0,0 +1,9 @@ +:orphan: + +fsl.utils.callfsl module +======================== + +.. automodule:: fsl.utils.callfsl + :members: + :undoc-members: + :show-inheritance: diff --git a/doc/fsl.utils.rst b/doc/fsl.utils.rst index 0e9ada2e500926df4dd876bb2b779b47dd716a24..61b9c2fedc69503a6603f3d1e14a28f6d3553419 100644 --- a/doc/fsl.utils.rst +++ b/doc/fsl.utils.rst @@ -6,6 +6,7 @@ fsl.utils package fsl.utils.async fsl.utils.cache + fsl.utils.callfsl fsl.utils.colourbarbitmap fsl.utils.dialog fsl.utils.imagepanel diff --git a/fsl/utils/callfsl.py b/fsl/utils/callfsl.py new file mode 100644 index 0000000000000000000000000000000000000000..a77cbc40113c6ed080b64ff3213b707df13d8736 --- /dev/null +++ b/fsl/utils/callfsl.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python +# +# callfsl.py - The callFSL function. +# +# Author: Paul McCarthy <pauldmccarthy@gmail.com> +# +"""This module provides the :func:`callFSL` function, which can be +used to call a FSL command, and retrieve the result. +""" + + +import logging +import subprocess as sp +import os.path as op + +from fsl.utils.platform import platform as fslplatform + + +log = logging.getLogger(__name__) + + +def callFSL(*args): + """Call a FSL command and return the result. + + You can pass the command and arguments as a single string, or as a + list/tuple. + """ + + if fslplatform.fsldir is None: + raise RuntimeError('FSL cannot be found!') + + # If we've been given a single argument, + # assume it is a string containing the + # command and its arguments. Otherwise, + # assume it is a sequence containing + # separate command and arguments. + if len(args) == 1: + args = args.split() + + args = list(args) + args[0] = op.join(fslplatform.fsldir, 'bin', args[0]) + + log.debug('callfsl: {}'.format(' '.join(args))) + + result = sp.check_output(args) + + log.debug('result: {}'.format(result)) + + return result diff --git a/fsl/utils/platform.py b/fsl/utils/platform.py index df2677e7c3a9541f98704491306cdfed9e58344b..93c8fa3ecf26c520fef4dd7b95219ebbe8a6e63e 100644 --- a/fsl/utils/platform.py +++ b/fsl/utils/platform.py @@ -145,11 +145,12 @@ class Platform(notifier.Notifier): self.WX_GTK = WX_GTK self.isWidgetAlive = isWidgetAlive - self.fsldir = os.environ.get('FSLDIR', None) self.__inSSHSession = False self.__glVersion = None self.__glRenderer = None self.__glIsSoftware = None + self.__fslVersion = None + self.fsldir = os.environ.get('FSLDIR', None) # Determine if a display is available. We do # this once at init (instead of on-demand in @@ -293,9 +294,24 @@ class Platform(notifier.Notifier): if value is not None: os.environ['FSLDIR'] = value + + # Set the FSL version field if we can + versionFile = op.join(value, 'etc', 'fslversion') + + if op.exists(versionFile): + with open(versionFile, 'rt') as f: + self.__fslVersion = f.read().strip() self.notify() + + @property + def fslVersion(self): + """Returns the FSL version as a string, e.g. ``'5.0.9'``. Returns + ``None`` if a FSL installation could not be found. + """ + return self.__fslVersion + @property def glVersion(self):