任务管理
| 37 | |
| 38 | |
| 39 | class JobManager(object): |
| 40 | """任务管理 |
| 41 | """ |
| 42 | |
| 43 | def __init__(self, project=None): |
| 44 | """初始化函数 |
| 45 | """ |
| 46 | self._project = project |
| 47 | self._log_prefix = "[Project: %d]" % project.id if project else "" |
| 48 | self._analysis_client = AnalyseClient() |
| 49 | |
| 50 | def _format_scm_time(self, scm_time): |
| 51 | """格式化scm时间 |
| 52 | """ |
| 53 | # 时间戳格式转换为日期字符串格式 |
| 54 | if type(scm_time) == int or type(scm_time) == float: |
| 55 | scm_time = str(datetime.fromtimestamp(scm_time)) |
| 56 | return scm_time |
| 57 | |
| 58 | def _filter_languages(self, languages): |
| 59 | """筛选语言 |
| 60 | """ |
| 61 | if not languages: |
| 62 | return [] |
| 63 | languages = languages.split(',') |
| 64 | return Language.objects.filter(name__in=languages) |
| 65 | |
| 66 | def _filter_labels(self, labels): |
| 67 | """筛选标签 |
| 68 | """ |
| 69 | if not labels: |
| 70 | return [] |
| 71 | labels = labels.split(',') |
| 72 | return Label.objects.filter(name__in=labels) |
| 73 | |
| 74 | def insert_auth_into_job_context(self, job_context): |
| 75 | """将项目的鉴权信息插入任务参数 |
| 76 | """ |
| 77 | scm_username = self._project.auth_info.get("scm_username") |
| 78 | logger.info("Auth type: %s[%s]" % (self._project.auth_info.get("auth_type"), scm_username)) |
| 79 | scm_password = self._project.auth_info.get("scm_password") |
| 80 | job_context.update({ |
| 81 | "scm_auth_info": self._project.auth_info, |
| 82 | "scm_username": scm_username, |
| 83 | "scm_password": scm_password |
| 84 | }) |
| 85 | |
| 86 | def get_checktool_scheme_libs_info(self, tool_scheme): |
| 87 | """获取工具依赖方案依赖信息 |
| 88 | """ |
| 89 | tool_libs = [] |
| 90 | # 已默认按pos排序过 |
| 91 | toollib_maps = tool_scheme.toollibmap.select_related("toollib").all() |
| 92 | for toollib_map in toollib_maps: |
| 93 | toollib = toollib_map.toollib |
| 94 | tool_libs.append({ |
| 95 | "key": str(toollib), |
| 96 | "name": toollib.name, |
no outgoing calls
no test coverage detected