import os, sys, time, shutil, subprocess, shlex, json import xml.etree.ElementTree as ET import platform 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, libs_db,common if __name__ == '__main__': #遍历oss 指定文件夹下指定日期的文件 for obj in config.bucket.list_objects(prefix="auto/"): #判断是否是文件夹 并且 日期是否在 2023-11-08 之后的 if obj.key[-1] == "/" and obj.key.split("/")[1] >= "2023-11-08": #判断是否存在这个目录 if not os.path.exists(os.path.join(config.workdir,obj.key.split("/")[1])): os.mkdir(os.path.join(config.workdir,obj.key.split("/")[1])) #拷贝文件到本地 for obj2 in config.bucket.list_objects(prefix=obj.key): if obj2.key[-1] != "/": print(obj2.key) #判断文件是否存在 if not os.path.exists(os.path.join(config.workdir,obj2.key)): #下载文件 config.bucket.get_object_to_file(obj2.key,os.path.join(config.workdir,obj2.key)) #判断文件是否下载成功 if os.path.exists(os.path.join(config.workdir,obj2.key)): print("下载成功") else: print("下载失败") else: print("文件已存在") # 解析XML文件 # pid = "112322" # file_path = os.path.join(config.workdir, pid, f'{pid}.rcproj') # tree = ET.parse(file_path) # root = tree.getroot() # # 遍历所有的reconstructions节点 # for reconstruction in root.findall('reconstructions'): # for component in reconstruction.findall('component'): # if component.find('model') == None: # reconstruction.remove(component) # continue # # 获取所有包含model标签的component节点 # components_with_model = [component for component in reconstruction.findall('component') if component.find('model') is not None] # print(components_with_model) # # 如果包含model标签的component节点数量大于1,则按照model数量降序排序 # if len(components_with_model) > 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)