• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2#
3# Copyright 2018 - The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#     http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17"""An enum class to provide the running platform OS info.
18
19AndroidDevOS provides 2 functions to get info from current platform type, it
20maps strings got from python standard library method 'platform.system()' to 3
21types of OS platform, i.e., Linux, Mac, and Windows.
22
23    Class functions:
24        get_os_type, which returns a relevant enum object for current platform.
25        get_os_name, which returns the platform OS name in upper case.
26"""
27
28from enum import Enum, unique
29
30import platform
31
32
33@unique
34class AndroidDevOS(str, Enum):
35    """The string enum class identifies the OS for Android development.
36
37    Currently, it can identify 3 types of OS, e.g., Mac, Linux, and Windows.
38    And transform the os name into a meaningful platform name.
39    """
40
41    MAC = 'Darwin'
42    LINUX = 'Linux'
43    WINDOWS = 'Windows'
44
45    @classmethod
46    def get_os_name(cls):
47        """Get the actual OS name.
48
49        Return:
50            AndroidDevOS enum, the os type name for current environment.
51        """
52        return cls.get_os_type().name
53
54    @classmethod
55    def get_os_type(cls):
56        """get current OS type.
57
58        Return:
59            AndroidDevOS enum object, mapped to relevant platform.
60        """
61        return {
62            'Darwin': cls.MAC,
63            'Linux': cls.LINUX,
64            'Windows': cls.WINDOWS
65        }.get(platform.system(), cls.LINUX)
66