分布式任务调整

This commit is contained in:
dongchangxi committed 2023-10-31 19:55:28 +08:00
1 parent fe9c6e6267
commit 57831c7167
11 files changed
+224 -96

No files matched your search

+31 -1
View File
@@ -1,5 +1,6 @@
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')
@@ -110,4 +111,33 @@ def change_rcbox_s(pid,new_value):
new_content = re.sub(old_value_pattern,f'<Residual s="{new_value}"',content)
#重新写入进去
with open(rcbox_path, 'w') as f:
f.write(new_content)
f.write(new_content)
#修改rcproj文件,删除没有模型的component,保留最多model 的component
def changeRcprojFile(pid):
# 解析XML文件
file_path = os.path.join(config.workdir, pid, f'{pid}.rcproj')
#判断文件是否存在
if not os.path.exists(file_path):
return False
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)
return True