aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/project/os.py
blob: 199086f1cec2a8423cb046c8b676c7cd765113da (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Copyright (c) 2020 Egor Tensin <egor@tensin.name>
# 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 auto, StrEnum
import platform


class OS(StrEnum):
    WINDOWS = auto()
    LINUX = auto()
    MACOS = auto()

    @staticmethod
    def current():
        system = platform.system()
        mapping = {
            "Windows": OS.WINDOWS,
            "Linux": OS.LINUX,
            "Darwin": OS.MACOS,
        }
        if system not in mapping:
            raise NotImplementedError(f"unsupported OS: {system}")
        return mapping[system]


def on_windows():
    return OS.current() is OS.WINDOWS


def on_windows_like():
    os = OS.current()
    return os is OS.WINDOWS


def on_linux():
    return OS.current() is OS.LINUX


def on_linux_like():
    os = OS.current()
    return os is OS.LINUX or os is OS.MACOS