#!/usr/bin/python
#coding:UTF-8 import sys
import re
import getopt
import md5
import os
import subprocess
import shutil
import xlrd
import xlwt
from xlutils.copy import copy #from subprocess import call g_bAllBin = 0
g_bAllBinbyId = 0
g_bDecrypt = 0
g_binDir = "./decryptDir"
g_strBinPath="./"
g_BinSplitext=[".BIN", ".bin"]
g_listBoard = ["VR01A", "VR01AX", "VR01B"]
g_listUI = ["videocon", "sansui", "philips"]
g_listMode = [] mapModeCode = {}
g_headerLen = 16*1024
g_listBin=[] '''
解密当前目录BIN文件到 decryptDir文件夹
运行命令:
python gen_codebin.py -d VIL 服务软件:
运行命令: 编译全部modeCode
python gen_codebin.py -a 编译EXCEL文档包含的MODELCODE
python gen_codebin.py -i [./] 将当前目录所有的BIN打包为“VIL_SER.BIN”
python gen_codebin.py [-p] 打包格式为:HEAD长度+BIN总数+BIN_1名字+BIN_1长度+....BIN_N名字+BIN_N长度+版本号+BIN内容
步骤:
先读取“Design Data.xls”得到需要的打包ModeID,然后根据ModeID逐个进行编译。再将编译完成的BIN打包
''' def fun_get_head_info():
try:
raise Exception
except:
f = sys.exc_info()[2].tb_frame.f_back
print("[debug]function :%s, line :%s"%(f.f_code.co_name, str(f.f_lineno))) def usage():
print'''param error.''' def fun_parse_InputParam():
global g_bAllBin
global g_bDecrypt
global g_strBinPath
global g_bAllBinbyId
try:
opts, args = getopt.getopt(sys.argv[1:], 'hi:dpa')
except getopt.GetoptError, err:
print str(err)
usage()
sys.exit() for op, value in opts:
if op == "-i":
g_bAllBin = 1
g_strBinPath = value
elif op == "-p":
g_bAllBin = 0
elif op == "-a":
g_bAllBinbyId = 1
elif op == "-d":
g_bDecrypt = 1
elif op == "-h":
usage()
sys.exit()
else:
print("unhandled option")
sys.exit() #==生成BIN LIST==#
def fun_getBinList(Path):
for item in os.listdir(Path):
abs_item=os.path.join(Path, item)
if os.path.isdir(abs_item):
fun_getBinList(abs_item)
elif os.path.isfile(abs_item):
if os.path.splitext(abs_item)[1] in g_BinSplitext:
g_listBin.append(abs_item)
#print abs_item
else:
pass
else:
pass
return def fun_decryptBinFile(listBin):
os.mkdir(g_binDir)
os.system('gcc -m32 -o decrypt decrypt.c')
for line in listBin:
outfile = ""
strCmd = "./decrypt %s" %line
os.system(strCmd)
outfile = "./decrypt_%s" %(line[2:])
shutil.move(outfile,g_binDir) def fun_genCombinationbin(binCombinFile, str_BinTable, str_BinData):
print str_BinTable
with open(str_BinTable) as binTable_op:
#print binTable_op
for line in binTable_op:
binCombinFile.write(line)
binCombinFile.seek(g_headerLen) with open(str_BinData) as bindata1_op:
for line in bindata1_op:
binCombinFile.write(line) return def fun_GetBinTableandBin(list_binpath, binTable_op, binData_op):
strTable=""
for binpath in list_binpath:
with open(binpath,"r+") as binFile:
binFile.truncate(4*1024*1024)#(0x3e083c) FLASH编译大小
for line in binFile:
binData_op.write(line) binname = os.path.basename(binpath)
binsize = os.path.getsize(binpath)
#删除每个文件的扩展名.bin
binname = binname[:-4]
strTable=binname+","+str(binsize)+","
print strTable
binTable_op.write(strTable)
#os.remove(binpath)
#写默认版本号为1
binTable_op.write("1,") def fun_getBinCountToProject():
with open("../aps/application/radisson/videocon/sys_common_guiobj/app_guiobj_setup.c", "r") as project_op:
temStr = '#define CONFIG_FLASH_BIN_COUNT ' + str(len(g_listBin))
print temStr
content = project_op.read() pos = content.find('#define CONFIG_FLASH_BIN_COUNT')
if pos != -1:
pos_end = content[pos:].find('\n')
print '======================================='
print 'pos = %d, pos_end = %d' %(pos, pos_end)
content = content[:pos] + temStr + content[pos + pos_end:]
with open("../aps/application/radisson/videocon/sys_common_guiobj/app_guiobj_setup.c", "w") as project_op:
project_op.write(content) def fun_getMapModeCode():
#读EXCEL到映射表
book = xlrd.open_workbook(r'Design Data.xls')
sheet = book.sheet_by_index(0) for row in range(sheet.nrows):
bFindModeId = False
for col in range(sheet.ncols):
cellStr = str(sheet.cell(row,col).value)
cellStr.rstrip()
if cellStr == "MODEL ID":
bFindModeId = True
break
if bFindModeId:
break for id in range(row+1,sheet.nrows):
listValue = []
strMode = sheet.cell(id,col).value
if len(strMode) <= 8:
continue
listValue.append(strMode)
if sheet.cell(id,col-3).value != "":
strBoard = sheet.cell(id,col-3).value
listValue.append(strBoard)
listValue.append("videocon" if sheet.cell(id,col-4).value == "V" else "sansui")
mapModeCode[id-row] = listValue def fun_modifyCommonPatchFile(strMode):
modeId = ""
for board in g_listBoard:
for line in open("../aps/customer/radisson/%s/adaptable/model_data.c" %board,"r"):
if strMode in line and re.search(".*?(\d+).*\{.*",line):
modeId = re.search(".*?(\d+).*\{.*",line).group(1)
with open("../aps/include/common_patch.h","r") as file:
tempStr = "#define DEFAULT_MODE_ID " + modeId
content = file.read()
pos = content.find("#define DEFAULT_MODE_ID")
if pos != -1:
pos_end = content[pos:].find('\n')
content = content[:pos] + tempStr + content[pos + pos_end:]
with open("../aps/include/common_patch.h", "w") as project_op:
project_op.write(content)
return True
return False def fun_genAllSerBin():
listSave = []
fun_getMapModeCode()
with open("../mconfig.config", "r") as mFile:
list = mFile.readlines()
for (k,v) in mapModeCode.items():
strMode = v[0]
board = v[1]
ui = v[2]
if fun_modifyCommonPatchFile(strMode) == False:
continue
os.system('cd ..; make clean')
for line in list:
if "#" in line:
continue
elif line.find("CONFIG_BOARD_") != -1 :
line = "CONFIG_BOARD_%s__RADISSON__RADISSON__RADISSON=y\n" %(board)
listSave.append(line)
elif line.find("CONFIG_MODEL_BOARD_NAME") != -1:
line = "CONFIG_MODEL_BOARD_NAME=\"%s\"\n" %(board)
listSave.append(line)
elif line.find("CONFIG_PROJECT_NAME") != -1 :
line = "CONFIG_PROJECT_NAME=\"%s___%s___ATV\"\n" %(board,ui)
listSave.append(line)
elif line.find("CONFIG_APP_FOLDER_NAME") != -1:
line = "CONFIG_APP_FOLDER_NAME=\"%s\"\n" %(ui)
listSave.append(line)
elif re.search("CONFIG_.*___ATV__RADISSON__RADISSON__RADISSON",line):
line = "CONFIG_%s_%s___ATV__RADISSON__RADISSON__RADISSON=y\n" %(board,ui.upper())
listSave.append(line)
else:
listSave.append(line)
with open("../mconfig.config", "w") as mFile:
mFile.writelines(listSave)
listSave = [] shutil.copy("../aps/customer/radisson/sub_customer/radisson/radisson/project/%s___%s___ATV.config" %(board,ui), "../menuconfig.config")
os.system('cd ..; make clean; make -j') if ui == "videocon" and os.path.exists("../mergedir/VIDEOCON.code.bin"):
shutil.copy("../mergedir/VIDEOCON.code.bin","../kitking/%s.bin" %strMode)
elif ui == "philips" and os.path.exists("../mergedir/PHILIPS.code.bin"):
shutil.copy("../mergedir/PHILIPS.code.bin","../kitking/%s.bin" %strMode)
elif ui == "sansui" and os.path.exists("../mergedir/SANSUI.code.bin"):
shutil.copy("../mergedir/SANSUI.code.bin","../kitking/%s.bin" %strMode) #print k,strMode,board,ui
#var = raw_input("debug pause:") def fun_searchModeCode(board):
global g_listMode
global mapModeCode
g_listMode = []
mapModeCode = {}
modeId = ""
for line in open("../aps/customer/radisson/%s/adaptable/model_data.c" %board,"r"):
if re.search(".*?(\d+).*\{.*\"(.*)\".*",line):
modeId = re.search(".*?(\d+).*\{.*",line).group(1)
strMode = re.search(".*?(\d+).*\{.*\"(.*)\".*",line).group(2)
mapModeCode[modeId] = strMode
g_listMode.append(strMode)
return modeId def fun_genCommonPatchFilebyId(modeId):
with open("../aps/include/common_patch.h","r") as file:
tempStr = "#define DEFAULT_MODE_ID " + modeId
content = file.read()
pos = content.find("#define DEFAULT_MODE_ID")
if pos != -1:
pos_end = content[pos:].find('\n')
content = content[:pos] + tempStr + content[pos + pos_end:]
with open("../aps/include/common_patch.h", "w") as project_op:
project_op.write(content) def fun_genAllSerBinbyId():
listSave = []
with open("../mconfig.config", "r") as mFile:
list = mFile.readlines() for board in g_listBoard:
fun_searchModeCode(board)
for ui in g_listUI:
os.system('cd ..; make clean')
for line in list:
if "#" in line:
continue
elif line.find("CONFIG_BOARD_") != -1 :
line = "CONFIG_BOARD_%s__RADISSON__RADISSON__RADISSON=y\n" %(board)
listSave.append(line)
elif line.find("CONFIG_MODEL_BOARD_NAME") != -1:
line = "CONFIG_MODEL_BOARD_NAME=\"%s\"\n" %(board)
listSave.append(line)
elif line.find("CONFIG_PROJECT_NAME") != -1 :
line = "CONFIG_PROJECT_NAME=\"%s___%s___ATV\"\n" %(board,ui)
listSave.append(line)
elif line.find("CONFIG_APP_FOLDER_NAME") != -1:
line = "CONFIG_APP_FOLDER_NAME=\"%s\"\n" %(ui)
listSave.append(line)
elif re.search("CONFIG_.*___ATV__RADISSON__RADISSON__RADISSON",line):
line = "CONFIG_%s_%s___ATV__RADISSON__RADISSON__RADISSON=y\n" %(board,ui.upper())
listSave.append(line)
else:
listSave.append(line)
with open("../mconfig.config", "w") as mFile:
mFile.writelines(listSave)
listSave = [] for (k,v) in mapModeCode.items():
fun_genCommonPatchFilebyId(k)
shutil.copy("../aps/customer/radisson/sub_customer/radisson/radisson/project/%s___%s___ATV.config" %(board,ui), "../menuconfig.config")
os.system('make -j') if ui == "videocon" and os.path.exists("../mergedir/VIDEOCON.code.bin"):
shutil.copy("../mergedir/VIDEOCON.code.bin","../kitking/%s_%s_%s.bin" %(board,ui.upper(),v))
elif ui == "philips" and os.path.exists("../mergedir/PHILIPS.code.bin"):
shutil.copy("../mergedir/PHILIPS.code.bin","../kitking/%s_%s_%s.bin" %(board,ui.upper(),v))
elif ui == "sansui" and os.path.exists("../mergedir/SANSUI.code.bin"):
shutil.copy("../mergedir/SANSUI.code.bin","../kitking/%s_%s_%s.bin" %(board,ui.upper(),v)) print board,ui
#var = raw_input("debug pause:") def main(): str_BinTable="bintable.txt"
str_BinData="bindata.txt"
str_CombinationBin="VIL_SER.BIN" str_temp=""
int_tablesize=0 #get bin path
fun_parse_InputParam() if os.path.exists(str_CombinationBin):
os.remove(str_CombinationBin) if os.path.exists(g_binDir):
shutil.rmtree(g_binDir) #gen all service bin file
if g_bAllBinbyId:
fun_genAllSerBinbyId()
return
elif g_bAllBin:
fun_genAllSerBin()
return
else:
print "\nThis mode don't compile all modeCode!"
print "python gen_codebin.py -i complie all modeCode\n" #get bin name
fun_getBinList(g_strBinPath)
g_listBin.sort() #decrypt bin file
if g_bDecrypt:
fun_decryptBinFile(g_listBin)
print "Decrypt finish"
return binTable_op = open(str_BinTable, "w+")
binData_op = open(str_BinData, "wb+") fun_GetBinTableandBin(g_listBin, binTable_op, binData_op)
#binTable_op.truncate(1024)
binTable_op.close()
binData_op.close() #gen header bin
binCombinFile = open(str_CombinationBin, "wb+")
int_tablesize=os.path.getsize(str_BinTable)
str_temp=str(int_tablesize)+","+str(len(g_listBin))+","
int_tablesize+=len(str_temp)
binCombinFile.write(str(g_headerLen) + ","+ str(len(g_listBin))+",") #gen combin bin
fun_genCombinationbin(binCombinFile, str_BinTable, str_BinData) binCombinFile.close()
#subprocess.call(["mv", str_CombinationBin, g_strBinPath])
os.remove(str_BinTable)
os.remove(str_BinData) if __name__ == '__main__':
main()

Python VIL Service Bin的更多相关文章

  1. #!/usr/bin/env python与#!/usr/bin/python的区别

    [摘自:http://blog.csdn.net/wh_19910525/article/details/8040494] 一般的python文件的开头都有#!/usr/bin/python.这是什么 ...

  2. Python 头部 #!/usr/bin/python 和 #!/usr/bin/env 的区别

    这个网址 https://www.cnblogs.com/scofi/p/4867851.html 讲述了Python 头部 #!/usr/bin/python 和 #!/usr/bin/env 的区 ...

  3. !/usr/bin/env python和!/usr/bin/python的区别

    脚本语言第一行 作用:文件中代码用指定可执行程序运行 #!/usr/bin/Python  执行脚本时,调用/usr/bin下python解释器 #!/usr/bin/env python  在环境设 ...

  4. 解决安装虚拟环境出现的问题(OSError: Command /home/python/.virtua...ngo3_web/bin/python3 - setuptools pkg_resources pip wheel failed with error code 2)

    python3的报错解决: OSError: Command /home/python/.virtua...ngo3_web/bin/python3 - setuptools pkg_resource ...

  5. python中#!/usr/bin/env python与#!/usr/bin/python

    通常在脚本语言的第一行会看到#!/usr/bin/env python 与 #!/usr/bin/python其中之一,这两句话的目的都是指出你的python文件用什么可执行程序去运行它. #!/us ...

  6. python中#!/usr/bin/python与#!/usr/bin/env python的区别

    目的是在运行python脚本的时候告诉操作系统我们要用python解释器去运行py脚本 所以我们在第一句往往会写如下两句中的其中一句: #!/usr/bin/python 或 >#!/usr/b ...

  7. #!/usr/bin/python和#!/usr/bin/env 的区别

    #!/usr/bin/python 通常在一个.py文件开头都会有这个语句 它只在Linux系统下生效,意思是当作为可执行文件运行时调用的解释器的位置上面代码的意思是调用/usr/bin/下的Pyth ...

  8. #!/usr/bin/python和#!/usr/bin/env 的区别(转)

    #!/usr/bin/python和#!/usr/bin/env 的区别   #!/usr/bin/python 通常在一个.py文件开头都会有这个语句 它只在Linux系统下生效,意思是当作为可执行 ...

  9. python头部 #!/usr/bin/env python

    *.py运行: python *.py OR ./*.py 对于*.py其首行应标明 #!/usr/bin/env python,定义python解释器调用路径,对比#!/usr/bin/python ...

随机推荐

  1. Xilinx Uboot网卡驱动分析

    1.MAC控制器.网卡.PHY.MDIO.mii.gmii.rgmii概念扫盲 网卡在功能上包含OSI模型的两个层,数据链路层和物理层.物理层定义了数据传送与接收所需要的电与光信号.线路状态.时钟基准 ...

  2. about SpringBoot学习后记

    <SpringBoot实战>第一章节入门的名称为Spring风云再起 看起来Spring的功能确实受Java开发者喜爱 在SpringBoot中,继续将Spring框架做了另一次的封装使框 ...

  3. SDOI2011_染色

    SDOI_染色 背景:很早就想学习树链剖分,趁着最近有点自由安排的时间去学习一下,发现有个很重要的前置知识--线段树.(其实不一定是线段树,但是线段树应该是最常见的),和同学吐槽说树剖的剖和分都很死板 ...

  4. 如何借助 OVN 来提高 OVS 在云计算环境中的性能

    众所周知,OpenvSwitch 以其丰富的功能和不错的性能,已经成为 Openstack 部署中最受欢迎的虚拟交换机.由于 Openstack Neutron 的架构引入了一些性能问题,比如 neu ...

  5. 【转】梯度下降算法以及其Python实现

    一.梯度下降算法理论知识 我们给出一组房子面积,卧室数目以及对应房价数据,如何从数据中找到房价y与面积x1和卧室数目x2的关系?   为了实现监督学习,我们选择采用自变量x1.x2的线性函数来评估因变 ...

  6. Android 之低版本高版本实现沉浸式状态栏

    沉浸式状态栏确切的说应该叫做透明状态栏.一般情况下,状态栏的底色都为黑色,而沉浸式状态栏则是把状态栏设置为透明或者半透明. 沉浸式状态栏是从android Kitkat(Android 4.4)开始出 ...

  7. 第106天:Ajax中同步请求和异步请求

    同步请求和异步请求的区别 1.同步是指:发送方发出数据后,等接收方发回响应以后才发下一个数据包的通讯方式. 用户填写所有信息后,提交给服务器,等待服务器的回应(检验数据),是一次性的.信息错误又要重新 ...

  8. Spring Boot 整合Swagger2构建API文档

    1.pom.xml中引入依赖 <dependency> <groupId>io.springfox</groupId> <artifactId>spri ...

  9. MySQL_explain关键字分析查询语句

    版权声明:本文为博主原创文章,转载请注明出处. 通过对查询语句的分析,可以了解查询语句的执行情况.MySQL中,可以使用EXPLAIN语句和DESCRIBE语句来分析查询语句. EXPLAIN语句的基 ...

  10. 微信支付 WeixinJSBridge is not defined 报错

    https://www.cnblogs.com/ottoman/p/7614419.html 我没有用到微信JS-SDK或者接口都正确返回预支付id都正确, 为什么会报这个错呢?答: 微信内置浏览器会 ...