diff --git a/src/ac/acl/package_license/__init__.py b/src/ac/acl/package_license/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..36e95ff3db7d173ff656de1605ce299b4e77f17a --- /dev/null +++ b/src/ac/acl/package_license/__init__.py @@ -0,0 +1,17 @@ +# -*- encoding=utf-8 -*- +""" +# ********************************************************************************** +# Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved. +# [openeuler-jenkins] is licensed under the Mulan PSL v1. +# You can use this software according to the terms and conditions of the Mulan PSL v1. +# You may obtain a copy of Mulan PSL v1 at: +# http://license.coscl.org.cn/MulanPSL +# 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 v1 for more details. +# Author: +# Create: 2020-10-16 +# Description: check spec file +# ********************************************************************************** +""" \ No newline at end of file diff --git a/src/ac/acl/package_license/check_license.py b/src/ac/acl/package_license/check_license.py new file mode 100644 index 0000000000000000000000000000000000000000..b73cdc0d7380de4897cbb22df3b6728465bb569a --- /dev/null +++ b/src/ac/acl/package_license/check_license.py @@ -0,0 +1,116 @@ +# -*- encoding=utf-8 -*- +""" +# ********************************************************************************** +# Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved. +# [openeuler-jenkins] is licensed under the Mulan PSL v1. +# You can use this software according to the terms and conditions of the Mulan PSL v1. +# You may obtain a copy of Mulan PSL v1 at: +# http://license.coscl.org.cn/MulanPSL +# 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 v1 for more details. +# Author: +# Create: 2020-10-16 +# Description: check spec file +# ********************************************************************************** +""" + +import logging +import time +import os +import yaml +import shutil + +from src.proxy.git_proxy import GitProxy +from src.ac.framework.ac_result import FAILED, WARNING, SUCCESS +from src.ac.framework.ac_base import BaseCheck +from src.ac.common.rpm_spec_adapter import RPMSpecAdapter +from src.ac.common.gitee_repo import GiteeRepo +from src.ac.acl.package_license.package_license import PkgLicense + +logger = logging.getLogger("ac") + +class CheckLicense(BaseCheck): + """ + check license in spec and src-code + """ + + def __init__(self, workspace, repo, conf=None): + super(CheckLicense, self).__init__(workspace, repo, conf) + + self._gp = GitProxy(self._work_dir) + self._work_tar_dir = os.path.join(workspace, "code") + self._gr = GiteeRepo(self._repo, self._work_dir, self._work_tar_dir) + if self._gr.spec_file: + self._spec = RPMSpecAdapter(os.path.join(self._work_dir, self._gr.spec_file)) + else: + self._spec = None + + self._pkg_license = PkgLicense() + self._license_in_spec = set() + self._license_in_src = set() + + def check_license_in_spec(self): + """ + check whether the license in spec file is in white list + :return + """ + if self._spec is None: + logger.warning("spec file not find") + return WARNING + self._license_in_spec = self._gr.scan_license_in_spec(self._spec) + self._license_in_spec = self._pkg_license.translate_license(self._license_in_spec) + if self._pkg_license.check_license_safe(self._license_in_spec): + return SUCCESS + else: + logger.warning("licenses in spec are not in white list") + return WARNING + + def check_license_in_src(self): + """ + check whether the license in src file is in white list + :return + """ + self._license_in_src = self._pkg_license.scan_licenses_in_license(self._work_tar_dir) + self._license_in_src = self._pkg_license.translate_license(self._license_in_src) + if not self._license_in_src: + logger.warning("can't find license in src code") + return WARNING + if self._pkg_license.check_license_safe(self._license_in_src): + return SUCCESS + else: + logger.warning("licenses in src code are not in white list") + return WARNING + + def check_license_is_same(self): + """ + check whether the license in spec file and in src file is same + :return + """ + if self._pkg_license.check_licenses_is_same(self._license_in_spec, self._license_in_src): + logger.info("licenses in src:{} and in spec:{} are same".format(self._license_in_src, + self._license_in_spec)) + return SUCCESS + else: + logger.warning("licenses in src:{} and in spec:{} are not same".format(self._license_in_src, + self._license_in_spec)) + return WARNING + + def __call__(self, *args, **kwargs): + """ + 入口函数 + :param args: + :param kwargs: + :return: + """ + logger.info("check {} license ...".format(self._repo)) + + _ = not os.path.exists(self._work_tar_dir) and os.mkdir(self._work_tar_dir) + self._gr.decompress_all() # decompress all compressed file into work_tar_dir + self._pkg_license.load_config() # load license config into instance variable + + try: + return self.start_check_with_order("license_in_spec", "license_in_src", "license_is_same") + finally: + shutil.rmtree(self._work_tar_dir) \ No newline at end of file diff --git a/src/ac/acl/package_license/config/license_list b/src/ac/acl/package_license/config/license_list new file mode 100644 index 0000000000000000000000000000000000000000..c988ebb11820292c573fadc71727ebc5359311d5 --- /dev/null +++ b/src/ac/acl/package_license/config/license_list @@ -0,0 +1,263 @@ +AFL, white +AFLv2.1, white +AGPL-3.0, white +AGPLv3, white +AGPLv3+, white +Apache, white +Apache-2, white +Apache-2.0, white +APSL-2.0, white +Artistic, white +Artistic-1.0, white +Artistic-2.0, white +ASL-1.0, white +ASL-1.1, white +ASL-2.0, white +Boost, white +BSD, white +BSD-2-Clause, white +BSD-2-Clause-Patent, white +BSD3, white +BSD-3-Clause, white +BSD-licenced-3, white +BSL-1.0, white +CC0, white +CC0-1.0, white +CDDL, white +GFDL-1.1, white +Commons Clause 1.0, white +CPL, white +CPL-1.0, white +EPL, white +EPL-2.0, white +GPL-1.0, white +GPL, white +GPL+, white +GPL-1.0+, white +GPL2, white +GPL-2, white +GPL-2.0, white +GPL-2.0+, white +GPL-2.0-only, white +GPL-2.0-or-later, white +GPL-3.0, white +GPL-3.0+, white +GPL-3.0-only, white +GPLv1+, white +GPLv2, white +GPLV2, white +GPLv2+, white +GPLV2+, white +GPLv2-or-later, white +GPLv3, white +GPLv3+, white +ISC, white +LGPL-2.0, white +LGPL-2.0+, white +LGPL-2.1, white +LGPL-2.1+, white +LGPL-3.0+, white +LGPLv2, white +LGPLv2.1, white +LGPLv2.1+, white +LGPLv2+, white +LGPLv3, white +LGPLv3+, white +LPPL, white +MirOS, white +MIT, white +MPLv1.1, white +MPLv2.0, white +MPL-2, white +MPL-2.0, white +MPL2, white +MPLv1.1, white +MPL-1.1, white +Mulan-PSL-1, white +Mulan-PSL-2, white +Mulan 2.0, white +NCSA, white +OFL, white +OSL-2.1, white +Perl, white +Artistic-1.0-Perl, white +PHP, white +PostgreSQL, white +Python, white +Python-2.0, white +QPL, white +SISSL, white +Sleepycat, white +SSPL-1.0, white +W3C, white +zlib, white +Zlib, white +ZPL-2.0, white +ZPLv2.0, white +ZPLv2.1, white +ZPL-2.1, white +Adobe-2006, black +ADSL, black +Afmparse, black +Afmparse, black +AGPL-1.0-or-later, black +AMDPLPA, black +AML, black +AMPAS, black +AND, black +Arphic, black +Barr, black +BitTorrent-1.0, black +blessing, black +Borceux, black +BSD-3-Clause-Attribution, black +BSD-3-Clause-No-Nuclear-License-2014, black +BSD-3-Clause-Open-MPI, black +BSD-4-Clause-UC, black +BSD-Source-Code, black +bzip2-1.0.5, black +Caldera, black +CC0, black +CC0-1.0, black +CC-BY, black +CC-BY-1.0, black +CC-BY-2.5, black +CC-BY-NC-2.0, black +CC-BY-NC-3.0, black +CC-BY-NC-ND-1.0, black +CC-BY-NC-ND-2.5, black +CC-BY-NC-ND-4.0, black +CC-BY-NC-SA-2.0, black +CC-BY-NC-SA-3.0, black +CC-BY-ND-1.0, black +CC-BY-ND-2.5, black +CC-BY-ND-4.0, black +CC-BY-SA, black +CC-BY-SA-2.0, black +CC-BY-SA-3.0, black +CC-BY-SA-3.0, black +CC-PDDC, black +CDLA-Permissive-1.0, black +CECILL-1.0, black +CERN-OHL-1.1, black +CERN-OHL-P-2.0, black +CERN-OHL-W-2.0, black +CNRI-Jython, black +CNRI-Python-GPL-Compatible, black +copyleft-next-0.3.0, black +CPOL-1.02, black +CrystalStacker, black +Cube, black +D-FSL-1.0, black +DMIT, black +DMTF, black +DOC, black +DSDP, black +eGenix, black +ErlPL-1.1, black +Eurosym, black +FSFAP, black +FSFULLR, black +FTL, black +Giftware, black +Glide, black +gnuplot, black +GPL-1.0-or-later, black +HaskellReport, black +IBM, black +IBM-pibs, black +ICU, black +IEEE, black +IJG, black +ImageMagick, black +Info-ZIP, black +Info-ZIP, black +Intel-ACPI, black +Interbase, black +JPNIC, black +Knuth, black +LAL-1.2, black +Latex2e, black +LGPLLR, black +Liberation, black +libpng-2.0, black +libtiff, black +libtiff, black +Licence-2.0, black +Linux-OpenIB, black +LPPL-1.1, black +Lucida, black +MakeIndex, black +MIT-advertising, black +MIT-enna, black +MITNFA, black +mpich2, black +MulanPSL-1.0, black +NBPL-1.0, black +NetCDF, black +Netscape, black +NLPL, black +Nmap, black +ODC-By-1.0, black +OFL-1.0-no-RFN, black +OFSFDL, black +OGL-Canada-2.0, black +OGL-UK-2.0, black +OLDAP-1.2, black +OLDAP-1.4, black +OLDAP-2.0.1, black +OLDAP-2.2, black +OLDAP-2.2.2, black +OLDAP-2.4, black +OLDAP-2.6, black +OLDAP-2.8, black +OpenLDAP, black +OpenSSL, black +O-UDA-1.0, black +Parity-6.0.0, black +PDDL-1.0, black +PolyForm-Noncommercial-1.0.0, black +PSF, black +psfrag, black +psutils, black +Pubilc, black +Qhull, black +RHeCos-1.1, black +RSA-MD, black +Ruby, black +Saxpath, black +Sendmail, black +Sendmail, black +SGI-B-1.0, black +SHL-0.51, black +SMPPL, black +SNIA, black +Spencer-86, black +Spencer-99, black +SSH-OpenSSH, black +SSLeay, black +SWL, black +SWL, black +TCGL, black +TCL, black +TCL, black +TMate, black +TOSL, black +TTWL, black +TU-Berlin-2.0, black +UCD, black +Unicode, black +Unicode-DFS-2015, black +Unicode-TOU, black +Utopia, black +Verbatim, black +Vim, black +VOSTROM, black +W3C-20150513, black +Wsuipa, black +WTFPL, black +xinetd, black +XSkat, black +Zend, black +Zimbra-1.4, black +zlib-acknowledgement, black diff --git a/src/ac/acl/package_license/config/license_translations b/src/ac/acl/package_license/config/license_translations new file mode 100644 index 0000000000000000000000000000000000000000..541aa18ec691ede239110ce9796ae0f2b7419488 --- /dev/null +++ b/src/ac/acl/package_license/config/license_translations @@ -0,0 +1,104 @@ +# : +2-clause, BSD-2-Clause +AGPL-3, AGPL-3.0 +APL-2.0, Apache-2.0 +APL2, Apache-2.0 +APL2.0, Apache-2.0 +ASL 2.0, Apache-2.0 +ASL-2, Apache-2.0 +ASL-2.0, Apache-2.0 +Apache 2.0, Apache-2.0 +Apache License 2.0, Apache-2.0 +Apache License, Version 2.0, Apache-2.0 +Apache, Apache-2.0 +Apache-2, Apache-2.0 +Apache2.0, Apache-2.0 +Apachev2, Apache-2.0 +Artistic-1.0+GPL-1.0, Artistic-1.0 GPL-1.0 +Artistic License, Artistic +BSD(3-clause), BSD-3-Clause +BSD_2_clause, BSD-2-Clause +BSD_3_clause, BSD-3-Clause +Boost, BSL-1.0 +CC0, CC0-1.0 +CPL, CPL-1.0 +Expat, MIT +Eclipse Public License, EPL +GFDL1.1, GFDL-1.1 +GPL(==-2), GPL-2.0 +GPL(>=-2), GPL-2.0+ +GPL(>=-2.0), GPL-2.0+ +GPL(>=-2.1), GPL-2.0 +GPL(>=-3), GPL-3.0 +GPL(>=2), GPL-2.0+ +GPL(>=3), GPL-3.0+ +GPL-2+, GPL-2.0+ +GPL-2, GPL-2.0 +GPL-2.0+, GPL-2.0+ +GPL-2.0+LGPL-2.1, GPL-2.0 LGPL-2.1 +GPL-2.0, GPL-2.0 +GPL-2.0-or-later, GPL-2.0+ +GPL-3+, GPL-3.0 +GPL-3, GPL-3.0 +GPL-3.0+, GPL-3.0+ +GPL-3.0, GPL-3.0 +GPL2, GPL-2.0 +GPL3, GPL-3.0 +GPLV2, GPL-2.0 +GPLV3, GPL-3.0 +GPLv2+, GPL-2.0+ +GPLv2, GPL-2.0 +GPLv3+, GPL-3.0+ +GPLv3, GPL-3.0 +ISCL , ISC +LGPL(>=-2), LGPL-2.0+ +LGPL(>=-2.1), LGPL-2.1 +LGPL(>=2), LGPL-2.0+ +LGPL-2, LGPL-2.0 +LGPL-2.0+, LGPL-2.0+ +LGPL-2.1+, LGPL-2.1+ +LGPL-2.1-or-later, LGPL-2.1+ +LGPL-3+, LGPL-3.0+ +LGPL-3, LGPL-3.0 +LGPLv2+, LGPL-2.1+ +LGPLv2, LGPL-2.0 +LGPLv2.1+, LGPL-2.1+ +LGPLv2.1, LGPL-2.1 +LGPLv3+, LGPL-3.0+ +LGPLv3, LGPL-3.0 +MIT, MIT +MIT/X, MIT +MPL-2, MPL-2.0 +MPL2, MPL-2.0 +MPLv1.1, MPL-1.1 +MPLv2, MPL-2.0 +MPLv2.0, MPL-2.0 +MPLv2.0,, MPL-2.0 +PSF, Python-2.0 +Perl, Artistic-1.0-Perl +Python, Python-2.0 +VIM, Vim +ZLIB, Zlib +ZPL 2.1, ZPL-2.1 +ZPL, ZPL-2.0 +apache, Apache-2.0 +artistic2, Artistic-2.0 +artistic_2, Artistic-2.0 +gplv3, GPL-3.0 +http://creativecommons.org/licenses/BSD/, BSD-2-Clause +http://opensource.org/licenses/MIT, MIT +http://www.apache.org/licenses/LICENSE-2.0, Apache-2.0 +lgpl, LGPL-2.1 +MIT License, MIT +(mit), MIT +(MIT), MIT +perl, Artistic-1.0-Perl +(per1), Artistic-1.0-Perl +w3c, W3C +zlib, Zlib +zlib/libpng, zlib-acknowledgement +OFL, OFL +GNU LESSER GENERAL PUBLIC LICENSE, LGPL-2.1+ +BSD, BSD +version 3 of the GNU General Public License, GPL-3.0+ +GNU GENERAL PUBLIC LICENSE, GPL+ diff --git a/src/ac/acl/package_license/package_license.py b/src/ac/acl/package_license/package_license.py new file mode 100644 index 0000000000000000000000000000000000000000..93bb579a980575e2374851e2096d8aafff6e0766 --- /dev/null +++ b/src/ac/acl/package_license/package_license.py @@ -0,0 +1,184 @@ +# -*- encoding=utf-8 -*- +""" +# ********************************************************************************** +# Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved. +# [openeuler-jenkins] is licensed under the Mulan PSL v1. +# You can use this software according to the terms and conditions of the Mulan PSL v1. +# You may obtain a copy of Mulan PSL v1 at: +# http://license.coscl.org.cn/MulanPSL +# 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 v1 for more details. +# Author: +# Create: 2020-10-16 +# Description: check spec file +# ********************************************************************************** +""" + +import logging +import os +import re +import chardet + +from src.ac.common.pyrpm import Spec, replace_macros +from src.ac.common.rpm_spec_adapter import RPMSpecAdapter + +logger = logging.getLogger("ac") + +class PkgLicense(object): + """ + 解析获取软件包中源码、spec中的license + 进行白名单校验、一致性检查 + """ + + LICENSE_FILE_TARGET = ["apache-2.0", + "artistic", + "artistic.txt", + "libcurllicense", + "gpl.txt", + "gpl2.txt", + "gplv2.txt", + "notice", + "about_bsd.txt", + "mit", + "pom.xml", + "meta.yml"] + + LICENSE_TARGET_PAT = re.compile(r"^(copying)|(copyright)|(copyrights)|(licenses)|(licen[cs]e)(\.(txt|xml))?$") + + WHITE_LIST_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), + "config", + "license_list") + LICENSE_TRANS_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), + "config", + "license_translations") + + def __init__(self): + self._white_black_list = {} + self._license_translation = {} + + def _load_license_dict(self, filename): + """ + read the dict from license file + """ + result = {} + if not os.path.isfile(filename): + logger.warning("not found the config file: %s", os.path.basename(filename)) + return result + with open(filename, "r") as f: + for line in f: + if line.startswith("#"): + continue + k, v = line.rsplit(", ", 1) + result[k] = v.rstrip() + return result + + def load_config(self): + """ + Load the license white list and translation list into dict + """ + self._white_black_list = self._load_license_dict(self.WHITE_LIST_PATH) + self._license_translation = self._load_license_dict(self.LICENSE_TRANS_PATH) + + def check_license_safe(self, licenses): + """ + Check if the license is in the blacklist + """ + result = True + for lic in licenses: + res = self._white_black_list.get(lic, "Need review") + if res == "white": + logger.info("This license: %s is safe", lic) + elif res == "black": + logger.error("This license: %s is not safe", lic) + result = False + else: + logger.warning("This license: %s need to be review", lic) + result = False + return result + + def translate_license(self, licenses): + """ + Convert license to uniform format + """ + result = set() + for lic in licenses: + real_license = self._license_translation.get(lic, lic) + result.add(real_license) + return result + + @staticmethod + def split_license(licenses): + """ + 分割spec license字段的license + """ + license_set = re.split(r'/\s?|\(|\)|\,|[Aa][Nn][Dd]|or|OR|\s?/g', licenses) + for index in range(len(license_set)): # 去除字符串首尾空格 + license_set[index] = license_set[index].strip() + return set(filter(None, license_set)) # 去除list中空字符串 + + # 以下为从license文件中获取license + def scan_licenses_in_license(self, srcdir): + """ + Find LICENSE files and scan. + """ + licenses_in_file = set() + if not os.path.exists(srcdir): + logger.error("%s not exist.", srcdir) + return licenses_in_file + + for root, dirnames, filenames in os.walk(srcdir): + for filename in filenames: + if (filename.lower() in self.LICENSE_FILE_TARGET + or self.LICENSE_TARGET_PAT.search(filename.lower())): + logger.info("scan the license target file: %s", filename) + licenses_in_file.update( + self.scan_licenses( + os.path.join(root, filename))) + logger.info("all licenses from src: %s", licenses_in_file) + return licenses_in_file + + def scan_licenses(self, copying): + """ + Scan licenses from copying file and add to licenses_for_source_files. + if get contents failed or decode data failed, return nothing. + """ + licenses_in_file = set() + + if not os.path.exists(copying): + logger.warning("file: %s not exist", copying) + return licenses_in_file + + for word in self._license_translation: + if word in copying: + licenses_in_file.add(word) + + with open(copying, "rb") as f: + data = f.read() + data = PkgLicense._decode_license(data, chardet.detect(data)['encoding']) + if not data: + return licenses_in_file + for word in self._license_translation: + if word in data: + licenses_in_file.add(word) + return licenses_in_file + + @staticmethod + def _decode_license(license_string, charset): + """ + Decode the license string. return the license string or nothing. + """ + if not charset: + return + return license_string.decode(charset) + + @staticmethod + def check_licenses_is_same(licenses_for_spec, licenses_for_source_files): + """ + Check if the licenses from SPEC is the same as the licenses from LICENSE file. + if same, return True. if not same return False. + """ + if not licenses_for_source_files: + return False + return licenses_for_spec.issuperset(licenses_for_source_files) \ No newline at end of file diff --git a/src/ac/common/gitee_repo.py b/src/ac/common/gitee_repo.py index 40e73ce4ccf6980ffaf5bf5e47f11d545f6c90bb..3a4d3ef8bd174f49b05933672c56875d5b4b9327 100644 --- a/src/ac/common/gitee_repo.py +++ b/src/ac/common/gitee_repo.py @@ -21,6 +21,7 @@ import logging from src.proxy.git_proxy import GitProxy from src.utils.shell_cmd import shell_cmd_live +from src.ac.acl.package_license.package_license import PkgLicense logger = logging.getLogger("ac") @@ -168,38 +169,89 @@ class GiteeRepo(object): return 0 if all(rs) else (1 if any(rs) else -1) + def scan_license_in_spec(self, spec): + """ + Find spec file and scan. If no spec file or open file failed, the program will exit with an error. + """ + if not spec: + return set() + licenses = spec.license + licenses_in_spec = PkgLicense.split_license(licenses) + logger.info("all licenses from SPEC: %s", licenses_in_spec) + return licenses_in_spec + @staticmethod def is_py_file(filename): + """ + 功能描述:判断文件是否是python文件 + 参数:文件名 + 返回值:bool + """ return filename.endswith((".py",)) @staticmethod def is_go_file(filename): + """ + 功能描述:判断文件名是否是go文件 + 参数:文件名 + 返回值:bool + """ return filename.endswith((".go",)) @staticmethod def is_c_cplusplus_file(filename): + """ + 功能描述:判断文件名是否是c++文件 + 参数:文件名 + 返回值:bool + """ return filename.endswith((".c", ".cpp", ".cc", ".cxx", ".c++", ".h", ".hpp", "hxx")) @staticmethod def is_code_file(filename): + """ + 功能描述:判断文件名是否是源码文件 + 参数:文件名 + 返回值:bool + """ return GiteeRepo.is_py_file(filename) \ or GiteeRepo.is_go_file(filename) \ or GiteeRepo.is_c_cplusplus_file(filename) @staticmethod def is_patch_file(filename): + """ + 功能描述:判断文件名是否是补丁文件 + 参数:文件名 + 返回值:bool + """ return filename.endswith((".patch", ".diff")) @staticmethod def is_compress_file(filename): + """ + 功能描述:判断文件名是否是压缩文件 + 参数:文件名 + 返回值:bool + """ return GiteeRepo._is_compress_tar_file(filename) or GiteeRepo._is_compress_zip_file(filename) @staticmethod def _is_compress_zip_file(filename): + """ + 功能描述:判断文件名是否是zip压缩文件 + 参数:文件名 + 返回值:bool + """ return filename.endswith((".zip",)) @staticmethod def _is_compress_tar_file(filename): + """ + 功能描述:判断文件名是否是tar压缩文件 + 参数:文件名 + 返回值:bool + """ return filename.endswith((".tar.gz", ".tar.bz", ".tar.bz2", ".tar.xz", "tgz")) @staticmethod diff --git a/src/ac/framework/ac.yaml b/src/ac/framework/ac.yaml index 2c2ac9160b9900fdd24dbacc7485ae4adee3b73a..47fefb9953f1099f4dfc1525454f1b519ea3aa21 100644 --- a/src/ac/framework/ac.yaml +++ b/src/ac/framework/ac.yaml @@ -9,8 +9,12 @@ code: entry: CheckCodeStyle #exclude: True ignored: [] -yaml: +package_yaml: hint: check_package_yaml_file module: package_yaml.check_yaml entry: CheckPackageYaml ignored: ["fields"] +package_license: + hint: check_package_license + module: package_license.check_license + entry: CheckLicense \ No newline at end of file diff --git a/src/requirements b/src/requirements index 2829e5c2736da41bc20842679f02706bdc7a1878..34e139555ef82db1274bee08b2b88dd6eb2d7706 100644 --- a/src/requirements +++ b/src/requirements @@ -6,4 +6,5 @@ PyYAML gevent==1.2.2 jsonpath mock -tldextract \ No newline at end of file +tldextract +chardet \ No newline at end of file diff --git a/test/ac/acl/license/__init__.py b/test/ac/acl/license/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..36e95ff3db7d173ff656de1605ce299b4e77f17a --- /dev/null +++ b/test/ac/acl/license/__init__.py @@ -0,0 +1,17 @@ +# -*- encoding=utf-8 -*- +""" +# ********************************************************************************** +# Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved. +# [openeuler-jenkins] is licensed under the Mulan PSL v1. +# You can use this software according to the terms and conditions of the Mulan PSL v1. +# You may obtain a copy of Mulan PSL v1 at: +# http://license.coscl.org.cn/MulanPSL +# 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 v1 for more details. +# Author: +# Create: 2020-10-16 +# Description: check spec file +# ********************************************************************************** +""" \ No newline at end of file diff --git a/test/ac/acl/license/license_test_sample/no_spec/no_spec b/test/ac/acl/license/license_test_sample/no_spec/no_spec new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/test/ac/acl/license/license_test_sample/no_src/no_src b/test/ac/acl/license/license_test_sample/no_src/no_src new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/test/ac/acl/license/license_test_sample/pkgship/README.en.md b/test/ac/acl/license/license_test_sample/pkgship/README.en.md new file mode 100644 index 0000000000000000000000000000000000000000..ae5aff0dad8869a2b9b7b973d58a460cbc71015a --- /dev/null +++ b/test/ac/acl/license/license_test_sample/pkgship/README.en.md @@ -0,0 +1,36 @@ +# pkgship + +#### Description +a package depend query tool + +#### Software Architecture +Software architecture description + +#### Installation + +1. xxxx +2. xxxx +3. xxxx + +#### Instructions + +1. xxxx +2. xxxx +3. xxxx + +#### Contribution + +1. Fork the repository +2. Create Feat_xxx branch +3. Commit your code +4. Create Pull Request + + +#### Gitee Feature + +1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md +2. Gitee blog [blog.gitee.com](https://blog.gitee.com) +3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore) +4. The most valuable open source project [GVP](https://gitee.com/gvp) +5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) +6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) diff --git a/test/ac/acl/license/license_test_sample/pkgship/README.md b/test/ac/acl/license/license_test_sample/pkgship/README.md new file mode 100644 index 0000000000000000000000000000000000000000..b5a39bf91029b55ab201ba35a6b0957e3239519b --- /dev/null +++ b/test/ac/acl/license/license_test_sample/pkgship/README.md @@ -0,0 +1,176 @@ +[English](./README-en.md) | 简体中文 + +# pkgship + +## 介绍 +pkgship是一款管理OS软件包依赖关系,提供依赖和被依赖关系的完整图谱查询工具,pkgship提供软件包依赖,生命周期,补丁查询等功能。 +1. 软件包依赖:方便社区人员在新引入、软件包更新和删除的时候能方便的了解软件的影响范围。 +2. 生命周期管理:跟踪upstream软件包发布状态,方便维护人员了解当前软件状态,及时升级到合理的版本。 +3. 补丁查询:方便社区人员了解openEuler软件包的补丁情况,方便的提取补丁内容 + + +### 软件架构 +系统采用flask-restful开发,使用SQLAlchemy ORM查询框架,同时支持mysql和sqlite数据库,通过配置文件的形式进行更改 + + +安装教程 +--- +#### 方法一: 可以使用dnf挂载pkgship软件在所在repo源,直接下载安装pkgship及其依赖 + +``` +dnf install pkgship(版本号) +``` + +#### 方法二: 可以直接下载pkgship的rpm包后安装软件包 + +``` +rpm -ivh pkgship.rpm +``` +或者 +``` +dnf install pkgship-(版本号) +``` + +系统配置 +--- +系统的默认配置文件存放在 /etc/pkgship/packge.ini,请根据实际情况进行配置更改 + +``` +vim /etc/pkgship/package.ini +``` +创建初始化数据库的yaml配置文件: +conf.yaml 文件默认存放在 /etc/pkgship/ 路径下,pkgship会通过该配置读取要建立的数据库名称以及需要导入的sqlite文件。conf.yaml 示例如下: + +``` +- dbname:openEuler-20.03-LTS + src_db_file: +- /etc/pkgship/src.sqlite + bin_db_file: +- /etc/pkgship/bin.sqlite + status:enable + priority:1 +``` + +如需更改存放路径,请更改package.ini下的 init_conf_path 选项 + + +服务启动和停止 +--- +pkgship使用uWSGI web服务器 +``` +pkgshipd start + +pkgshipd stop +``` + +使用说明 +--- +#### 1. 数据库初始化 +``` +pkgship init +``` +#### 2. 单包查询 + +查询源码包(sourceName)在所有数据库中的信息 +``` +pkgship single sourceName +``` +查询当前包(sourceName)在指定数据库(dbName)中的信息 +``` +pkgship single sourceName -db dbName +``` +#### 3. 查询所有包 +查询所有数据库下包含的所有包的信息 +``` +pkgship list +``` +查询指定数据库(dbName)下的所有包的信息 +``` +pkgship list -db dbName +``` +#### 4. 安装依赖查询 +查询二进制包(binaryName)的安装依赖,按照默认优先级查询数据库 +``` +pkgship installdep binaryName +``` +在指定数据库(dbName)下查询二进制包(binaryName)的所有安装依赖 +按照先后顺序指定数据库查询的优先级 +``` +pkgship installdep binaryName -dbs dbName1 dbName2... +``` +#### 5. 编译依赖查询 +查询源码包(sourceName)的所有编译依赖,按照默认优先级查询数据库 +``` +pkgship builddep sourceName +``` +在指定数据库(dbName)下查询源码包(sourceName)的所有安装依赖 +按照先后顺序指定数据库查询的优先级 +``` +pkgship builddep sourceName -dbs dbName1 dbName2... +``` +#### 6. 自编译自安装依赖查询 +查询二进制包(binaryName)的安装和编译依赖,按照默认优先级查询数据库 +``` +pkgship selfbuild binaryName +``` +查询源码包(sourceName )的安装和编译依赖,按照默认优先级查询数据库 +``` +pkgship selfbuild sourceName -t source +``` +其他参数: + +-dbs 指定数据库优先级. +``` +示例:pkgship selfbuild binaryName -dbs dbName1 dbName2 +``` +-s 是否查询自编译依赖 +默认为0不查询自编译依赖,可以指定0或1(表示查询自编译) +``` +查询自编译示例:pkgship selfbuild sourceName -t source -s 1 +``` +-w 是否查询对应包的子包.默认为0,不查询对应子包,可以指定 0或1(表示查询对应子包) +``` +查询子包示例:pkgship selfbuild binaryName -w 1 +``` +#### 7. 被依赖查询 +查询源码包(sourceName)在某数据库(dbName)中被哪些包所依赖 +查询结果默认不包含对应二进制包的子包 +``` +pkgship bedepend sourceName -db dbName +``` +使查询结果包含二进制包的子包 加入参数 -w +``` +pkgship bedepend sourceName -db dbName -w 1 +``` +#### 8. 修改包信息记录 +变更数据库中(dbName)源码包(sourceName)的maintainer为Newmaintainer +``` +pkgship updatepkg sourceName db dbName -m Newmaintainer +``` +变更数据库中(dbName)源码包(sourceName)的maintainlevel为Newmaintainlevel,值在1~4之间 +``` +pkgship updatepkg sourceName db dbName -l Newmaintainlevel +``` +同时变更数据库中(dbName)源码包(sourceName)的maintainer 为Newmaintainer和变更maintainlevel为Newmaintainlevel +``` +pkgship updatepkg sourceName db dbName -m Newmaintainer -l Newmaintainlevel +``` +#### 9. 删除数据库 +删除指定数据库(dbName) +``` +pkgship rm db dbName +``` + +参与贡献 +--- +我们非常欢迎新贡献者加入到项目中来,也非常高兴能为新加入贡献者提供指导和帮助。在您贡献代码前,需要先签署[CLA](https://openeuler.org/en/cla.html)。 + +1. Fork 本仓库 +2. 新建 Feat_xxx 分支 +3. 提交代码 +4. 新建 Pull Request + + +### 会议记录 +1. 2020.5.18:https://etherpad.openeuler.org/p/aHIX4005bTY1OHtOd_Zc + diff --git a/test/ac/acl/license/license_test_sample/pkgship/pkgship-1.1.0.tar.gz b/test/ac/acl/license/license_test_sample/pkgship/pkgship-1.1.0.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..9e45007af4b886171379b56d7a74feb9acce0481 Binary files /dev/null and b/test/ac/acl/license/license_test_sample/pkgship/pkgship-1.1.0.tar.gz differ diff --git a/test/ac/acl/license/license_test_sample/pkgship/pkgship.spec b/test/ac/acl/license/license_test_sample/pkgship/pkgship.spec new file mode 100644 index 0000000000000000000000000000000000000000..0abe1da5bfa7ef80919984e30bd89295a4a86e24 --- /dev/null +++ b/test/ac/acl/license/license_test_sample/pkgship/pkgship.spec @@ -0,0 +1,164 @@ +Name: pkgship +Version: 1.1.0 +Release: 14 +Summary: Pkgship implements rpm package dependence ,maintainer, patch query and so no. +License: Mulan 2.0 +URL: https://gitee.com/openeuler/openEuler-Advisor +Source0: https://gitee.com/openeuler/openEuler-Advisor/pkgship-%{version}.tar.gz + +# Modify the query logic of package information, reduce redundant queries and align dnf query results, +# extract multiplexing functions, add corresponding docString, and clear pylint +Patch0: 0001-solve-installation-dependency-query-error.patch + +# Fix the problem of continuous spaces in message information in log records +Patch1: 0002-fix-the-problem-of-continuous-spaces.patch + +# When initializing logging, modify the incoming class object to an instance of the class, +# ensure the execution of internal functions,and read configuration file content +Patch2: 0003-fix-log_level-configuration-item-not-work.patch + +# Fix the error when executing query commands +Patch3: 0004-fix-the-error-when-executing-query-commands.patch + +# Add the judgment of whether the subpack_name attribute exists, fix the code indentation problem, +# and reduce the judgment branch of the old code. +Patch4: 0005-fix-the-error-when-source-package-has-no-sub-packages.patch + +# Solve the problem of data duplication, increase the maximum queue length judgment, +# and avoid occupying too much memory +Patch5: 0006-fix-memory_caused-service-crash-and-data-duplication-issue.patch + +# Fix the problem of function parameters +Patch6: 0007-correct-the-parameter-transfer-method-and-change-the-status-recording-method.patch + +# Fix the selfbuild error message +Patch7: 0008-fix-selfbuild-error-message.patch + +# Optimize-log-records-when-obtaining-issue-content +Patch8: 0009-optimize-log-records-when-obtaining-issue-content.patch +BuildArch: noarch + +BuildRequires: python3-flask-restful python3-flask python3 python3-pyyaml python3-sqlalchemy +BuildRequires: python3-prettytable python3-requests python3-flask-session python3-flask-script python3-marshmallow +BuildRequires: python3-Flask-APScheduler python3-pandas python3-retrying python3-xlrd python3-XlsxWriter +BuildRequires: python3-concurrent-log-handler +Requires: python3-pip python3-flask-restful python3-flask python3 python3-pyyaml +Requires: python3-sqlalchemy python3-prettytable python3-requests python3-concurrent-log-handler +Requires: python3-flask-session python3-flask-script python3-marshmallow python3-uWSGI +Requires: python3-pandas python3-dateutil python3-XlsxWriter python3-xlrd python3-Flask-APScheduler python3-retrying + +%description +Pkgship implements rpm package dependence ,maintainer, patch query and so no. + +%prep +%autosetup -n pkgship-%{version} -p1 + +%build +%py3_build + +%install +%py3_install + + +%check +# The apscheduler cannot catch the local time, so a time zone must be assigned before running the test case. +export TZ=Asia/Shanghai +# change log_path to solve default log_path permission denied problem +log_path=`pwd`/tmp/ +sed -i "/\[LOG\]/a\log_path=$log_path" test/common_files/package.ini +%{__python3} -m unittest test/init_test.py +%{__python3} -m unittest test/read_test.py +%{__python3} -m unittest test/write_test.py +rm -rf $log_path + +%post + +%postun + + +%files +%doc README.md +%{python3_sitelib}/* +%attr(0755,root,root) %config %{_sysconfdir}/pkgship/* +%attr(0755,root,root) %{_bindir}/pkgshipd +%attr(0755,root,root) %{_bindir}/pkgship + +%changelog +* Tue Oct 13 2020 ZhangTao 1.1.0-14 +- correct-the-parameter-transfer-method-and-change-the-status-recording-method. + +* Fri Sep 25 2020 Cheng Shaowei 1.1.0-13 +- Optimize-log-records-when-obtaining-issue-content + +* Fri Sep 25 2020 Zhang Tao - 1.1.0-12 +- In the selfbuild scenario, add the error message that the software package cannot be found + +* Fri Sep 25 2020 Zhang Tao - 1.1.0-11 +- Fix the problem of function parameters + +* Thu Sep 24 2020 Yiru Wang - 1.1.0-10 +- rm queue_maxsize param from package.ini and this parameter is not customizable + +* Tue Sep 21 2020 Shenmei Tu - 1.0-0-9 +- Solve the problem of data duplication, increase the maximum queue length judgment, +- and avoid occupying too much memory + +* Mon Sep 21 2020 Shenmei Tu - 1.0-0-8 +- Add the judgment of whether the subpack_name attribute exists, fix the code indentation problem, +- and reduce the judgment branch of the old code. + +* Mon Sep 21 2020 Shenmei Tu - 1.0-0-7 +- fix the error when executing query commands + +* Mon Sep 21 2020 Shenmei Tu - 1.0-0-6 +- When initializing logging, modify the incoming class object to an instance of the class, +- ensure the execution of internal functions,and read configuration file content + +* Mon Sep 21 2020 Shenmei Tu - 1.0-0-5 +- Fix the problem of continuous spaces in message information in log records + +* Thu Sep 17 2020 Shenmei Tu - 1.0-0-4 +- Modify the query logic of package information, reduce redundant queries and align dnf query results, +- extract multiplexing functions, add corresponding docString, and clear pylint + +* Fri Sep 11 2020 Yiru Wang - 1.1.0-3 +- #I1UCM8, #I1UC8G: Modify some config files' permission issue; +- #I1TIYQ: Add concurrent-log-handler module to fix log resource conflict issue +- #I1TML0: Fix the matching relationship between source_rpm and src_name + +* Tue Sep 1 2020 Zhengtang Gong - 1.1.0-2 +- Delete the packaged form of pyinstaller and change the execution + of the command in the form of a single file as the input + +* Sat Aug 29 2020 Yiru Wang - 1.1.0-1 +- Add package management features: + RPM packages statically displayed in the version repository + RPM packages used time displayed for current version in the version repository + Issue management of packages in a version-management repository + +* Fri Aug 21 2020 Chengqiang Bao < baochengqiang1@huawei.com > - 1.0.0-7 +- Fixed a problem with command line initialization of the Filepath parameter where relative paths are not supported and paths are too long + +* Wed Aug 12 2020 Zhang Tao - 1.0.0-6 +- Fix the test content to adapt to the new data structure, add BuildRequires for running %check + +* Mon Aug 10 2020 Zhengtang Gong - 1.0-5 +- Command line supports calling remote services + +* Wed Aug 5 2020 Yiru Wang - 1.0-4 +- change Requires rpm pakcages' name to latest one + +* Mon Jul 13 2020 Yiru Wang - 1.0-3 +- run test cases while building + +* Sat Jul 4 2020 Yiru Wang - 1.0-2 +- cheange requires python3.7 to python3,add check pyinstaller file. + +* Tue Jun 30 2020 Yiru Wang - 1.0-1 +- add pkgshipd file + +* Thu Jun 11 2020 Feng Hu - 1.0-0 +- add macro to build cli bin when rpm install + +* Sat Jun 6 2020 Feng Hu - 1.0-0 +- init package diff --git a/test/ac/acl/license/license_test_sample/rubygem-mail/2.6.4.tar.gz b/test/ac/acl/license/license_test_sample/rubygem-mail/2.6.4.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..3c7c19f7c87bcf156c34a394d514abe16ba5e9fe Binary files /dev/null and b/test/ac/acl/license/license_test_sample/rubygem-mail/2.6.4.tar.gz differ diff --git a/test/ac/acl/license/license_test_sample/rubygem-mail/mail-2.6.4-Fix-deprecated-warnings-in-Ruby-2.4.0.patch b/test/ac/acl/license/license_test_sample/rubygem-mail/mail-2.6.4-Fix-deprecated-warnings-in-Ruby-2.4.0.patch new file mode 100644 index 0000000000000000000000000000000000000000..01d3556a6f7966d99b539d2eb65c25d75f8cfc22 --- /dev/null +++ b/test/ac/acl/license/license_test_sample/rubygem-mail/mail-2.6.4-Fix-deprecated-warnings-in-Ruby-2.4.0.patch @@ -0,0 +1,59 @@ +From e8fde9cf1d77ee7e465c12e809501df8d27e8451 Mon Sep 17 00:00:00 2001 +From: Koichi ITO +Date: Sun, 4 Dec 2016 12:33:06 +0800 +Subject: [PATCH] Fix deprecated warnings in Ruby 2.4.0+ + +--- + lib/mail/attachments_list.rb | 2 +- + lib/mail/multibyte/chars.rb | 4 ++-- + lib/mail/network/retriever_methods/test_retriever.rb | 2 +- + 3 files changed, 4 insertions(+), 4 deletions(-) + +diff --git a/lib/mail/attachments_list.rb b/lib/mail/attachments_list.rb +index bb34a85..14fe31c 100644 +--- a/lib/mail/attachments_list.rb ++++ b/lib/mail/attachments_list.rb +@@ -30,7 +30,7 @@ module Mail + # mail.attachments['test.png'].filename #=> 'test.png' + # mail.attachments[1].filename #=> 'test.jpg' + def [](index_value) +- if index_value.is_a?(Fixnum) ++ if index_value.is_a?(Integer) + self.fetch(index_value) + else + self.select { |a| a.filename == index_value }.first +diff --git a/lib/mail/multibyte/chars.rb b/lib/mail/multibyte/chars.rb +index bb39897..2e431ca 100644 +--- a/lib/mail/multibyte/chars.rb ++++ b/lib/mail/multibyte/chars.rb +@@ -269,12 +269,12 @@ module Mail #:nodoc: + @wrapped_string[*args] = replace_by + else + result = Unicode.u_unpack(@wrapped_string) +- if args[0].is_a?(Fixnum) ++ if args[0].is_a?(Integer) + raise IndexError, "index #{args[0]} out of string" if args[0] >= result.length + min = args[0] + max = args[1].nil? ? min : (min + args[1] - 1) + range = Range.new(min, max) +- replace_by = [replace_by].pack('U') if replace_by.is_a?(Fixnum) ++ replace_by = [replace_by].pack('U') if replace_by.is_a?(Integer) + elsif args.first.is_a?(Range) + raise RangeError, "#{args[0]} out of range" if args[0].min >= result.length + range = args[0] +diff --git a/lib/mail/network/retriever_methods/test_retriever.rb b/lib/mail/network/retriever_methods/test_retriever.rb +index 9bb3e1a..dfbc909 100644 +--- a/lib/mail/network/retriever_methods/test_retriever.rb ++++ b/lib/mail/network/retriever_methods/test_retriever.rb +@@ -25,7 +25,7 @@ module Mail + emails_index.reverse! if options[:what] == :last + emails_index = case count = options[:count] + when :all then emails_index +- when Fixnum then emails_index[0, count] ++ when Integer then emails_index[0, count] + else + raise 'Invalid count option value: ' + count.inspect + end +-- +2.11.0 + diff --git a/test/ac/acl/license/license_test_sample/rubygem-mail/mail-2.6.4-fix-new-warning-in-ruby-2.4.patch b/test/ac/acl/license/license_test_sample/rubygem-mail/mail-2.6.4-fix-new-warning-in-ruby-2.4.patch new file mode 100644 index 0000000000000000000000000000000000000000..af455602f552ad3069f29a7d32e64feea9dc5b1d --- /dev/null +++ b/test/ac/acl/license/license_test_sample/rubygem-mail/mail-2.6.4-fix-new-warning-in-ruby-2.4.patch @@ -0,0 +1,38 @@ +From 48cb6db25b31eebe7bdd330d812c52d3c93aa328 Mon Sep 17 00:00:00 2001 +From: "yuuji.yaginuma" +Date: Tue, 13 Dec 2016 07:50:42 +0900 +Subject: [PATCH] fix new warning in ruby 2.4 + +This fixes the following warning. + +``` +/home/travis/build/mikel/mail/lib/mail/fields/common/address_container.rb:11: warning: parentheses after method name is interpreted as +/home/travis/build/mikel/mail/lib/mail/fields/common/address_container.rb:11: warning: an argument list, not a decomposed argument +``` + +Ref: https://github.com/ruby/ruby/commit/65e27c8b138d6959608658ffce2fa761842b8d24 +--- + lib/mail/fields/common/address_container.rb | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/lib/mail/fields/common/address_container.rb b/lib/mail/fields/common/address_container.rb +index f4a5aec..48c1286 100644 +--- a/lib/mail/fields/common/address_container.rb ++++ b/lib/mail/fields/common/address_container.rb +@@ -8,10 +8,10 @@ module Mail + super(list) + end + +- def << (address) ++ def <<(address) + @field << address + end + + end + +-end +\ No newline at end of file ++end +-- +2.11.0 + diff --git a/test/ac/acl/license/license_test_sample/rubygem-mail/mail-2.6.4.gem b/test/ac/acl/license/license_test_sample/rubygem-mail/mail-2.6.4.gem new file mode 100644 index 0000000000000000000000000000000000000000..4fa553a1f40c3cccb1614b4a9b980cb907d3b860 Binary files /dev/null and b/test/ac/acl/license/license_test_sample/rubygem-mail/mail-2.6.4.gem differ diff --git a/test/ac/acl/license/license_test_sample/rubygem-mail/rubygem-mail.spec b/test/ac/acl/license/license_test_sample/rubygem-mail/rubygem-mail.spec new file mode 100644 index 0000000000000000000000000000000000000000..750602f02adb2acd78c5f8d40fb18b9b457d0575 --- /dev/null +++ b/test/ac/acl/license/license_test_sample/rubygem-mail/rubygem-mail.spec @@ -0,0 +1,71 @@ +%global gem_name mail +Name: rubygem-%{gem_name} +Version: 2.6.4 +Release: 2 +Summary: Mail provides a nice Ruby DSL for making, sending and reading emails +License: MIT +URL: https://github.com/mikel/mail +Source0: https://rubygems.org/gems/%{gem_name}-%{version}.gem +Source1: https://github.com/mikel/mail/archive/%{version}.tar.gz +# Fix Ruby 2.4 compatibility. +# https://github.com/mikel/mail/commit/e8fde9cf1d77ee7e465c12e809501df8d27e8451 +Patch0: mail-2.6.4-Fix-deprecated-warnings-in-Ruby-2.4.0.patch +# https://github.com/mikel/mail/commit/48cb6db25b31eebe7bdd330d812c52d3c93aa328 +Patch1: mail-2.6.4-fix-new-warning-in-ruby-2.4.patch +BuildRequires: ruby(release) rubygems-devel ruby rubygem(mime-types) >= 1.16 rubygem(rspec) +BuildArch: noarch +%description +A really Ruby Mail handler. + +%package doc +Summary: Documentation for %{name} +Requires: %{name} = %{version}-%{release} +BuildArch: noarch +%description doc +Documentation for %{name}. + +%prep +%setup -q -c -T +ln -s %{_builddir}/%{gem_name}-%{version}/spec ../spec +%gem_install -n %{SOURCE0} +pushd .%{gem_instdir} +%patch0 -p1 +%patch1 -p1 +popd + +%build + +%install +mkdir -p %{buildroot}%{gem_dir} +cp -a .%{gem_dir}/* \ + %{buildroot}%{gem_dir}/ + +%check +pushd .%{gem_instdir} +tar xzvf %{SOURCE1} +rspec spec +popd + +%files +%dir %{gem_instdir} +%license %{gem_instdir}/MIT-LICENSE +%{gem_libdir} +%exclude %{gem_cache} +%{gem_spec} + +%files doc +%doc %{gem_docdir} +%doc %{gem_instdir}/CHANGELOG.rdoc +%doc %{gem_instdir}/CONTRIBUTING.md +%doc %{gem_instdir}/Dependencies.txt +%{gem_instdir}/Gemfile* +%doc %{gem_instdir}/README.md +%{gem_instdir}/Rakefile +%doc %{gem_instdir}/TODO.rdoc + +%changelog +* Tue Sep 8 2020 geyanan - 2.6.4-2 +- fix build fail + +* Wed Aug 19 2020 geyanan - 2.6.4-1 +- package init diff --git a/test/ac/acl/license/license_test_sample/rubygem-mail/rubygem-mail.yaml b/test/ac/acl/license/license_test_sample/rubygem-mail/rubygem-mail.yaml new file mode 100644 index 0000000000000000000000000000000000000000..98f733e147e70f49f88c832934a60cef477b5fdf --- /dev/null +++ b/test/ac/acl/license/license_test_sample/rubygem-mail/rubygem-mail.yaml @@ -0,0 +1,4 @@ +version_control: github +src_repo: mikel/mail +tag_prefix: "" +seperator: "." diff --git a/test/ac/acl/license/license_test_sample/spec_fail/spec_fail.spec b/test/ac/acl/license/license_test_sample/spec_fail/spec_fail.spec new file mode 100644 index 0000000000000000000000000000000000000000..80b9b23d87dd793ead6056a013fdac2a522635a4 --- /dev/null +++ b/test/ac/acl/license/license_test_sample/spec_fail/spec_fail.spec @@ -0,0 +1,37 @@ +Name: spec_fail +Version: 1.1.0 +Release: 1 +Summary: test case for spec license error. +License: Mulan 2.0 and ADSL +URL: https://gitee.com/openeuler/openEuler-Advisor +Source0: https://gitee.com/openeuler/openEuler-Advisor/pkgship-%{version}.tar.gz + +%description +test case for spec license error. + +%prep +%autosetup + +%build +%py3_build + +%install +%py3_install + +%check + +%post + +%postun + + +%files +%doc README.md +%{python3_sitelib}/* +%attr(0755,root,root) %config %{_sysconfdir}/pkgship/* +%attr(0755,root,root) %{_bindir}/pkgshipd +%attr(0755,root,root) %{_bindir}/pkgship + +%changelog +* Mon Oct 19 2020 xxx - 1.0-0 +- init package diff --git a/test/ac/acl/license/license_test_sample/spec_src_diff/spec_src_diff b/test/ac/acl/license/license_test_sample/spec_src_diff/spec_src_diff new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/test/ac/acl/license/license_test_sample/spec_src_same/spec_src_same b/test/ac/acl/license/license_test_sample/spec_src_same/spec_src_same new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/test/ac/acl/license/license_test_sample/src_fail/src_fail b/test/ac/acl/license/license_test_sample/src_fail/src_fail new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/test/ac/acl/license/license_test_sample/src_success/src_success b/test/ac/acl/license/license_test_sample/src_success/src_success new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/test/ac/acl/license/test_check_license.py b/test/ac/acl/license/test_check_license.py new file mode 100644 index 0000000000000000000000000000000000000000..22431ef7cff5ab238c3b1046dcfd51c85dfdc99f --- /dev/null +++ b/test/ac/acl/license/test_check_license.py @@ -0,0 +1,133 @@ +# -*- encoding=utf-8 -*- +""" +# ********************************************************************************** +# Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved. +# [openeuler-jenkins] is licensed under the Mulan PSL v1. +# You can use this software according to the terms and conditions of the Mulan PSL v1. +# You may obtain a copy of Mulan PSL v1 at: +# http://license.coscl.org.cn/MulanPSL +# 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 v1 for more details. +# Author: +# Create: 2020-10-16 +# Description: check spec file +# ********************************************************************************** +""" + +import unittest +import mock +import sys +import os +import types +import logging.config +import logging +import shutil + +from src.ac.framework.ac_result import FAILED, WARNING, SUCCESS +from src.ac.acl.package_license.check_license import CheckLicense + +logging.getLogger('test_logger') + +class TestCheckPkgLicense(unittest.TestCase): + DIR_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), + "license_test_sample") + + TEST_SAMPLE_DIR = { + "no_spec": "no_spec", + "spec_success": "pkgship", + "spec_fail": "spec_fail", + "no_src": "no_src", + "src_success": "rubygem-mail", + "src_fail": "pkgship", + "spec_src_same": "rubygem-mail", + "spec_src_diff": "pkgship" + } + + def bind_func(self, check): + def get_work_tar_dir(self): + return self._work_tar_dir + def load_license_config(self): + self._pkg_license.load_config() + def decompress(self): + self._gr.decompress_all() + check.get_work_tar_dir = types.MethodType(get_work_tar_dir, check, CheckLicense) + check.load_license_config = types.MethodType(load_license_config, check, CheckLicense) + check.decompress = types.MethodType(decompress, check, CheckLicense) + + def _test_check_license_in_spec(self, dir_key, predict): + os.chdir(os.path.join(self.DIR_PATH, + self.TEST_SAMPLE_DIR[dir_key])) + cl = CheckLicense(self.DIR_PATH, + self.TEST_SAMPLE_DIR[dir_key]) + self.bind_func(cl) + cl.load_license_config() + self.assertEqual(cl.check_license_in_spec(), predict) + + def test_check_license_in_spec_none(self): + self._test_check_license_in_spec("no_spec", WARNING) + + def test_check_license_in_spec_succeed(self): + self._test_check_license_in_spec("spec_success", SUCCESS) + + def test_check_license_in_spec_failed(self): + self._test_check_license_in_spec("spec_fail", WARNING) + + def _test_check_license_in_src(self, dir_key, predict): + os.chdir(os.path.join(self.DIR_PATH, + self.TEST_SAMPLE_DIR[dir_key])) + cl = CheckLicense(self.DIR_PATH, + self.TEST_SAMPLE_DIR[dir_key]) + self.bind_func(cl) + _ = not os.path.exists(cl.get_work_tar_dir()) and os.mkdir(cl.get_work_tar_dir()) + try: + cl.decompress() + cl.load_license_config() + self.assertEqual(cl.check_license_in_src(), predict) + finally: + shutil.rmtree(cl.get_work_tar_dir()) + + def test_check_license_none(self): + self._test_check_license_in_src("no_src", WARNING) + + def test_check_license_in_src_succeed(self): + self._test_check_license_in_src("src_success", SUCCESS) + + def test_check_license_in_src_failed(self): + self._test_check_license_in_src("src_fail", WARNING) + + def _test_check_license_same(self, dir_key, predict): + os.chdir(os.path.join(self.DIR_PATH, + self.TEST_SAMPLE_DIR[dir_key])) + cl = CheckLicense(self.DIR_PATH, + self.TEST_SAMPLE_DIR[dir_key]) + self.bind_func(cl) + _ = not os.path.exists(cl.get_work_tar_dir()) and os.mkdir(cl.get_work_tar_dir()) + try: + cl.decompress() + cl.load_license_config() + cl.check_license_in_spec() + cl.check_license_in_src() + self.assertEqual(cl.check_license_is_same(), predict) + finally: + shutil.rmtree(cl.get_work_tar_dir()) + + def test_check_license_same_succeed(self): + self._test_check_license_same("spec_src_same", SUCCESS) + + def test_cehck_license_same_failed(self): + self._test_check_license_same("spec_src_diff", WARNING) + + +if __name__ == "__main__": + work_dir = os.getcwd() + _ = not os.path.exists("log") and os.mkdir("log") + logger_conf_path = os.path.realpath(os.path.join(os.path.dirname(os.path.realpath(__file__)), "../../../../src/conf/logger.conf")) + logging.config.fileConfig(logger_conf_path) + logger = logging.getLogger("test_logger") + # Test Package License + suite = unittest.makeSuite(TestCheckPkgLicense) + unittest.TextTestRunner().run(suite) + os.chdir(work_dir) + shutil.rmtree("log") \ No newline at end of file