import os, sys, datetime, subprocess, shlex, shutil, requests, time, json, oss2 import platform if platform.system() == 'Windows': sys.path.append('e:\\libs\\') else: sys.path.append('/data/deploy/make3d/make2/libs/') import config, libs, libs_db def down_xmps_from_oss(psid): 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_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') 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 print('正在下载影棚坐标文件') dest_path = os.path.join(config_path, 'xmps', psid) if os.path.exists(os.path.join(dest_path)): shutil.rmtree(os.path.join(dest_path), ignore_errors=True) os.makedirs(os.path.join(dest_path, 'mesh'), exist_ok=True) os.makedirs(os.path.join(dest_path, 'texture'), exist_ok=True) prefix = f'xmps/{psid}/mesh/' filelist = oss2.ObjectIteratorV2(config.oss_bucket, prefix=prefix) for file in filelist: if file.key.endswith('.xmp'): filename = file.key.split('/')[-1] print('正在下载:', file.key) config.oss_bucket.get_object_to_file(file.key, os.path.join(dest_path, 'mesh', filename)) prefix = f'xmps/{psid}/texture/' filelist = oss2.ObjectIteratorV2(config.oss_bucket, prefix=prefix) for file in filelist: if file.key.endswith('.xmp'): filename = file.key.split('/')[-1] print('正在下载:', file.key) config.oss_bucket.get_object_to_file(file.key, os.path.join(dest_path, 'texture', filename)) print('下载完成') if __name__ == '__main__': start = datetime.datetime.now() if len(sys.argv) == 2: pids = sys.argv[1] else: print('usage: python downxmps.py [pids]') exit(1) for pid in pids.split(','): input_path = os.path.join(config.workdir, pid) ImagesGeometry = os.path.join(input_path, "photo1") ImagesTexture = os.path.join(input_path, "photo2") psid = libs.getPSid(pid) config_path = os.path.join(config.sharedir, 'libs') 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) # 根据坐标文件时间戳判断是否需要更新 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)