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