import redis,sys,os,re import platform import xml.etree.ElementTree as ET if platform.system() == 'Windows': #sys.path.append('e:\\libs\\') sys.path.append('libs') else: sys.path.append('/data/deploy/make3d/make2/libs/') import config,libs #判断模型是需要高精模 或者是 需要photo3 参与 def task_need_high_model_or_photo3(pid): resHigh = task_need_high_model(pid) resPhoto3 = task_need_photo3(pid) if resHigh or resPhoto3: return True else: return False #判断是否需要高精模 def task_need_high_model(pid): redis_conn = config.redis_local_common #判断在redis中是否有高精模和 需要photo3 参与的 task if redis_conn.sismember("calculateHighModel",pid): return True #判断是否需要高精模 if redis_conn.sismember("calculateHighModel_no",pid): return False #判断是否需要高精模 if libs.get_ps_type(pid) == 1: if libs.aliyun_face(pid): #calulate_type = 'calculateHighModel' redis_conn.sadd("calculateHighModel",pid) return True else: redis_conn.sadd("calculateHighModel_no",pid) return False #判断是否需要photo3参与建模 def task_need_photo3(pid): redis_conn = config.redis_local_common #判断在redis中是否有高精模和 需要photo3 参与的 task if redis_conn.sismember("photo3",pid): return True #判断是否需要photo3参与建模 if redis_conn.sismember("photo3_no",pid): return False if os.path.exists(os.path.join(config.workdir, pid, 'photo3')): redis_conn.sadd("photo3",pid) return True else: redis_conn.sadd("photo3_no",pid) return False #拷贝远程主机上的指定目录到本地指定目录 def copy_remote_directory(remote_host, remote_path, local_path): # 建立 SSH 连接 ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(remote_host, username='your_username', password='your_password') # 创建 SFTP 客户端 sftp = ssh.open_sftp() # 获取远程目录下的所有文件/子目录 file_list = sftp.listdir(remote_path) # 遍历远程目录中的每个文件/子目录 for file_name in file_list: remote_file_path = os.path.join(remote_path, file_name) local_file_path = os.path.join(local_path, file_name) # 判断当前项是文件还是目录 if sftp.stat(remote_file_path).st_isdir(): # 如果是目录,递归调用函数进行拷贝 os.makedirs(local_file_path, exist_ok=True) copy_remote_directory(remote_host, remote_file_path, local_file_path) else: # 如果是文件,直接拷贝到指定目录 sftp.get(remote_file_path, local_file_path) # 关闭 SFTP 客户端和 SSH 连接 sftp.close() ssh.close() #移除redis中的高精模和 需要photo3 参与的 task # def remove_redis_high_model_or_photo3(pid): # redis_conn = config.redis_local_common # redis_conn.srem("calculateHighModel",pid) # redis_conn.srem("photo3",pid) # if __name__ == '__main__': # redis_conn = config.redis_local_common # print(redis_conn.sismember("photo3_no","1")) #读取rcbox文件进行修改指定的值 def change_rcbox_s(pid,new_value): rcbox_path = os.path.join(config.workdir, pid, f"{pid}.rcbox") old_value_pattern = r' 1: components_with_model.sort(key=lambda x: len(x.findall('model')), reverse=False) for i in range(len(components_with_model)-1): reconstruction.remove(components_with_model[i]) # 保存修改后的XML文件 tree.write(file_path) return True