From: SnickerSun Date: Sat, 7 Sep 2024 16:25:20 +0000 (+0800) Subject: ota包制作过程中,生成system/fileschecksum.txt 供新固件检测 ota升级失败内容。 X-Git-Tag: release_V1.2.70_20241020_135402~524^2~2 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=ad28a15d41f7c8369105f93c535a3563c061d14c;p=mirrors%2FFD230.git ota包制作过程中,生成system/fileschecksum.txt 供新固件检测 ota升级失败内容。 --- diff --git a/tools/scripts/gen_fs_otapkg.sh b/tools/scripts/gen_fs_otapkg.sh index 87896d3b3..935e97a90 100644 --- a/tools/scripts/gen_fs_otapkg.sh +++ b/tools/scripts/gen_fs_otapkg.sh @@ -15,6 +15,7 @@ OLDVERSION=`dirname $0`/../../code/sdk/output/brandy/TestOTA/oldsoftware UNYAFFS_SCRIPT=$HOMEDIR/tools/scripts/unyaffs2tool.py COMPARE_FOLDER_SCRIPT=$HOMEDIR/tools/scripts/compare_folder.py +SEARCH_FOLDER_SCRIPT=$HOMEDIR/tools/scripts/search_folder_files.py echo $0 @@ -39,12 +40,19 @@ if [ $? != 0 ] then exit 2 fi -python $COMPARE_FOLDER_SCRIPT $BACKUPDIR_HOME/new $BACKUPDIR_HOME/old $BACKUPDIR_HOME +python $SEARCH_FOLDER_SCRIPT $BACKUPDIR_HOME/new $BACKUPDIR_HOME/new if [ $? != 0 ] then exit 3 fi +python $COMPARE_FOLDER_SCRIPT $BACKUPDIR_HOME/new $BACKUPDIR_HOME/old $BACKUPDIR_HOME +if [ $? != 0 ] +then +exit 4 +fi + + echo done diff --git a/tools/scripts/search_folder_files.py b/tools/scripts/search_folder_files.py new file mode 100644 index 000000000..b269fc14f --- /dev/null +++ b/tools/scripts/search_folder_files.py @@ -0,0 +1,88 @@ +# -*-coding:utf-8-*- + +#=============================================================================== +# 目录对比工具(包含子目录 ),并列出 +# 1、A比B多了哪些文件 +# 2、B比A多了哪些文件 +# 3、二者相同的文件: md5比较 +#=============================================================================== + +import os +import sys +import time +import difflib +import hashlib +import struct +import shutil + + +def getFileMd5(filename): + if not os.path.isfile(filename): + print('file not exist: ' + filename) + return + myhash = hashlib.md5() + f = open(filename,'rb') + while True: + b = f.read(8096) + if not b : + break + myhash.update(b) + f.close() + return myhash.hexdigest() + + +def getAllFiles(path): + flist=[] + for root, dirs , fs in os.walk(path): + for f in fs: + f_fullpath = os.path.join(root, f) + f_relativepath = f_fullpath[len(path):] + flist.append(f_relativepath) + return flist + + +def create_dirs(dir_path): + # print(dir_path) + if not os.path.exists(dir_path): + try: + os.makedirs(dir_path) + except OSError as exc: # Guard against race condition + if exc.errno != errno.EEXIST: + raise +# 获取文件大小 +def get_FileSize(filePath): + fsize = os.path.getsize(filePath) + # fsize = fsize / float(1024 * 1024) # 单位换算 从 B --> MB + # return round(fsize, 2) # 保留两位小数 + return fsize + +def write_string_to_file(filename, content): + file.write(content) + +aPath="" +target_tmp_dir="" +filelist=[] +target_filelist_name="" + +if __name__ == '__main__': + aPath = sys.argv[1] + target_tmp_dir = sys.argv[2] + print("{},{}".format(aPath,target_tmp_dir)) + target_filelist_name=target_tmp_dir+"/system/fileschecksum.txt" + if os.path.exists(target_filelist_name): + os.remove(target_filelist_name) + filelist=getAllFiles(aPath) + create_dirs(target_tmp_dir+"/system/") + with open(target_filelist_name, 'w') as file: + for f in filelist: + fullpath=aPath+"/"+f + print(fullpath) + fmd5=getFileMd5(fullpath) + fsize=get_FileSize(fullpath) + content = "{},{},{}\n".format(f,fsize,fmd5) + file.write(content) + file.close + + + +