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.update_module_interface import UpdateModuleInterface
26from util.component_util import ComponentUtil
27from exceptions.ohos_exception import OHOSException
28from services.hpm import CMDTYPE
29
30
31class UpdateArgsResolver(ArgsResolverInterface):
32
33    def __init__(self, args_dict: dict):
34        super().__init__(args_dict)
35
36    @staticmethod
37    def resolve_part(target_arg: Arg, update_module: UpdateModuleInterface):
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            update_module.hpm.regist_flag('part_name', part_name)
43
44    @staticmethod
45    def resolve_global(target_arg: Arg, update_module: UpdateModuleInterface):
46        if target_arg.arg_value == True or target_arg.arg_value == '':
47            update_module.hpm.regist_flag('global', '')