diff --git a/iot_upload.py b/iot_upload.py index 1cfc3ca..da6e600 100644 --- a/iot_upload.py +++ b/iot_upload.py @@ -171,20 +171,27 @@ def get_the_last_windowsAppZIP(name): def build_for_windowsApp(): print ("开始打包exe流程") + os.chdir('/drone/src/') os.system('makensis Sources/nbn.nsi') os.system('du -sh Sources/Setup.exe') - -def calculate_md5(file_path): - md5 = hashlib.md5() - with open(file_path, 'rb') as f: - while True: - data = f.read(4096) - if not data: - break - md5.update(data) - print( file_path + 'MD5值为' + md5.hexdigest()) - return md5.hexdigest() +def count_files_in_directory(directory): + count = 0 + for root, dirs, files in os.walk(directory): + # 仅计算文件数量,不包括目录 + count += len(files) + return count + +# def calculate_md5(file_path): +# md5 = hashlib.md5() +# with open(file_path, 'rb') as f: +# while True: +# data = f.read(4096) +# if not data: +# break +# md5.update(data) +# print( file_path + 'MD5值为' + md5.hexdigest()) +# return md5.hexdigest() def build_the_current_windowsApp(name): the_current_windowsAppZIP="/drone/src/IOTContainer/" + os.getenv('DRONE_REPO_NAME') + '.' + os.getenv('version') + '.zip' @@ -192,11 +199,10 @@ def build_the_current_windowsApp(name): os.system('mkdir -p /tmp/a/ /tmp/b/ /tmp/IOTContainer/') os.system('unzip -q ' + the_last_windowsAppZIP + ' -d /tmp/a/') - os.system('cd /tmp/a/ && tar -zcf diff.tgz ./') os.system('unzip -q ' + the_current_windowsAppZIP + ' -d /tmp/b/') - os.system('cd /tmp/b/ && tar -zcf diff.tgz ./') - the_current_windowsAppTar='/tmp/a/diff.tgz' - the_last_windowsAppTar='/tmp/b/diff.tgz' + os.system('/bin/sh -c /drone/src/zip_diff.sh') + + file_count = count_files_in_directory('/tmp/IOTContainer/') if the_last_windowsAppZIP == None: print("初次上传,不比对zip,直接打包上传") @@ -206,11 +212,11 @@ def build_the_current_windowsApp(name): else: print ("比对新老版本zip文件") - if calculate_md5(the_current_windowsAppTar) == calculate_md5(the_last_windowsAppTar): + if file_count == 1: print ("\033[34m比对结果: 程序版本无更新,流程终止\033[0m") else: print ("比对结果:程序版本已更新") - os.system('/bin/sh -c /drone/src/zip_diff.sh') + os.system('cd /tmp/IOTContainer/ && zip -rq ' + os.getenv('DRONE_REPO_NAME') + '.' + os.getenv('version') + '.zip') diff_zip='/tmp/IOTContainer/' + os.getenv('DRONE_REPO_NAME') + '.' + os.getenv('version') + '.zip' platformAppAdd(diff_zip, '.zip') build_for_windowsApp() diff --git a/zip_diff.sh b/zip_diff.sh index d014414..a9b64f6 100644 --- a/zip_diff.sh +++ b/zip_diff.sh @@ -1,4 +1,5 @@ rm -rf /tmp/a/diff.tgz /tmp/b/diff.tgz +cat /drone/src/.tags > /tmp/IOTContainer/version for i in $(diff -rq /tmp/a/ /tmp/b/ | grep Only | awk '{print $NF}') do mv /tmp/b/$i /tmp/IOTContainer/ @@ -9,7 +10,5 @@ cd /tmp/IOTContainer/ ls -la -zip_name=$DRONE_REPO_NAME.$(cat /drone/src/.tags).zip -zip -q -r $zip_name ./ - -cd /drone/src/ \ No newline at end of file +# zip_name=$DRONE_REPO_NAME.$(cat /drone/src/.tags).zip +# zip -q -r $zip_name ./ \ No newline at end of file