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_ciimport os 205f9996aaSopenharmony_ciimport sys 215f9996aaSopenharmony_ciimport importlib 225f9996aaSopenharmony_ciimport importlib.util 235f9996aaSopenharmony_ci 245f9996aaSopenharmony_ci 255f9996aaSopenharmony_cidef is_in_ohos_dir(): 265f9996aaSopenharmony_ci cur_dir = os.getcwd() 275f9996aaSopenharmony_ci while cur_dir != "/": 285f9996aaSopenharmony_ci global_var = os.path.join( 295f9996aaSopenharmony_ci cur_dir, 'build', 'hb', 'resources', 'global_var.py') 305f9996aaSopenharmony_ci if os.path.exists(global_var): 315f9996aaSopenharmony_ci return True, cur_dir 325f9996aaSopenharmony_ci cur_dir = os.path.dirname(cur_dir) 335f9996aaSopenharmony_ci return False, '' 345f9996aaSopenharmony_ci 355f9996aaSopenharmony_ci 365f9996aaSopenharmony_cidef main(): 375f9996aaSopenharmony_ci in_ohos_dir, ohos_root_path = is_in_ohos_dir() 385f9996aaSopenharmony_ci if in_ohos_dir : 395f9996aaSopenharmony_ci entry_path = os.path.join(os.path.abspath(os.path.relpath( 405f9996aaSopenharmony_ci ohos_root_path, os.path.curdir)), 'build', 'hb', 'main.py') 415f9996aaSopenharmony_ci spec = importlib.util.spec_from_file_location('main', entry_path) 425f9996aaSopenharmony_ci api = importlib.util.module_from_spec(spec) 435f9996aaSopenharmony_ci spec.loader.exec_module(api) 445f9996aaSopenharmony_ci main_api = api.Main() 455f9996aaSopenharmony_ci main_api.main() 465f9996aaSopenharmony_ci else: 475f9996aaSopenharmony_ci raise Exception( 485f9996aaSopenharmony_ci "[OHOS_ERROR]: Please call hb utilities inside ohos source directory") 495f9996aaSopenharmony_ci 505f9996aaSopenharmony_ci 515f9996aaSopenharmony_ciif __name__ == "__main__": 525f9996aaSopenharmony_ci sys.exit(main()) 53