xref: /build/indep_configs/scripts/utils.py (revision 5f9996aa)
15f9996aaSopenharmony_ci#!/usr/bin/env python
25f9996aaSopenharmony_ci# -*- coding: utf-8 -*-
35f9996aaSopenharmony_ci# Copyright (c) 2024 Huawei Device Co., Ltd.
45f9996aaSopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License");
55f9996aaSopenharmony_ci# you may not use this file except in compliance with the License.
65f9996aaSopenharmony_ci# You may obtain a copy of the License at
75f9996aaSopenharmony_ci#
85f9996aaSopenharmony_ci#     http://www.apache.org/licenses/LICENSE-2.0
95f9996aaSopenharmony_ci#
105f9996aaSopenharmony_ci# Unless required by applicable law or agreed to in writing, software
115f9996aaSopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS,
125f9996aaSopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
135f9996aaSopenharmony_ci# See the License for the specific language governing permissions and
145f9996aaSopenharmony_ci# limitations under the License.
155f9996aaSopenharmony_ci
165f9996aaSopenharmony_ciimport json
175f9996aaSopenharmony_ciimport os
185f9996aaSopenharmony_ciimport stat
195f9996aaSopenharmony_ci
205f9996aaSopenharmony_ci
215f9996aaSopenharmony_cidef get_json(file_path):
225f9996aaSopenharmony_ci    data = {}
235f9996aaSopenharmony_ci    try:
245f9996aaSopenharmony_ci        with open(file_path, 'r') as f:
255f9996aaSopenharmony_ci            data = json.load(f)
265f9996aaSopenharmony_ci    except FileNotFoundError:
275f9996aaSopenharmony_ci        print(f"can not find file: {file_path}.")
285f9996aaSopenharmony_ci    except Exception as e:
295f9996aaSopenharmony_ci        print(f"{file_path}: \n {e}")
305f9996aaSopenharmony_ci    return data