ota包制作过程中,生成system/fileschecksum.txt 供新固件检测 ota升级失败内容。
authorSnickerSun <snickersun@163.com>
Sat, 7 Sep 2024 16:25:20 +0000 (00:25 +0800)
committerSnickerSun <snickersun@163.com>
Sat, 7 Sep 2024 16:25:20 +0000 (00:25 +0800)
tools/scripts/gen_fs_otapkg.sh
tools/scripts/search_folder_files.py [new file with mode: 0644]

index 87896d3..935e97a 100644 (file)
@@ -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 (file)
index 0000000..b269fc1
--- /dev/null
@@ -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
+
+    
+
+