From 707e75a6b355ec10c72a2e41264c6a5608e1908c Mon Sep 17 00:00:00 2001 From: Paul McCarthy <pauld.mccarthy@gmail.com> Date: Fri, 13 May 2016 10:54:26 +0100 Subject: [PATCH] Platform object now has an 'inSSHSession' flag, so we can test whether we're running locally or over ssh. --- fsl/utils/platform.py | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/fsl/utils/platform.py b/fsl/utils/platform.py index 05bbd1a64..e54440d8a 100644 --- a/fsl/utils/platform.py +++ b/fsl/utils/platform.py @@ -68,6 +68,7 @@ class Platform(notifier.Notifier): frozen fsldir haveGui + inSSHSession wxPlatform wxFlavour glVersion @@ -86,12 +87,13 @@ class Platform(notifier.Notifier): self.WX_MAC_CARBON = WX_MAC_CARBON self.WX_GTK = WX_GTK - self.__fsldir = os.environ.get('FSLDIR', None) - self.__haveGui = False - self.__wxFlavour = None - self.__wxPlatform = None - self.__glVersion = None - self.__glRenderer = None + self.__fsldir = os.environ.get('FSLDIR', None) + self.__haveGui = False + self.__inSSHSession = False + self.__wxFlavour = None + self.__wxPlatform = None + self.__glVersion = None + self.__glRenderer = None try: import wx @@ -100,6 +102,8 @@ class Platform(notifier.Notifier): except ImportError: pass + # If we have a GUI, get some + # info about the wx platform if self.__haveGui: pi = [t.lower() for t in wx.PlatformInfo] @@ -124,6 +128,12 @@ class Platform(notifier.Notifier): log.warning('Could not determine wx platform from ' 'information: {}'.format(pi)) + # If one of these environment + # variables is set, then we're + # probably running over SSH. + self.__inSSHSession = 'SSH_CLIENT' in os.environ or \ + 'SSH_TTY' in os.environ + @property def os(self): @@ -146,6 +156,14 @@ class Platform(notifier.Notifier): """``True`` if we are running with a GUI, ``False`` otherwise. """ return self.__haveGui + + @property + def inSSHSession(self): + """``True`` if this application is running over an SSH session, + ``False`` otherwise. + """ + return self.__inSSHSession + @property def wxPlatform(self): -- GitLab