genPanel.py

#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os
import sys
import re
import shutil
import glob
'''
脚本使用说明 
             1. 执行命令./genPanel.py -a 分辨率 :代表生成这种分辨率的软件包
             2. 如果想要编译特定的几个分辨率的软件,可在make radissonconfig中选择多个分辨率,然后执行命令./genPanel.py -b 即可
'''
cfgFileName = "radisson.config"
buildNowfile = "../BUILD_RECORD/BUILD_NOW.h"
g_ratioAMode = 0
g_ratioBMode = 0 
def CreatebinDir(): 
    global binDir
    try:
        fd = open(cfgFileName, "r")
        data = fd.readlines()
        for linedata in data:
            if re.search("^CONFIG_CUSDEF_MI.*",linedata):
         #获取字串linedata以“_”分开的第四个字串,linedata.split('_')返回一个列表 Customer = (linedata.split('_'))[3] elif re.search("^CONFIG_CUSDEF_BD.*",linedata): ChipType = (linedata.split('_'))[4] BoardType = (linedata.split('_'))[5].split('=')[0] BDCfg = ChipType+"_"+BoardType binDir = Customer+"_"+BDCfg fd.close() except IOError as err: binDir = "binFile" print('File Error: ' + str(err)) if os.path.exists(binDir): shutil.rmtree(binDir) os.mkdir(binDir) #编译某一分辨率的所有软件。 def RatioA(Resolution): PANEL_floder_path = ("../CUS_FILE/PN").replace('"','') for dirPath, dirNames, fileNames in os.walk(PANEL_floder_path): break for panelName in dirNames: #筛选符合需求的分辨率 if Resolution not in panelName: continue print "===Start Panel %s Please Wait ===" %panelName listSave = [] try: cfgFile = open(buildFile,"r") list = cfgFile.readlines() for each in list: if re.search("^#define PN_CUSDEF.*",each): continue else: listSave.append(each) each = "#define PN_CUSDEF %s" %(panelName) listSave.append(each) listSave.append("\n") cfgFile = open(buildFile,"w") cfgFile.writelines(listSave) cfgFile.close() except IOError as err: print('File Error: ' + str(err)) os.system('make clean;./build_history.sh') #将生成的bin文件移进软件包目录
     #glob模块返回一个完整的路径列表,而不是查找到的文件名 binPath=glob.glob(r"./mergedir/RR*.bin") if len(binPath) != 0: os.mkdir(panelName) shutil.copy(binPath[0],panelName) shutil.move(panelName,binDir) else: print "compile error!" sys.exit() #编译make radissonconfig中选中的多个分辨率 def RatioB(): try: panelSet = [] setStr = set() cfgFile = open(buildFile,"r") list = cfgFile.readlines() for each in list: if re.search("^#define PN_CUSDEF\d?(.*)",each): setStr.add(re.search("^#define PN_CUSDEF\d?(.*)",each).group(1)) for line in setStr: line1=line.strip() panelSet.append(line1) except IOError as err: print('File Error: ' + str(err)) for panelName in panelSet: print "===Start Panel %s Please Wait ===" %panelName listSave = [] try: cfgFile = open(buildFile,"r") list = cfgFile.readlines() for each in list: if re.search("^#define PN_CUSDEF .*",each): continue else: listSave.append(each) each = "#define PN_CUSDEF %s" %(panelName) listSave.append(each) listSave.append("\n") cfgFile = open(buildFile,"w") cfgFile.writelines(listSave) cfgFile.close() except IOError as err: print('File Error: ' + str(err)) os.system('make clean;./build_history.sh') #将生成的bin文件移进软件包目录 binPath=glob.glob(r"./mergedir/RR*.bin") if len(binPath) != 0: os.mkdir(panelName) shutil.copy(binPath[0],panelName) shutil.move(panelName,binDir) else: print "compile error!" sys.exit() def fun_parse_InputParam(): global g_ratioAMode global g_ratioBMode #获取脚本带入参数的长度 if len(sys.argv) < 2: print "The number of parameters is wrong!" sys.exit() else:
    #sys.argv[1]表示脚本带入的第一个的参数 opt1 = sys.argv[1] opt2 = ["1366x768","1440x900","1024x768","1400x1050","1920x1080","1024x600","1280x1024","1280x800","1400x1050","1600x900","1680x1050","1920x1200","1600x1200"] if opt1 == "-a" and len(sys.argv) == 3: g_ratioAMode = 1 if sys.argv[2] not in opt2: print("parameter2: unhandled option!") sys.exit() elif opt1 == "-b" and len(sys.argv) == 2: g_ratioBMode = 1 else: print("parameter error!") sys.exit() if __name__ == "__main__": #处理脚本带入的参数 fun_parse_InputParam() #从BUILD_NOW.h中获取build_setting.h所在的目录名 try: buildNow = open(buildNowfile,"r") list = buildNow.readlines() for line in list: if re.search("^#define BUILD_NAME .*",line): buildDir = re.search("^#define BUILD_NAME (.*)",line).group(1) buildNow.close() except IOError as err: print('File Error: ' + str(err)) buildFile = "../BUILD_RECORD/"+buildDir+"/BUILD_SETTING.h" #创建软件包目录 CreatebinDir() if g_ratioAMode: #编译某一分辨率的所有软件。 RatioA(sys.argv[2]) if g_ratioBMode: #编译make radissonconfig中选中的多个分辨率 RatioB()
posted @ 2018-01-26 16:32  轻轻的吻  阅读(287)  评论(0编辑  收藏  举报