aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/project/os.py
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2020-03-29 14:24:17 +0000
committerEgor Tensin <Egor.Tensin@gmail.com>2020-03-29 14:24:17 +0000
commit5807ec7bc875d678f2e9502259d62d83b858a854 (patch)
tree0e6e1f92777230d94c627ef9208de24d84b4558a /project/os.py
parentclang-format.py: fix timestamps in logs (diff)
downloadcmake-common-5807ec7bc875d678f2e9502259d62d83b858a854.tar.gz
cmake-common-5807ec7bc875d678f2e9502259d62d83b858a854.zip
project: add os.py
Diffstat (limited to '')
-rw-r--r--project/os.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/project/os.py b/project/os.py
new file mode 100644
index 0000000..86ccaad
--- /dev/null
+++ b/project/os.py
@@ -0,0 +1,36 @@
+# Copyright (c) 2020 Egor Tensin <Egor.Tensin@gmail.com>
+# This file is part of the "cmake-common" project.
+# For details, see https://github.com/egor-tensin/cmake-common.
+# Distributed under the MIT License.
+
+from enum import Enum
+import platform
+
+
+class OS(Enum):
+ WINDOWS = 'Windows'
+ LINUX = 'Linux'
+ CYGWIN = 'Cygwin'
+
+ def __str__(self):
+ return self.value
+
+ @staticmethod
+ def current():
+ system = platform.system()
+ if system == 'Windows':
+ return OS.WINDOWS
+ if system == 'Linux':
+ return OS.LINUX
+ if system.startswith('CYGWIN_NT'):
+ return OS.CYGWIN
+ raise NotImplementedError(f'unsupported OS: {system}')
+
+
+def on_windows():
+ return OS.current() is OS.WINDOWS
+
+
+def on_linux_like():
+ os = OS.current()
+ return os is OS.LINUX or os is OS.CYGWIN