83 lines
3.3 KiB
Python
83 lines
3.3 KiB
Python
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 diff_time(start_time, end_time):
|
|
d = end_time - start_time
|
|
m = d.microseconds
|
|
return str(d.seconds // 60) + ":" + str(d.seconds % 60) + ":" + str(m)[:-3]
|
|
|
|
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)
|
|
|
|
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('d:\\', pid)
|
|
ImagesGeometry = os.path.join(input_path, "photo1")
|
|
ImagesTexture = os.path.join(input_path, "photo2")
|
|
|
|
psid = libs.getPSid(pid)
|
|
config_path = f'D:\\apps\\config\\'
|
|
xmps_mesh_path = config_path + f'xmps\\{psid}\\mesh\\'
|
|
xmps_texture_path = config_path + f'xmps\\{psid}\\texture\\'
|
|
|
|
down_xmps_from_oss(psid)
|
|
|
|
os.system('xcopy /Y ' + xmps_mesh_path + '*.* ' + ImagesGeometry)
|
|
os.system('xcopy /Y ' + xmps_texture_path + '*.* ' + ImagesTexture)
|
|
|
|
|