15f9996aaSopenharmony_ci#!/usr/bin/env python3 25f9996aaSopenharmony_ci# -*- coding: utf-8 -*- 35f9996aaSopenharmony_ci 45f9996aaSopenharmony_ci# 55f9996aaSopenharmony_ci# Copyright (c) 2023 Huawei Device Co., Ltd. 65f9996aaSopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License"); 75f9996aaSopenharmony_ci# you may not use this file except in compliance with the License. 85f9996aaSopenharmony_ci# You may obtain a copy of the License at 95f9996aaSopenharmony_ci# 105f9996aaSopenharmony_ci# http://www.apache.org/licenses/LICENSE-2.0 115f9996aaSopenharmony_ci# 125f9996aaSopenharmony_ci# Unless required by applicable law or agreed to in writing, software 135f9996aaSopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS, 145f9996aaSopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 155f9996aaSopenharmony_ci# See the License for the specific language governing permissions and 165f9996aaSopenharmony_ci# limitations under the License. 175f9996aaSopenharmony_ci# 185f9996aaSopenharmony_ci 195f9996aaSopenharmony_cifrom services.hpm import CMDTYPE 205f9996aaSopenharmony_cifrom modules.interface.install_module_interface import InstallModuleInterface 215f9996aaSopenharmony_cifrom resolver.interface.args_resolver_interface import ArgsResolverInterface 225f9996aaSopenharmony_cifrom exceptions.ohos_exception import OHOSException 235f9996aaSopenharmony_cifrom services.interface.build_file_generator_interface import BuildFileGeneratorInterface 245f9996aaSopenharmony_cifrom util.log_util import LogUtil 255f9996aaSopenharmony_cifrom containers.status import throw_exception 265f9996aaSopenharmony_ci 275f9996aaSopenharmony_ci 285f9996aaSopenharmony_ciclass OHOSInstallModule(InstallModuleInterface): 295f9996aaSopenharmony_ci 305f9996aaSopenharmony_ci _instance = None 315f9996aaSopenharmony_ci 325f9996aaSopenharmony_ci def __init__(self, args_dict: dict, args_resolver: ArgsResolverInterface, hpm: BuildFileGeneratorInterface): 335f9996aaSopenharmony_ci super().__init__(args_dict, args_resolver) 345f9996aaSopenharmony_ci self._hpm = hpm 355f9996aaSopenharmony_ci OHOSInstallModule._instance = self 365f9996aaSopenharmony_ci 375f9996aaSopenharmony_ci @property 385f9996aaSopenharmony_ci def hpm(self): 395f9996aaSopenharmony_ci return self._hpm 405f9996aaSopenharmony_ci 415f9996aaSopenharmony_ci @staticmethod 425f9996aaSopenharmony_ci def get_instance(): 435f9996aaSopenharmony_ci if OHOSInstallModule._instance is not None: 445f9996aaSopenharmony_ci return OHOSInstallModule._instance 455f9996aaSopenharmony_ci else: 465f9996aaSopenharmony_ci raise OHOSException( 475f9996aaSopenharmony_ci 'OHOSInstallModule has not been instantiated', '0000') 485f9996aaSopenharmony_ci 495f9996aaSopenharmony_ci @throw_exception 505f9996aaSopenharmony_ci def run(self): 515f9996aaSopenharmony_ci try: 525f9996aaSopenharmony_ci super().run() 535f9996aaSopenharmony_ci except OHOSException as exception: 545f9996aaSopenharmony_ci raise exception 555f9996aaSopenharmony_ci else: 565f9996aaSopenharmony_ci LogUtil.hb_info('{} build success') 575f9996aaSopenharmony_ci 585f9996aaSopenharmony_ci def _install(self): 595f9996aaSopenharmony_ci self._run_phase() 605f9996aaSopenharmony_ci self.hpm.execute_hpm_cmd(CMDTYPE.INSTALL) 615f9996aaSopenharmony_ci 625f9996aaSopenharmony_ci def _run_phase(self): 635f9996aaSopenharmony_ci for arg in self.args_dict.values(): 645f9996aaSopenharmony_ci self.args_resolver.resolve_arg(arg, self)