2014-07-02 01:57:19 +08:00
|
|
|
""" Utility module to determine the OS Python running on
|
|
|
|
|
2014-11-17 23:37:59 +08:00
|
|
|
--------------------------------------------------------------------------
|
|
|
|
File: utilsOsType.py
|
2014-07-02 01:57:19 +08:00
|
|
|
|
2015-11-06 07:57:33 +08:00
|
|
|
Overview: Python module to supply functions and an enumeration to
|
2014-11-17 23:37:59 +08:00
|
|
|
help determine the platform type, bit size and OS currently
|
|
|
|
being used.
|
|
|
|
--------------------------------------------------------------------------
|
2014-07-02 01:57:19 +08:00
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Python modules:
|
2014-11-17 23:37:59 +08:00
|
|
|
import sys # Provide system information
|
2014-07-02 01:57:19 +08:00
|
|
|
|
|
|
|
# Third party modules:
|
|
|
|
|
|
|
|
# In-house modules:
|
|
|
|
|
|
|
|
# Instantiations:
|
|
|
|
|
|
|
|
# Enumerations:
|
|
|
|
#-----------------------------------------------------------------------------
|
2014-11-17 23:37:59 +08:00
|
|
|
# Details: Class to implement a 'C' style enumeration type.
|
|
|
|
# Gotchas: None.
|
|
|
|
# Authors: Illya Rudkin 28/11/2013.
|
|
|
|
# Changes: None.
|
2014-07-02 01:57:19 +08:00
|
|
|
#--
|
2015-10-07 05:11:28 +08:00
|
|
|
if sys.version_info.major >= 3:
|
|
|
|
from enum import Enum
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-10-07 05:11:28 +08:00
|
|
|
class EnumOsType(Enum):
|
|
|
|
Unknown = 0
|
|
|
|
Darwin = 1
|
|
|
|
FreeBSD = 2
|
|
|
|
Linux = 3
|
|
|
|
NetBSD = 4
|
2018-10-05 04:34:58 +08:00
|
|
|
OpenBSD = 5
|
|
|
|
Windows = 6
|
|
|
|
kFreeBSD = 7
|
2015-10-07 05:11:28 +08:00
|
|
|
else:
|
2015-11-06 07:57:33 +08:00
|
|
|
class EnumOsType(object):
|
|
|
|
values = ["Unknown",
|
|
|
|
"Darwin",
|
|
|
|
"FreeBSD",
|
|
|
|
"Linux",
|
|
|
|
"NetBSD",
|
2018-05-22 03:47:45 +08:00
|
|
|
"OpenBSD",
|
2016-12-17 20:48:06 +08:00
|
|
|
"Windows",
|
|
|
|
"kFreeBSD"]
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-11-06 07:57:33 +08:00
|
|
|
class __metaclass__(type):
|
2016-09-07 04:57:50 +08:00
|
|
|
#++----------------------------------------------------------------
|
|
|
|
# Details: Fn acts as an enumeration.
|
|
|
|
# Args: vName - (R) Enumeration to match.
|
|
|
|
# Returns: Int - Matching enumeration/index.
|
|
|
|
# Throws: None.
|
|
|
|
#--
|
|
|
|
|
2015-11-06 07:57:33 +08:00
|
|
|
def __getattr__(cls, vName):
|
|
|
|
return cls.values.index(vName)
|
2014-07-02 01:57:19 +08:00
|
|
|
|
|
|
|
#++---------------------------------------------------------------------------
|
2014-11-17 23:37:59 +08:00
|
|
|
# Details: Reverse fast lookup of the values list.
|
|
|
|
# Args: vI - (R) Index / enumeration.
|
|
|
|
# Returns: Str - text description matching enumeration.
|
|
|
|
# Throws: None.
|
2014-07-02 01:57:19 +08:00
|
|
|
#--
|
2015-11-06 07:57:33 +08:00
|
|
|
def name_of(cls, vI):
|
|
|
|
return EnumOsType.values[vI]
|
2014-07-02 01:57:19 +08:00
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#++---------------------------------------------------------------------------
|
2014-11-17 23:37:59 +08:00
|
|
|
# Details: Determine what operating system is currently running on.
|
|
|
|
# Args: None.
|
|
|
|
# Returns: EnumOsType - The OS type being used ATM.
|
|
|
|
# Throws: None.
|
2014-07-02 01:57:19 +08:00
|
|
|
#--
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
|
2014-07-02 01:57:19 +08:00
|
|
|
def determine_os_type():
|
2015-11-06 07:57:33 +08:00
|
|
|
eOSType = EnumOsType.Unknown
|
2014-11-17 23:37:59 +08:00
|
|
|
|
|
|
|
strOS = sys.platform
|
2014-11-17 23:40:18 +08:00
|
|
|
if strOS == "darwin":
|
|
|
|
eOSType = EnumOsType.Darwin
|
2015-11-06 07:57:33 +08:00
|
|
|
elif strOS.startswith("freebsd"):
|
2014-11-17 23:40:18 +08:00
|
|
|
eOSType = EnumOsType.FreeBSD
|
2015-11-06 07:57:33 +08:00
|
|
|
elif strOS.startswith("linux"):
|
2014-11-17 23:40:18 +08:00
|
|
|
eOSType = EnumOsType.Linux
|
2015-11-06 07:57:33 +08:00
|
|
|
elif strOS.startswith("netbsd"):
|
2015-09-09 09:22:05 +08:00
|
|
|
eOSType = EnumOsType.NetBSD
|
2018-05-22 03:47:45 +08:00
|
|
|
elif strOS.startswith("openbsd"):
|
|
|
|
eOSType = EnumOsType.OpenBSD
|
2014-11-17 23:40:18 +08:00
|
|
|
elif strOS == "win32":
|
|
|
|
eOSType = EnumOsType.Windows
|
2016-12-17 20:48:06 +08:00
|
|
|
elif strOS.startswith("gnukfreebsd"):
|
|
|
|
eOSType = EnumOsType.kFreeBSD
|
2014-11-17 23:37:59 +08:00
|
|
|
|
2015-11-06 07:57:33 +08:00
|
|
|
return eOSType
|