Skip to content
Snippets Groups Projects
Commit f7bf82cb authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

RF,ENH: Simplified management of $FSLDIR. Added $FSLDEVDIR. runfsl function

gives $FSLDEVDIR precedence, and also allows a global override.
parent badd80c8
No related branches found
No related tags found
No related merge requests found
...@@ -88,7 +88,6 @@ def isWidgetAlive(widget): ...@@ -88,7 +88,6 @@ def isWidgetAlive(widget):
import wx import wx
if platform.wxFlavour == platform.WX_PHOENIX: if platform.wxFlavour == platform.WX_PHOENIX:
excType = RuntimeError excType = RuntimeError
elif platform.wxFlavour == platform.WX_PYTHON: elif platform.wxFlavour == platform.WX_PYTHON:
...@@ -116,6 +115,7 @@ class Platform(notifier.Notifier): ...@@ -116,6 +115,7 @@ class Platform(notifier.Notifier):
os os
frozen frozen
fsldir fsldir
fsldevdir
haveGui haveGui
canHaveGui canHaveGui
inSSHSession inSSHSession
...@@ -146,8 +146,9 @@ class Platform(notifier.Notifier): ...@@ -146,8 +146,9 @@ class Platform(notifier.Notifier):
self.__glRenderer = None self.__glRenderer = None
self.__glIsSoftware = None self.__glIsSoftware = None
self.__fslVersion = None self.__fslVersion = None
self.__fsldir = None
self.fsldir = os.environ.get('FSLDIR', None) # initialise fsldir - see fsldir.setter
self.fsldir = self.fsldir
# Determine if a display is available. We do # Determine if a display is available. We do
# this once at init (instead of on-demand in # this once at init (instead of on-demand in
...@@ -284,7 +285,13 @@ class Platform(notifier.Notifier): ...@@ -284,7 +285,13 @@ class Platform(notifier.Notifier):
any registered listeners are notified via the any registered listeners are notified via the
:class:`.Notifier` interface. :class:`.Notifier` interface.
""" """
return self.__fsldir return os.environ.get('FSLDIR', None)
@property
def fsldevdir(self):
"""The FSL development directory location. """
return os.environ.get('FSLDEVDIR', None)
@fsldir.setter @fsldir.setter
...@@ -301,9 +308,9 @@ class Platform(notifier.Notifier): ...@@ -301,9 +308,9 @@ class Platform(notifier.Notifier):
elif not op.exists(value): value = None elif not op.exists(value): value = None
elif not op.isdir(value): value = None elif not op.isdir(value): value = None
self.__fsldir = value if value is None:
os.environ.pop('FSLDIR', None)
if value is not None: else:
os.environ['FSLDIR'] = value os.environ['FSLDIR'] = value
# Set the FSL version field if we can # Set the FSL version field if we can
...@@ -316,6 +323,26 @@ class Platform(notifier.Notifier): ...@@ -316,6 +323,26 @@ class Platform(notifier.Notifier):
self.notify(value=value) self.notify(value=value)
@fsldevdir.setter
def fsldevdir(self, value):
"""Changes the value of the :attr:`fsldevdir` property, and notifies
any registered listeners.
"""
if value is not None:
value = value.strip()
if value is None: pass
elif value == '': value = None
elif not op.exists(value): value = None
elif not op.isdir(value): value = None
if value is None:
os.environ.pop('FSLDEVDIR', None)
else:
os.environ['FSLDEVDIR'] = value
@property @property
def fslVersion(self): def fslVersion(self):
"""Returns the FSL version as a string, e.g. ``'5.0.9'``. Returns """Returns the FSL version as a string, e.g. ``'5.0.9'``. Returns
......
...@@ -40,6 +40,10 @@ execute them. ...@@ -40,6 +40,10 @@ execute them.
""" """
FSL_PREFIX = None
"""Global override for the FSL executable location used by :func:`runfsl`. """
class FSLNotPresent(Exception): class FSLNotPresent(Exception):
"""Error raised by the :func:`runfsl` function when ``$FSLDIR`` cannot """Error raised by the :func:`runfsl` function when ``$FSLDIR`` cannot
be found. be found.
...@@ -239,11 +243,19 @@ def runfsl(*args, **kwargs): ...@@ -239,11 +243,19 @@ def runfsl(*args, **kwargs):
``$FSLDIR/bin/`` to the command before passing it to :func:`run`. ``$FSLDIR/bin/`` to the command before passing it to :func:`run`.
""" """
if fslplatform.fsldir is None: prefix = None
if FSL_PREFIX is not None:
prefix = FSL_PREFIX
elif fslplatform.fsldevdir is not None:
prefix = op.join(fslplatform.fsldevdir, 'bin')
elif fslplatform.fsldir is not None:
prefix = op.join(fslplatform.fsldir, 'bin')
else:
raise FSLNotPresent('$FSLDIR is not set - FSL cannot be found!') raise FSLNotPresent('$FSLDIR is not set - FSL cannot be found!')
args = _prepareArgs(args) args = _prepareArgs(args)
args[0] = op.join(fslplatform.fsldir, 'bin', args[0]) args[0] = op.join(prefix, args[0])
return run(*args, **kwargs) return run(*args, **kwargs)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment