diff --git a/advisors/psrtool.py b/advisors/psrtool.py new file mode 100755 index 0000000000000000000000000000000000000000..b41f99433f7a44a696b7cdb11f20ce12ac23c9f0 --- /dev/null +++ b/advisors/psrtool.py @@ -0,0 +1,96 @@ +#!/usr/bin/python +#****************************************************************************** +# 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: Love_hangzhou +# Create: 2020-07-05 +# ******************************************************************************/ +''' +This is a script used for query sigs infomation in openEuelr register in openeuler/community/sig/sigs.yaml +(1) This script depends on openuler/commnity/sig/sigs.yaml file, + suppose you clone commnuity and openEuler-Advisors in the same directory, + then you needn't specify the sigs.yaml path + +(2) Command parameters + -s Specify the sigs name,list the packages in the sigs + (eg:-s dev-utils) + -p Specify the packages name ,query the packages belong which sigs + (eg:-p mate-polkit ) + -l List all sigs in openEuler + -y yaml:sigs.yaml path in community repository's location of you clone + default is ../../community/sig/sigs.yaml +''' +import yaml +import sys +import argparse +import re +import os + +def list_packages_in_sig(sig_name = None,sigs = None): + if sig_name is None or sigs is None: + return None + for sig in sigs: + if sig['name'].lower() == sig_name.lower(): + return sig['repositories'] + +def pkg_2_sig(pkgname,sigs): + result = {} + for pkg in pkgname: + for sig in sigs: + repos = sig['repositories'] + for repo in repos: + seachObj=re.search(pkg.lower(),repo.lower(),0) + if seachObj: + result[repo]=sig['name'] + return result + +def list_sigs(sigs): + result = [] + for sig in sigs: + result.append(sig['name']) + return result + +def print_list(l): + for i in l: + print(i) + +def print_dict(d): + for key,value in d.items(): + print(key+": "+ value) + +if __name__ == "__main__": + default_sigs_yaml=os.path.join(sys.path[0],'../../community/sig/sigs.yaml') + + parser = argparse.ArgumentParser() + group = parser.add_mutually_exclusive_group(required=True) + group.add_argument('-s','--signame',nargs='?',help='List packages managed by the specific SIG') + group.add_argument('-p','--pkgs',nargs='+',help='Query which SIG manage the specific package') + group.add_argument('-l','--list',action='store_true',help='List all SIGS in openEuler') + parser.add_argument('-y','--yaml', nargs='?',default=default_sigs_yaml,help='''Local path of sigs.yaml file,default is ../../community/sig/sigs.yaml, +assume you clone Community repository with openEuler-Advisor in the same directory''') + + args=parser.parse_args() + + try: + with open(args.yaml,mode='r') as f: + data = yaml.load(f,Loader=yaml.SafeLoader) + input_sigs=data['sigs'] + except (IOError,TypeError): + print('Failed to load infomation from %s' %args.yaml) + parser.print_help() + exit(1) + + if args.list == True: + print_list(list_sigs(input_sigs)) + elif args.signame: + print_list(list_packages_in_sig(args.signame,input_sigs)) + elif args.pkgs: + print_dict(pkg_2_sig(args.pkgs,input_sigs)) +