#!/usr/bin/env python
#encoding: utf-8
import sys
import os
import string
import shutil
import xml.etree.ElementTree
import getopt
import subprocess
import commands
import xlwt
import xlrd
import sys
reload(sys)
sys.setdefaultencoding('utf8')
SCRIPT_VERSION = "v4.0"
#riox只有外销,暂时不支持区分内外销
NX_EXP_VERSION="外销"
#python xxxxx.py argv[1]<代码根目录> argv[2]<ProductName>
#CODE_DIR = sys.argv[1]
CODE_DIR = "../../../../../"
#PRODUCT_NAME = '_'.join(sys.argv[2].split('_')[0:-1])
PRODUCT_NAME = "ums9230_hulk"
#product out目录
TARGET_OUT = CODE_DIR+"/out/target/product/"+PRODUCT_NAME
#presoftware目录
#presoftware_dir = TARGET_OUT+"/presoftware"
presoftware_dir = "./"
#aapt工具目录
AAPT_TOOLS = CODE_DIR+"/prebuilts/sdk/tools/linux/bin"
#app_config.xml
app_config = CODE_DIR+"/vendor/huaqin/Android/copy_modules/system/etc/app_config.xml"
#出货地区文件region_config.txt vendor\huaqin\release\script
region_config = "./region_config.txt"
#region_config = CODE_DIR+"/vendor/huaqin/release/script/region_config.txt"
class Country:
def __init__(self, region, nv_id, regionmark, operator):
self.appinfo_list = []
#地区的名称
self.region = region
#地区的国家码
self.regionmark = regionmark
#对应运营商
self.operator = operator
#nv_id
self.nv_id = nv_id
self.init_apkinfo()
def init_apkinfo(self):
try:
with open(app_config) as xml_in:
registry = xml.etree.ElementTree.fromstring(xml_in.read())
for registry_package in registry.iter('package'):
# get region set
if ('country' in registry_package.attrib and 'path' in registry_package.attrib and 'operator' in registry_package.attrib):
country_xml_value = registry_package.attrib['country']
country_xml_list = country_xml_value.strip().split(',')
operator_xml_value = registry_package.attrib['operator']
operator_xml_list = operator_xml_value.strip().split(',')
path_xml_value = registry_package.attrib['path']
#if path_xml_value.startswith("/mnt/my_preload"):
# path_xml_value = path_xml_value[4:]
#print("country_xml_list = ", country_xml_list)
#print("operator_xml_list = ", operator_xml_list)
#print("path_xml_value = ", path_xml_value)
is_region = False
is_operator = False
#地区校验
if ((self.regionmark in country_xml_list) or ("common" in country_xml_list)):
is_region = True
if (country_xml_list[0].startswith("-") and "-"+self.regionmark not in country_xml_list):
is_region = True
#运营商校验
if ((self.operator in operator_xml_list) or ("common" in operator_xml_list)):
is_operator = True
if (operator_xml_list[0].startswith("-") and "-"+self.operator not in operator_xml_list):
is_operator = True
if is_region and is_operator:
apk_file = TARGET_OUT + path_xml_value
if os.path.exists(apk_file):
print("apk_file=", apk_file)
info = ApkInfo(apk_file)
self.appinfo_list.append(info)
except xml.etree.ElementTree.ParseError, e:
print("parse app_config xml error")
sys.exit(1)
myPreloadPath = TARGET_OUT + "/my_preload" + self.nv_id + "/preloadapp"
myPreloadList = os.listdir(myPreloadPath)
for i in range(0, len(myPreloadList)):
path = os.path.join(myPreloadPath, myPreloadList[i])
apk_file = path + "/" + myPreloadList[i] + ".apk"
if os.path.exists(apk_file):
print("apk_file=", apk_file)
info = ApkInfo(apk_file)
self.appinfo_list.append(info)
class ApkInfo:
def __init__(self, apk_file):
self.apk_lable = cmd_run(AAPT_TOOLS + "/aapt d badging " + apk_file
+ " | grep 'application-label:' | sed 's/^.*application-label:'\\''//g' | sed 's/'\\''.*//g'", 'get app lable', back = True)
self.apk_package = cmd_run(AAPT_TOOLS + "/aapt d badging " + apk_file
+ " | grep 'package: name' | sed 's/^.*package: name='\\''//g' | sed 's/'\\''.*//g'", 'get app name', back = True)
self.apk_version = cmd_run(AAPT_TOOLS + "/aapt d badging " + apk_file
+ " | grep 'versionName=' | sed 's/^.*versionName='\\''//g' | sed 's/'\\''.*//g'", 'get app verion', back = True)
def cmd_run(cmd, flag, errorCheck = True, back = False):
status = None
output = None
try:
(status, output) = commands.getstatusoutput(cmd)
if status == 0:
#print flag + ' ok!!'
pass
else:
if errorCheck:
print 'Error: ' + flag + ' failed!!!'
raise SystemError
finally:
if errorCheck:
#print output
pass
#print '*' * 100
if back:
return output
def read_file_to_set(file):
readin = set()
if os.path.exists(file):
for line in open(file):
readin.add(line)
else:
print(file+" not exist!")
exit()
return readin
def init_software_version():
version = []
for prop_file in prop_file_list:
if os.path.exists(prop_file):
for line in open(prop_file):
if "ro.build.version.ota" in line:
value_array = line.strip().split('=')
if len(value_array) == 2:
version.append(value_array[1])
break
return version
def init_country_list():
c_list=[]
read_set = read_file_to_set(region_config)
print('region count =',read_set.__len__())
if read_set.__len__() != 0:
for item in read_set:
value_array = item.strip().split('#')
if len(value_array) == 4:
country = Country(value_array[0], value_array[1], value_array[2], value_array[3])
c_list.append(country)
return c_list
def init_excel_file():
global excel_line
excel_line = 0
if not os.path.exists(presoftware_dir):
os.makedirs(presoftware_dir)
presoftware_excel = xlwt.Workbook()
presoftware_sheet = presoftware_excel.add_sheet('presoftware')
presoftware_sheet.write(excel_line, 0, unicode("机型"))
presoftware_sheet.write(excel_line, 1, unicode("国家"))
presoftware_sheet.write(excel_line, 2, unicode("软件版本"))
presoftware_sheet.write(excel_line, 3, unicode("应用名称"))
presoftware_sheet.write(excel_line, 4, unicode("应用包名"))
presoftware_sheet.write(excel_line, 5, unicode("应用版本"))
presoftware_sheet.write(excel_line, 6, unicode("内外销标识"))
presoftware_sheet.write(excel_line, 7, unicode("脚本版本"))
presoftware_sheet.write(excel_line, 8, unicode("NV_ID"))
presoftware_sheet.write(excel_line, 9, unicode("应用位置"))
presoftware_sheet.write(excel_line, 10, unicode("region_key"))
presoftware_sheet.write(excel_line, 11, unicode("carrier_key"))
presoftware_sheet.write(excel_line, 12, unicode("应用渠道文件名"))
presoftware_sheet.col(0).width = 256*15
presoftware_sheet.col(1).width = 256*15
presoftware_sheet.col(2).width = 256*30
presoftware_sheet.col(3).width = 256*30
presoftware_sheet.col(4).width = 256*30
presoftware_sheet.col(5).width = 256*30
presoftware_sheet.col(6).width = 256*15
presoftware_sheet.col(7).width = 256*15
presoftware_sheet.col(8).width = 256*15
presoftware_sheet.col(9).width = 256*15
presoftware_sheet.col(10).width = 256*15
presoftware_sheet.col(11).width = 256*15
presoftware_sheet.col(12).width = 256*30
return presoftware_excel,presoftware_sheet
def convert_file(presoftware_excel, presoftware_sheet, country_list, product_name, software_version):
global excel_line
for country_item in country_list:
for info_item in country_item.appinfo_list:
excel_line = excel_line +1
presoftware_sheet.write(excel_line, 0, unicode(product_name))
presoftware_sheet.write(excel_line, 1, unicode(country_item.region))
presoftware_sheet.write(excel_line, 2, unicode(software_version))
presoftware_sheet.write(excel_line, 3, unicode(info_item.apk_lable))
presoftware_sheet.write(excel_line, 4, unicode(info_item.apk_package))
presoftware_sheet.write(excel_line, 5, unicode(info_item.apk_version))
presoftware_sheet.write(excel_line, 6, unicode(NX_EXP_VERSION))
presoftware_sheet.write(excel_line, 7, unicode(SCRIPT_VERSION))
presoftware_sheet.write(excel_line, 8, unicode(country_item.nv_id))
#close excel
presoftware_excel.save(unicode(presoftware_dir + "/presoftware_list.xls"))
return
def create_911_file(country_list):
if os.path.exists("./productinfo"):
shutil.rmtree("./productinfo")
print("rm dir = ./productinfo")
os.mkdir("./productinfo")
for country_item in country_list:
file_path = "./productinfo/prebuildapplist_" + country_item.nv_id
f = open(file_path, "w")
for info_item in country_item.appinfo_list:
if is_disable_app(info_item.apk_package):
continue
f.write(info_item.apk_package + "\n")
f.close()
print("create_911_file done!")
#ifdef ODM_HQ_EDIT
#zhouguifei@ODM_HQ, 2023/08/25
#判断传入的包名是否为开机之后会被disable的应用,这些应用需要在真关机名单中去除
def is_disable_app(apk_package):
#开机之后被disable掉的应用包名数组,如后续有其他应用开机之后被禁,需要在此添加包名
disabled_app_list=["com.bijoy.androidkeyboard","com.bijoyapp.androidkeyboard","com.payjoy.access","com.oplus.payjoy",
"com.miclaro.app","com.clarocolombia.miclaro","com.claro.pe.miclaro","com.instagram.android","com.ayoba.ayoba","com.momosa","com.mtnsar3"]
if apk_package in disabled_app_list:
return True
else:
return False
#endif ODM_HQ_EDIT
excel_line = 0
if __name__ == '__main__':
#print(sys.argv[1],sys.argv[2])
#software_version_list = init_software_version()
#print("software version count:",len(software_version_list))
country_list = init_country_list()
#excel,sheet = init_excel_file()
#convert_file(excel, sheet, country_list, PRODUCT_NAME, "null")
create_911_file(country_list)
file_path = "./productinfo/prebuildapplist_" + country_item.nv_id
这个文件在哪获取的