1# -*- coding: utf-8 -*- 2# Copyright (c) 2023 Huawei Device Co., Ltd. 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14#!/usr/bin/python3 15 16# import subprocess 17# import pandas as pd 18# import urllib.parse 19import os 20import sys 21sys.path.append(os.path.dirname(os.path.realpath(__file__)) + os.sep) 22from common import * 23from apl_config import * 24import json 25log_tag = 'read_whitelist' 26 27# # 全部文件夹检出(本地已经安装svn) 28# def svn_checkout(settings): 29# try: 30# print(settings['url']) 31# print(settings['dir']) 32# os.chdir(settings['svn']) 33# cmd = 'svn export --force %(url)s %(dir)s --username %(user)s --password %(pwd)s'%settings 34# p = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE) 35# stdout,stderr = p.communicate() 36# print(stderr) 37# if stderr != b'': 38# raise AplCompareException(str(stderr,'utf-8').replace('\r\n','\t')) 39# apl_set_log_content(LogLevel(2).name, log_tag, '{} export successful!'.format(settings['dir'])) 40# return settings['dir'] 41# except Exception as e: 42# apl_set_log_content(LogLevel(1).name, log_tag, "{}".format(e.msg)) 43# return None 44# 45# #url编码 46# def url_encode(url): 47# partions=url.split("/",3) 48# encode_url=partions[0] 49# partions[-1]=urllib.parse.quote(partions[-1]) 50# for partion in partions[1:]: 51# encode_url=encode_url+'/'+partion 52# return encode_url 53# 54# def read_excel(file, sheet, cols): 55# try: 56# df = pd.read_excel(file, sheet_name = sheet, usecols = cols) 57# data_list = df.values.tolist() 58# apl_map = set_map(data_list) 59# apl_set_log_content(LogLevel(2).name, log_tag, '{} read successful!'.format(file)) 60# return apl_map 61# except (ValueError,FileNotFoundError) as e: 62# apl_set_log_content(LogLevel(1).name, log_tag, "{}".format(e.msg)) 63# return None 64# 65 66def read_json(path): 67 try: 68 with open(path, 'r') as f: 69 file = f.read() 70 data_list = json.loads(file) 71 res_dict = set_dict(data_list) 72 return res_dict 73 except Exception as e: 74 apl_set_log_content(LogLevel(1).name, log_tag, '{}'.format(e.msg)) 75 return None 76 77def set_dict(data_list: list()): 78 res_dict = {} 79 for res in data_list: 80 res_dict[res['bundle&processName']] = res['apl'] 81 return res_dict