1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3
4#
5# Copyright (c) 2023 Huawei Device Co., Ltd.
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10#     http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18
19import os
20import sys
21
22from containers.arg import Arg
23from containers.arg import ModuleType
24from resolver.interface.args_resolver_interface import ArgsResolverInterface
25from modules.interface.install_module_interface import InstallModuleInterface
26from util.component_util import ComponentUtil
27from exceptions.ohos_exception import OHOSException
28from services.hpm import CMDTYPE
29
30
31class InstallArgsResolver(ArgsResolverInterface):
32
33    def __init__(self, args_dict: dict):
34        super().__init__(args_dict)
35
36    @staticmethod
37    def resolve_part(target_arg: Arg, install_module: InstallModuleInterface):
38        part_name = target_arg.arg_value
39        if len(sys.argv) > 2 and not sys.argv[2].startswith("-"): # 第一个部件名参数
40            part_name = sys.argv[2]
41        if part_name:
42            install_module.hpm.regist_flag('part_name', part_name)
43
44
45    @staticmethod
46    def resolve_global(target_arg: Arg, install_module: InstallModuleInterface):
47        if target_arg.arg_value == True or target_arg.arg_value == '':
48            install_module.hpm.regist_flag('global', '')
49
50    @staticmethod
51    def resolve_local(target_arg: Arg, install_module: InstallModuleInterface):
52        if target_arg.arg_value:
53            install_module.hpm.regist_flag('local', target_arg.arg_value)
54
55    @staticmethod
56    def resolve_variant(target_arg: Arg, install_module: InstallModuleInterface):
57        if target_arg.arg_value:
58            install_module.hpm.regist_flag('defaultDeps', ComponentUtil.get_default_deps(target_arg.arg_value))
59        else:
60            install_module.hpm.regist_flag('defaultDeps', ComponentUtil.get_default_deps("default"))