diff --git a/core/check_release_management.py b/core/check_release_management.py new file mode 100644 index 0000000000000000000000000000000000000000..6b4eda51889dbd9561c4f6f50f3b148621ea1494 --- /dev/null +++ b/core/check_release_management.py @@ -0,0 +1,175 @@ +#!/bin/env python3 +# -*- encoding=utf8 -*- +#****************************************************************************** +# Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved. +# licensed under the Mulan PSL v2. +# You can use this software according to the terms and conditions of the Mulan PSL v2. +# You may obtain a copy of Mulan PSL v2 at: +# http://license.coscl.org.cn/MulanPSL2 +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR +# PURPOSE. +# See the Mulan PSL v2 for more details. +# Author: yaokai +# Create: 2021/8/04 +# ****************************************************************************** +""" +check the software package for the corresponding project of thecorresponding branch of source +""" +import os +import sys +import yaml +import requests +Now_path = os.path.join(os.path.split(os.path.realpath(__file__))[0]) +sys.path.append(os.path.join(Now_path, "..")) +from common.log_obs import log +from common.common import git_repo_src + +class CheckReleaseManagement(object): + """ + The entrance check for release-management + """ + def __init__(self, **kwargs): + """ + kawrgs: dict,init dict by 'a': 'A' style + prid: the pullrequest id + meta_path: The path for obs_meta + manage_path : The path for release_management_path + """ + self.kwargs = kwargs + self.prid = self.kwargs['pr_id'] + self.current_path = os.getcwd() + self.meta_path = self.kwargs['obs_meta_path'] + self.manage_path = self.kwargs['release_management_path'] + #self.giteeuser = self.kwargs['gitee_user'] + #self.giteeuserpwd = self.kwargs['gitee_pwd'] + + def _clean(self, pkgname): + """ + remove the useless pkg dir + """ + cmd = "if [ -d {0} ];then rm -rf {0} && echo 'Finish clean the {0}';fi".format(pkgname) + rm_result = os.popen(cmd).readlines() + log.info(rm_result) + + def _get_latest_git_repo(self, owner, pkgname): + """ + get the latest git repo + """ + os.chdir(self.current_path) + rpm_url = "https://gitee.com/{0}/{1}".format(owner, pkgname) + pkg_path = git_repo_src(rpm_url, self.giteeuser, self.giteeuserpwd) + if pkg_path: + log.info("{0}:{1}".format(pkgname, pkg_path)) + return pkg_path + else: + raise SystemExit("Error:{0} Clone-error,Please check yournet.".format(pkgname)) + + def _get_repo_change_file(self, owner=None, pkgname=None, repo_path=None): + """ + Obtain the change for latest commit + """ + changed_file_cmd = "git diff --name-status HEAD~1 HEAD~0" + get_fetch = None + if not repo_path: + self._get_latest_git_repo(owner, pkgname) + os.chdir(os.path.join(self.current_path, pkgname)) + fetch_cmd = "git fetch origin pull/%s/head:thispr" % self.prid + checkout_cmd = "git checkout thispr" + for x in range(5): + fetch_result = os.system(fetch_cmd) + checkout_result = os.system(checkout_cmd) + log.debug(fetch_result) + log.debug(checkout_result) + if fetch_result == 0 and checkout_result == 0: + get_fetch = True + break + else: + os.chdir(self.current_path) + self._clean(pkgname) + self._get_latest_git_repo(owner, pkgname) + else: + os.chdir(repo_path) + get_fetch = True + changed_file = os.popen(changed_file_cmd).readlines() + if get_fetch and changed_file: + log.info(changed_file) + return changed_file + else: + raise SystemExit("Error:can not obtain the content for this commit") + + def _parse_commit_file(self, change_file): + """ + get the change file for latest commit + """ + new_file_path = [] + for line in change_file: + log.info("line:%s" % line) + log_list = list(line.split()) + temp_log_type = log_list[0] + if len(log_list) == 3: + if "pckg-mgmt.yaml" in log_list[2]: + new_file_path.append(log_list[2]) + elif len(log_list) == 2: + if temp_log_type != "D" and "pckg-mgmt.yaml" in log_list[1]: + new_file_path.append(log_list[1]) + if new_file_path: + log.info(new_file_path) + return new_file_path + else: + log.info("There are no file need to check!!!") + sys.exit() + + def _get_yaml_msg(self, yaml_path_list): + """ + get the pkg msg in pckg-mgmt.yaml + """ + pack_msg = [] + yaml_msg = {} + for yaml_path in yaml_path_list: + pack_msg.clear() + file_path = os.path.join(self.manage_path, yaml_path) + with open(file_path, 'r', encoding='utf-8')as f: + result = yaml.load(f, Loader=yaml.FullLoader) + all_pack_msg = result['packages']['natural'] + for msg in all_pack_msg: + pack_msg.append(os.path.join(msg['branch_from'], msg['obs_from'], msg['name'])) + yaml_msg[yaml_path] = pack_msg + return yaml_msg + + def _check_pkg_from(self, yaml_path_list, meta_path, yaml_msg): + """ + Detects the existence of file contents + """ + for yaml_path in yaml_path_list: + log.debug(yaml_path + ":") + for pkg_path in yaml_msg[yaml_path]: + pkg_dir_path = os.path.join(meta_path, pkg_path) + if not os.path.exists(pkg_dir_path): + log.error("The {0} not exist in obs_meta".format(pkg_path)) + error_flag = True + if not error_flag: + log.debug("All rpms exist") + error_flag = False + return error_flag + + def check_pckg_yaml(self): + """ + check the obs_from branch_from in pckg-mgmt.yaml + """ + change = self._get_repo_change_file(repo_path = self.manage_path) + change_file = self._parse_commit_file(change) + yaml_msg = self._get_yaml_msg(change_file) + error_flag = self._check_pkg_from(change_file, self.meta_path, yaml_msg) + if error_flag: + raise SystemExit("Please check your commit") + +if __name__ == "__main__": + kw = {"branch":"master", + "gitee_user":"", + "gitee_pwd":"", + "pr_id":"108", + "obs_meta_path":"/root/relese-management/openeuler-obs/core/obs_meta", + "release_management_path":"/root/relese-management/openeuler-obs/core/release-management"} + check = CheckReleaseManagement(**kw) + check.check_pckg_yaml() diff --git a/core/getdate.py b/core/getdate.py index bb6e3b91faa9f4b103a2d68bcc8a88d6190f79a2..804fab294537ddada74d00e65d7808b16c857eea 100644 --- a/core/getdate.py +++ b/core/getdate.py @@ -94,7 +94,7 @@ class GETDate(object): get a fixed format date rpm: which package you want to get """ - cmd = "show -s --format=%ad" + cmd = "show -s --format=%ad --date=local" pkg_dir = os.path.join(self.realdir, rpm) show_result = self.cmd.ssh_cmd("git -C %s %s" % (pkg_dir, cmd)) log.info("%s : %s" % (rpm, show_result[1].decode("utf-8").replace('\r\n', ''))) diff --git a/core/runner.py b/core/runner.py index 3b8e958658d88119c302a21da634c5cb673684eb..7a853484f8286aa8d0a2a2ab5a7ae4f95e2384e1 100644 --- a/core/runner.py +++ b/core/runner.py @@ -29,6 +29,7 @@ from core.package_manager import OBSPkgManager from core.update_obs_repos import RPMManager from core.obs_mail_notice import ObsMailNotice from core.sync_pckg_mgmt import SyncPckgMgmt +from core.check_release_management import CheckReleaseManagement import os class Runner(object): @@ -128,6 +129,13 @@ class Runner(object): mgmt = SyncPckgMgmt(**self.kwargs) mgmt.sync_yaml_meta() + def _check_release_mgmt(self): + """ + check the realese_mgmt commit + """ + check_mgmt = CheckReleaseManagement(**self.kwargs) + check_mgmt.check_pckg_yaml() + def run(self): """ run main @@ -159,3 +167,5 @@ class Runner(object): self._mail_notice() elif self.kwargs["pckg_mgmt"] == "true": self._pckg_mgmt() + elif self.kwargs["check_pckg_mgmt"] == "true": + self._check_release_mgmt() diff --git a/openeuler_obs.py b/openeuler_obs.py index 8266ef90e4d60e55db95ffc22426de01895bac37..8dab4d9274caefcfa3deffb14a6771166e6f0c35 100644 --- a/openeuler_obs.py +++ b/openeuler_obs.py @@ -108,6 +108,8 @@ par.add_argument("-pm", "--pckg_mgmt", default=False, par.add_argument("-rm", "--remt", default=None, help="Local path of release-management repository.", required=False) par.add_argument("-a", "--ALL_", default=False, help="update all obs repo rpms", required=False) +par.add_argument("-cpm", "--check_pckg_mgmt", default=False, + help="check if there are any problems with the commi for release-management", required=False) args = par.parse_args() #apply @@ -150,7 +152,8 @@ kw = { "cc_addr": args.cc_addr, "obs_mail_notice": args.obs_mail_notice, "pckg_mgmt": args.pckg_mgmt, - "release_management_path": args.remt + "release_management_path": args.remt, + "check_pckg_mgmt": args.check_pckg_mgmt } run = Runner(**kw) diff --git a/releasenode.txt b/releasenode.txt index 70a36913f811457d73fb31ef82c41d21d3beece7..d91c1d453e3ff0d5e26e279154e102e8679ff9cc 100644 --- a/releasenode.txt +++ b/releasenode.txt @@ -1,3 +1,6 @@ +v1.3.4: + - change to correct time collection + - add check for rease_management v1.3.3: - add new tool for getting time from obs building to iso - support collect rpms for openEuler-20.03-LTS-Next in oepkg