1 """ Utility module to determine the OS Python running on
3 --------------------------------------------------------------------------
6 Overview: Python module to supply functions and an enumeration to
7 help determine the platform type, bit size and OS currently
9 --------------------------------------------------------------------------
14 import sys # Provide system information
16 # Third party modules:
23 #-----------------------------------------------------------------------------
24 # Details: Class to implement a 'C' style enumeration type.
26 # Authors: Illya Rudkin 28/11/2013.
29 if sys.version_info.major >= 3:
32 class EnumOsType(Enum):
41 class EnumOsType(object):
50 class __metaclass__(type):
51 #++----------------------------------------------------------------
52 # Details: Fn acts as an enumeration.
53 # Args: vName - (R) Enumeration to match.
54 # Returns: Int - Matching enumeration/index.
58 def __getattr__(cls, vName):
59 return cls.values.index(vName)
61 #++---------------------------------------------------------------------------
62 # Details: Reverse fast lookup of the values list.
63 # Args: vI - (R) Index / enumeration.
64 # Returns: Str - text description matching enumeration.
68 return EnumOsType.values[vI]
70 #-----------------------------------------------------------------------------
71 #-----------------------------------------------------------------------------
72 #-----------------------------------------------------------------------------
74 #++---------------------------------------------------------------------------
75 # Details: Determine what operating system is currently running on.
77 # Returns: EnumOsType - The OS type being used ATM.
82 def determine_os_type():
83 eOSType = EnumOsType.Unknown
87 eOSType = EnumOsType.Darwin
88 elif strOS.startswith("freebsd"):
89 eOSType = EnumOsType.FreeBSD
90 elif strOS.startswith("linux"):
91 eOSType = EnumOsType.Linux
92 elif strOS.startswith("netbsd"):
93 eOSType = EnumOsType.NetBSD
94 elif strOS == "win32":
95 eOSType = EnumOsType.Windows
96 elif strOS.startswith("gnukfreebsd"):
97 eOSType = EnumOsType.kFreeBSD