From a94a19f2f2ec6a65b7e0ecdbf4c7eca14a035d7f Mon Sep 17 00:00:00 2001 From: Martyn Gigg <martyn.gigg@stfc.ac.uk> Date: Thu, 25 Oct 2012 15:23:48 +0100 Subject: [PATCH] Add environment module to wrap around platform Refs #6007 Gives more readable access to things like checking for windows/linux/mac etc --- .../mantid/kernel/environment.py | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Code/Mantid/Framework/PythonInterface/mantid/kernel/environment.py diff --git a/Code/Mantid/Framework/PythonInterface/mantid/kernel/environment.py b/Code/Mantid/Framework/PythonInterface/mantid/kernel/environment.py new file mode 100644 index 00000000000..ca5f87c3c42 --- /dev/null +++ b/Code/Mantid/Framework/PythonInterface/mantid/kernel/environment.py @@ -0,0 +1,50 @@ +""" + Defines a set functions for interrogating the current enviroment. + + The standard platform module doesn't have simple things like is_windows(), + is_linux(). The set of functions defined here should make it clearer what is going + on when they are used. +""" +import platform as _platform +import sys as _sys + +def is_windows(): + """ + Returns True if the current platform is Windows (regardless of version/32- or 64-bit etc) + """ + return _sys.platform == "win32" + +def is_mac(): + """ + Returns True if the current platform is Mac (regardless of version/32- or 64-bit etc) + """ + return _sys.platform == "darwin" + +def is_linux(): + """ + Returns True if the current platform is OS X (regardless of version/32- or 64-bit etc) + Variant on is_apple + """ + return _sys.platform.startswith("linux") + +def is_32bit(): + """ + Returns True if the current platform is 32-bit + """ + if is_mac(): + # See Python documentation on platform module for why this is different + return _sys.maxsize == 2**31 - 1 # Max size of integer + else: + bits = _platform.architecture()[0] + return bits == '32bit' + +def is_64bit(): + """ + Returns True if the current platform is 64-bit + """ + if is_mac(): + # See Python documentation on platform module for why this is different + return _sys.maxsize > 2**32 + else: + bits = _platform.architecture()[0] + return bits == '64bit' \ No newline at end of file -- GitLab