35 Star 142 Fork 70

腾讯蓝鲸智云/bk-sops

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
preview.py 3.34 KB
一键复制 编辑 原始数据 按行查看 历史
# -*- coding: utf-8 -*-
"""
Tencent is pleased to support the open source community by making 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community
Edition) available.
Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://opensource.org/licenses/MIT
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
"""
import logging
from copy import deepcopy
from pipeline_web.preview_base import PipelineTemplateWebPreviewer
from gcloud.common_template.models import CommonTemplate
from gcloud.tasktmpl3.models import TaskTemplate
from gcloud.constants import PROJECT
logger = logging.getLogger("root")
def preview_template_tree(project_id, template_source, template_id, version, exclude_task_nodes_id):
if template_source == PROJECT:
template = TaskTemplate.objects.get(pk=template_id, is_deleted=False, project_id=project_id)
else:
template = CommonTemplate.objects.get(pk=template_id, is_deleted=False)
pipeline_tree = template.get_pipeline_tree_by_version(version)
template_constants = deepcopy(pipeline_tree["constants"])
PipelineTemplateWebPreviewer.preview_pipeline_tree_exclude_task_nodes(pipeline_tree, exclude_task_nodes_id)
constants_not_referred = {
key: value for key, value in list(template_constants.items()) if key not in pipeline_tree["constants"]
}
return {"pipeline_tree": pipeline_tree, "constants_not_referred": constants_not_referred}
def preview_template_tree_with_schemes(template, version, scheme_id_list):
version = version or template.version
pipeline_tree = template.get_pipeline_tree_by_version(version)
template_constants = deepcopy(pipeline_tree["constants"])
exclude_task_nodes_id = PipelineTemplateWebPreviewer.get_template_exclude_task_nodes_with_schemes(
pipeline_tree, scheme_id_list
)
PipelineTemplateWebPreviewer.preview_pipeline_tree_exclude_task_nodes(pipeline_tree, exclude_task_nodes_id)
constants_not_referred = {}
custom_constants = {}
for key, value in template_constants.items():
if value["show_type"] == "show" and key not in pipeline_tree["constants"]:
if value["source_type"] == "custom":
custom_constants[key] = value
constants_not_referred[key] = value
# 添加outputs返回
template_outputs = template.get_outputs(version)
outputs = {}
for key, value in template_outputs.items():
# 如果输出变量来源于节点勾选,且来源的节点是执行方案删除节点的子集,则不展示该输出变量
if value["source_type"] in ["component_outputs", "component_inputs"] and set(
value["source_info"].keys()
).issubset(set(exclude_task_nodes_id)):
continue
outputs[key] = value
return {
"pipeline_tree": pipeline_tree,
"custom_constants": custom_constants,
"constants_not_referred": constants_not_referred,
"outputs": outputs,
"version": version,
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/Tencent-BlueKing/bk-sops.git
git@gitee.com:Tencent-BlueKing/bk-sops.git
Tencent-BlueKing
bk-sops
bk-sops
master

搜索帮助