下载坐标前的判断是否已经存在最新的坐标
This commit is contained in:
1 parent
b662fda437
commit
f93578258a
1 file changed
+51
-13
+51
-13
@@ -7,27 +7,37 @@ else:
|
|||||||
|
|
||||||
import config, libs, libs_db
|
import config, libs, libs_db
|
||||||
|
|
||||||
def down_xmps_from_oss(psid):
|
def down_xmps_from_oss(psid,pid = ""):
|
||||||
def need_down():
|
def need_down():
|
||||||
filename = f'xmps/{psid}/{psid}.rcbox'
|
filename = f'xmps/{psid}/{psid}.rcbox'
|
||||||
if not config.oss_bucket.object_exists(filename):
|
if not config.oss_bucket.object_exists(filename):
|
||||||
print(f'未找到{filename}, 请检查是否已经上传{psid}号影棚坐标文件')
|
print(f'未找到{filename}, 请检查是否已经上传{psid}号影棚坐标文件')
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
return False
|
return False
|
||||||
|
#获取到oss上文件rcbox的最后修改时间
|
||||||
oss_file_last_modified = float(config.oss_bucket.get_object_meta(filename).last_modified)
|
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')
|
local_file = os.path.join(config_path, 'xmps', psid, f'{psid}.rcbox')
|
||||||
|
#判断本地文件是否存在 rcbox文件
|
||||||
if not os.path.exists(local_file):
|
if not os.path.exists(local_file):
|
||||||
|
#不存在本地文件,从云端进行下载
|
||||||
print(f'未找到{local_file}, 需要下载影棚坐标文件')
|
print(f'未找到{local_file}, 需要下载影棚坐标文件')
|
||||||
os.makedirs(os.path.join(config_path, 'xmps', psid), exist_ok=True)
|
os.makedirs(os.path.join(config_path, 'xmps', psid), exist_ok=True)
|
||||||
config.oss_bucket.get_object_to_file(filename, local_file)
|
config.oss_bucket.get_object_to_file(filename, local_file)
|
||||||
return True
|
return True
|
||||||
|
#文件已在本地存在,则判断本地时间先后问题
|
||||||
local_file_last_modified = os.path.getmtime(local_file)
|
local_file_last_modified = os.path.getmtime(local_file)
|
||||||
if oss_file_last_modified > local_file_last_modified:
|
if oss_file_last_modified > local_file_last_modified:
|
||||||
print(f'本地{local_file}文件已过期, 需要下载影棚坐标文件')
|
print(f'本地{local_file}文件已过期, 需要下载影棚坐标文件')
|
||||||
config.oss_bucket.get_object_to_file(filename, local_file)
|
config.oss_bucket.get_object_to_file(filename, local_file)
|
||||||
return True
|
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('正在下载影棚坐标文件')
|
print('正在下载影棚坐标文件')
|
||||||
dest_path = os.path.join(config_path, 'xmps', psid)
|
dest_path = os.path.join(config_path, 'xmps', psid)
|
||||||
@@ -56,6 +66,31 @@ def down_xmps_from_oss(psid):
|
|||||||
|
|
||||||
print('下载完成')
|
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__':
|
if __name__ == '__main__':
|
||||||
start = datetime.datetime.now()
|
start = datetime.datetime.now()
|
||||||
if len(sys.argv) == 2:
|
if len(sys.argv) == 2:
|
||||||
@@ -74,21 +109,24 @@ if __name__ == '__main__':
|
|||||||
xmps_mesh_path = os.path.join(config_path, 'xmps', psid, 'mesh')
|
xmps_mesh_path = os.path.join(config_path, 'xmps', psid, 'mesh')
|
||||||
xmps_texture_path = os.path.join(config_path, 'xmps', psid, 'texture')
|
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')
|
if local_and_remote_file_time(psid,pid) == "local_file_best_new":
|
||||||
localfile = os.path.join(ImagesGeometry, '11_1.xmp')
|
print(f'本地文件已是最新, 不需要更新')
|
||||||
print(f'remotefile: {remotefile}, localfile: {localfile}')
|
continue
|
||||||
if os.path.exists(localfile):
|
# remotefile = os.path.join(xmps_mesh_path, '11_1.xmp')
|
||||||
remotefile_last_modified = os.path.getmtime(remotefile)
|
# localfile = os.path.join(ImagesGeometry, '11_1.xmp')
|
||||||
localfile_last_modified = os.path.getmtime(localfile)
|
# print(f'remotefile: {remotefile}, localfile: {localfile}')
|
||||||
if remotefile_last_modified <= localfile_last_modified:
|
# if os.path.exists(localfile):
|
||||||
print(f'本地{localfile}文件已是最新, 不需要更新')
|
# remotefile_last_modified = os.path.getmtime(remotefile)
|
||||||
continue
|
# localfile_last_modified = os.path.getmtime(localfile)
|
||||||
|
# if remotefile_last_modified <= localfile_last_modified:
|
||||||
|
# print(f'本地{localfile}文件已是最新, 不需要更新')
|
||||||
|
# continue
|
||||||
|
|
||||||
print(f'正在更新{pid}号影棚坐标文件')
|
print(f'正在更新{pid}号影棚坐标文件')
|
||||||
os.system('xcopy /y /q ' + xmps_mesh_path + '*.* ' + ImagesGeometry)
|
os.system('xcopy /y /q ' + xmps_mesh_path + '*.* ' + ImagesGeometry)
|
||||||
os.system('xcopy /y /q ' + xmps_texture_path + '*.* ' + ImagesTexture)
|
os.system('xcopy /y /q ' + xmps_texture_path + '*.* ' + ImagesTexture)
|
||||||
|
|
||||||
|
|
||||||
Reference in new issue
Block a user