diff --git a/tools/downxmps.py b/tools/downxmps.py index 5686ec4..ef4c256 100644 --- a/tools/downxmps.py +++ b/tools/downxmps.py @@ -7,27 +7,37 @@ else: import config, libs, libs_db -def down_xmps_from_oss(psid): +def down_xmps_from_oss(psid,pid = ""): def need_down(): filename = f'xmps/{psid}/{psid}.rcbox' if not config.oss_bucket.object_exists(filename): print(f'未找到{filename}, 请检查是否已经上传{psid}号影棚坐标文件') time.sleep(5) return False + #获取到oss上文件rcbox的最后修改时间 oss_file_last_modified = float(config.oss_bucket.get_object_meta(filename).last_modified) + #本地文件的路径 local_file = os.path.join(config_path, 'xmps', psid, f'{psid}.rcbox') + #判断本地文件是否存在 rcbox文件 if not os.path.exists(local_file): + #不存在本地文件,从云端进行下载 print(f'未找到{local_file}, 需要下载影棚坐标文件') os.makedirs(os.path.join(config_path, 'xmps', psid), exist_ok=True) config.oss_bucket.get_object_to_file(filename, local_file) return True + #文件已在本地存在,则判断本地时间先后问题 local_file_last_modified = os.path.getmtime(local_file) if oss_file_last_modified > local_file_last_modified: print(f'本地{local_file}文件已过期, 需要下载影棚坐标文件') config.oss_bucket.get_object_to_file(filename, local_file) return True - - if not need_down(): return + + #在有pid 的情况下判断是否要从云端下载影棚坐标文件 + if pid != "": + if local_and_remote_file_time(psid,pid) == "local_file_best_new": + return + else: + if not need_down(): return print('正在下载影棚坐标文件') dest_path = os.path.join(config_path, 'xmps', psid) @@ -56,6 +66,31 @@ def down_xmps_from_oss(psid): print('下载完成') + +#判断远程文件和本地文件的时间问题 +def local_and_remote_file_time(psid,pid): + #远程文件的路径 + config_path = os.path.join(config.sharedir, 'libs') + xmps_mesh_path = os.path.join(config_path, 'xmps', psid, 'mesh') + remotefile = os.path.join(xmps_mesh_path, '11_1.xmp') + #本地文件的路劲 + input_path = os.path.join(config.workdir, pid) + ImagesGeometry = os.path.join(input_path, "photo1") + localfile = os.path.join(ImagesGeometry, '11_1.xmp') + print(f'比对本地文件和远程文件的时间先后--remotefile: {remotefile}, localfile: {localfile}') + if os.path.exists(localfile): + remotefile_last_modified = os.path.getmtime(remotefile) + localfile_last_modified = os.path.getmtime(localfile) + if remotefile_last_modified <= localfile_last_modified: + print(f'本地{localfile}文件已是最新,') + return "local_file_best_new" + + else: + print(f'本地{remotefile}文件最新') + return "remote_file_best_new" + print(f'本地{localfile}文件不存在') + return "local_file_not_exist" + if __name__ == '__main__': start = datetime.datetime.now() if len(sys.argv) == 2: @@ -74,21 +109,24 @@ if __name__ == '__main__': xmps_mesh_path = os.path.join(config_path, 'xmps', psid, 'mesh') xmps_texture_path = os.path.join(config_path, 'xmps', psid, 'texture') - down_xmps_from_oss(psid) + # 从oss下载影棚坐标文件 + down_xmps_from_oss(psid,pid) # 根据坐标文件时间戳判断是否需要更新 - remotefile = os.path.join(xmps_mesh_path, '11_1.xmp') - localfile = os.path.join(ImagesGeometry, '11_1.xmp') - print(f'remotefile: {remotefile}, localfile: {localfile}') - if os.path.exists(localfile): - remotefile_last_modified = os.path.getmtime(remotefile) - localfile_last_modified = os.path.getmtime(localfile) - if remotefile_last_modified <= localfile_last_modified: - print(f'本地{localfile}文件已是最新, 不需要更新') - continue + if local_and_remote_file_time(psid,pid) == "local_file_best_new": + print(f'本地文件已是最新, 不需要更新') + continue + # remotefile = os.path.join(xmps_mesh_path, '11_1.xmp') + # localfile = os.path.join(ImagesGeometry, '11_1.xmp') + # print(f'remotefile: {remotefile}, localfile: {localfile}') + # if os.path.exists(localfile): + # remotefile_last_modified = os.path.getmtime(remotefile) + # localfile_last_modified = os.path.getmtime(localfile) + # if remotefile_last_modified <= localfile_last_modified: + # print(f'本地{localfile}文件已是最新, 不需要更新') + # continue print(f'正在更新{pid}号影棚坐标文件') os.system('xcopy /y /q ' + xmps_mesh_path + '*.* ' + ImagesGeometry) os.system('xcopy /y /q ' + xmps_texture_path + '*.* ' + ImagesTexture) - \ No newline at end of file