diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000000000000000000000000000000000000..5247c9c89de142238014cd484da8dcdd96dabdbf --- /dev/null +++ b/AUTHORS @@ -0,0 +1,7 @@ +##gitee name +@shinwell_hu +@licihua +@leofang94 +@zengwefeng +@orange-snn +@shanshishi diff --git a/advisors/check_missing_specs.py b/advisors/check_missing_specs.py index 1340aec757acd0454c2952d2cda57c269040eb92..f29175aaa1aae581055f061d6158a3c8b24d11b1 100755 --- a/advisors/check_missing_specs.py +++ b/advisors/check_missing_specs.py @@ -5,11 +5,15 @@ If not, it can be used to push an issue to remind the developer. """ import argparse -import gitee -import urllib.error from datetime import datetime -new_issue_body = """Dear {repo} maintainer: +try: + import gitee +except ImportError as error: + from advisors import gitee + + +NEW_ISSUE_BODY = """Dear {repo} maintainer: 亲爱的 {repo} 维护者: We found there is no spec file in this repository's master branch yet. @@ -27,7 +31,7 @@ This is a automatic advise from openEuler-Advisor. If you think the advise is no Yours openEuler Advisor. """ -new_comment = """Dear {repo} maintainer: +NEW_COMMENT = """Dear {repo} maintainer: We found this issue has been open for {days} days. @@ -40,10 +44,15 @@ This is a automatic advise from openEuler-Advisor. If you think the advise is no Yours openEuler Advisor. """ -if __name__ == "__main__": + +def main(): + """ + Main entrance for command line + """ pars = argparse.ArgumentParser() pars.add_argument("repo", type=str, help="Repo to be checked") - pars.add_argument("-p", "--push", help="Push the advise to gitee.com/src-openeuler", action="store_true") + pars.add_argument("-p", "--push", help="Push the advise to gitee.com/src-openeuler", + action="store_true") args = pars.parse_args() @@ -61,16 +70,18 @@ if __name__ == "__main__": print("Advise has been issues only %d days ago" % ages.days) print("Give developers more time to handle it.") break - else: - my_gitee.post_issue_comment(args.repo, issue["number"], - new_comment.format(repo=args.repo, days=ages.days)) + my_gitee.post_issue_comment(args.repo, issue["number"], NEW_COMMENT.format( + repo=args.repo, days=ages.days)) break else: my_gitee.post_issue(args.repo, "Submit spec file into this repository", - new_issue_body.format(repo=args.repo)) + NEW_ISSUE_BODY.format(repo=args.repo)) else: print("Keep this between us.") else: print("Everything's fine") + +if __name__ == "__main__": + main() diff --git a/advisors/check_repeated_repo.py b/advisors/check_repeated_repo.py index 40267f7126ff0c39e8c8c93606698cbf1ec3da93..ff9f55508c2497083057575cdc1dbaeaa4afee1d 100755 --- a/advisors/check_repeated_repo.py +++ b/advisors/check_repeated_repo.py @@ -17,9 +17,12 @@ This is an automatic script for checking repo is repeated or not import argparse import os import sys - import yaml -import yaml2url + +try: + import yaml2url +except ImportError as error: + from advisors import yaml2url def get_url(repo_file): diff --git a/advisors/check_source_url.py b/advisors/check_source_url.py index 4a2510b45b4e3ab7c70dbe3b4f73de72af26b8a2..0d807faa801f0760c8b0b24e9ac60b88e0f577b8 100755 --- a/advisors/check_source_url.py +++ b/advisors/check_source_url.py @@ -15,16 +15,34 @@ This is an automatic script for checking source url of package """ -from pyrpm.spec import Spec, replace_macros -import argparse -import gitee import os import re import sys -import yaml +import math import subprocess import threading -import math +import argparse +import yaml +from pyrpm.spec import Spec, replace_macros + +try: + import gitee +except ImportError as error: + from advisors import gitee + + +BODY_SOURCE = """Dear Maintainer: + Due to source url problem checked by openEuler-Advisor, please solve it as soon as + possible and check other branch too. + If any problem, please create issue in https://gitee.com/openeuler/openEuler-Advisor. + Thanks. + Yours openEuler-Advisor""" +BODY_SPEC = """Dear Maintainer: + Due to spec can't be found by openEuler-Advisor, please add it as soon as possible + and check other branch too. + If any problem, please create issue in https://gitee.com/openeuler/openEuler-Advisor. + Thanks. + Yours openEuler-Advisor""" def check_repo(repo, branch, batch_num): @@ -32,8 +50,8 @@ def check_repo(repo, branch, batch_num): Check source url of multi-packages in repo like src-openeuler. batch_num is batch num of one thread """ - gt = gitee.Gitee() - repo_info = gt.get_community(repo) + user_gitee = gitee.Gitee() + repo_info = user_gitee.get_community(repo) if not repo_info: print("WARNING: {repo}.yaml can't be found in community.".format(repo=repo)) sys.exit(1) @@ -43,12 +61,13 @@ def check_repo(repo, branch, batch_num): threads = [] lock = threading.Lock() for number in range(thread_num): - thread= threading.Thread(target=check_batch, args=(repo_list, branch, number, batch_num, lock)) + thread= threading.Thread(target=check_batch, args=(repo_list, branch, number, + batch_num, lock)) threads.append(thread) - for t in threads: - t.start() - for t in threads: - t.join() + for thread in threads: + thread.start() + for thread in threads: + thread.join() print("Ending check.") @@ -56,146 +75,100 @@ def create_issue(repo, title, body): """ Create issue for repo """ - gt = gitee.Gitee() + user_gitee = gitee.Gitee() created_issue = False - issues = gt.get_issues(repo) + issues = user_gitee.get_issues(repo) for issue in issues: if issue["title"] == title: created_issue = True break if not created_issue: - gt.post_issue(repo, title, body) + user_gitee.post_issue(repo, title, body) def check_batch(repo_list, branch, number, batch_num, lock): """ Check source url in one batch """ - gt = gitee.Gitee() - body_source = """Dear Maintainer: - Due to source url problem checked by openEuler-Advisor, please solve it as soon as - possible and check other branch too. - If any problem, please create issue in https://gitee.com/openeuler/openEuler-Advisor. - Thanks. - Yours openEuler-Advisor""" - body_spec = """Dear Maintainer: - Due to spec can't be found by openEuler-Advisor, please add it as soon as possible - and check other branch too. - If any problem, please create issue in https://gitee.com/openeuler/openEuler-Advisor. - Thanks. - Yours openEuler-Advisor""" file_str = "result_" + "{num}.log".format(num=number) - file_name = open(file_str, "w+") - for n in range(batch_num): - index = number * batch_num + n + batch_file = open(file_str, "w+") + for batch_index in range(batch_num): + index = number * batch_num + batch_index if index < len(repo_list): repo_name = repo_list[index].get("name") else: break - file_name.writelines("\n-----------------------Checking {repo}-----------------------".format(repo=repo_name)) - lock.acquire() - spec_str = gt.get_spec(repo_name, branch) - lock.release() - if not spec_str: - file_name.writelines("WARNING: {repo}.spec can't be found on {br}".format(repo=repo_name, br=branch)) - title = "Submit spec file into this repository" - ####create_issue(repo_name, title, body_spec) - continue - - repo_spec = Spec.from_string(spec_str) - if repo_spec.sources_dict: - source = replace_macros(repo_spec.sources[0], repo_spec) - else: - title = "Source url can't be found in spec on {br}".format(br=branch) - file_name.writelines("WARNING: {content}".format(content=title)) - create_issue(repo_name, title, body_source) - continue - - if re.search(r"%{.*?}", source): - title = "Source url can't be parsed with extra macros in spec on {br}.".format(br=branch) - file_name.writelines("WARNING: {content}".format(content=title)) - create_issue(repo_name, title, body_source) - continue - elif source.startswith("http") or source.startswith("ftp"): - fn = os.path.basename(source) - n = 0 - lock.acquire() - while n < 2: - n += 1 - if subprocess.call(["curl -m 600 -L {url} -o {name}".format(url=source, name=fn)], shell=True): - continue - else: - break - lock.release() - title = "Source url may be wrong in spec on {br}.".format(br=branch) - if os.path.exists(fn): - if subprocess.call(["tar -tvf {file_name} &>/dev/null".format(file_name=fn)], shell=True): - file_name.writelines("WARNING: {content}".format(content=title)) - create_issue(repo_name, title, body_source) - else: - file_name.writelines("Check successfully.") - subprocess.call(["rm -rf {file_name}".format(file_name=fn)], shell=True) - else: - file_name.writelines("WARNING: {content}".format(content=title)) - create_issue(repo_name, title, body_source) - else: - title = "Source url is invalid in spec on {br}.".format(br=branch) - file_name.writelines("WARNING: {content}".format(content=title)) - create_issue(repo_name, title, body_source) - continue + check_pkg(repo_name, branch, batch_file, lock) -def check_pkg(pkg, branch): + +def check_pkg(pkg, branch, check_file, lock): """ Check source url of single package """ - gt = gitee.Gitee() - print("\n-----------------------Checking {repo}-----------------------".format(repo=pkg)) - spec_str = gt.get_spec(pkg, branch) + user_gitee = gitee.Gitee() + check_file.writelines("\n-----------------------Checking {}-----------------------".format( + pkg)) + lock.acquire() + spec_str = user_gitee.get_spec(pkg, branch) + lock.acquire() if not spec_str: - print("WARNING: {repo}.spec can't be found on {branch}".format(repo=pkg, branch=branch)) - created_issue = False - issues = gt.get_issues(pkg) - for issue in issues: - if issue["title"] == "Submit spec file into this repository": - created_issue = True - break - if not created_issue: - title = "Submit spec file into this repository" - print(title) - sys.exit(1) + check_file.writelines("WARNING: {repo}.spec can't be found on {br}".format(repo=pkg, + br=branch)) + return False + repo_spec = Spec.from_string(spec_str) if repo_spec.sources_dict: source = replace_macros(repo_spec.sources[0], repo_spec) else: - print("No source url") - sys.exit(1) + title = "Source url can't be found in spec on {br}".format(br=branch) + check_file.writelines("WARNING: {content}".format(content=title)) + create_issue(pkg, title, BODY_SOURCE) + return False + if re.search(r"%{.*?}", source): - print("WARNING: Extra macros in source url which failed to be expanded.") - sys.exit(1) - elif source.startswith("http") or source.startswith("ftp"): - fn = os.path.basename(source) - n = 0 - while n < 2: - n += 1 - if subprocess.call(["curl -m 600 -L {url} -o {name}".format(url=source, name=fn)], shell=True): - continue - else: + title = "Source url can't be parsed with extra macros in spec on {}.".format(branch) + check_file.writelines("WARNING: {content}".format(content=title)) + create_issue(pkg, title, BODY_SOURCE) + return False + + if source.startswith("http") or source.startswith("ftp"): + file_name = os.path.basename(source) + down_cnt = 0 + lock.acquire() + while down_cnt < 2: + down_cnt += 1 + if not subprocess.call(["timeout 15m wget -c {url} -O {name}".format(url=source, + name=file_name)], shell=True): break + lock.release() - if os.path.exists(fn): - if subprocess.call(["tar -tvf {file_name} &>/dev/null".format(file_name=fn)], shell=True): - print("WARNING: source url of {repo} may be wrong.".format(repo=pkg)) + title = "Source url may be wrong in spec on {br}.".format(br=branch) + if os.path.exists(file_name): + if subprocess.call(["tar -tvf {} &>/dev/null".format(file_name)], shell=True): + check_file.writelines("WARNING: {content}".format(content=title)) + create_issue(pkg, title, BODY_SOURCE) + result = False else: - print("Check successfully.") + check_file.writelines("Check successfully.") + result = True + subprocess.call(["rm -rf {}".format(file_name)], shell=True) else: - print("WARNING: source url of {repo} may be wrong.".format(repo=pkg)) - else: - print("WARNING: Not valid URL for Source code.") - sys.exit(1) + check_file.writelines("WARNING: {content}".format(content=title)) + create_issue(pkg, title, BODY_SOURCE) + result = False + return result + title = "Source url is invalid in spec on {br}.".format(br=branch) + check_file.writelines("WARNING: {content}".format(content=title)) + create_issue(pkg, title, BODY_SOURCE) + return False -if __name__ == "__main__": + +def main(): + """ + Main entrance for command line + """ pars = argparse.ArgumentParser() pars.add_argument("-r", "--repo", type=str, help="The repository to be check.") pars.add_argument("-p", "--pkg", type=str, help="The package to be check.") @@ -206,7 +179,13 @@ if __name__ == "__main__": if args.repo: check_repo(args.repo, args.branch, args.batch_num) elif args.pkg: - check_pkg(args.pkg, args.branch) + check_file = open("check_repo.log", "w") + lock = threading.Lock() + check_pkg(args.pkg, args.branch, check_file, lock) else: print("WARNING: Please specify what to be checkd.") sys.exit(1) + + +if __name__ == "__main__": + main() diff --git a/advisors/check_upstream.py b/advisors/check_upstream.py index f3950f28c7b402f35a5b1c65b0c196375b7d26bc..e24b50cbd7c6dc2f6404f76c6ec4defb9e87a6d9 100755 --- a/advisors/check_upstream.py +++ b/advisors/check_upstream.py @@ -4,23 +4,25 @@ This modules containers methods to check upstream version info """ import re import sys +import json import subprocess from datetime import datetime - -#import http.cookiejar -#import urllib.request -#import yaml -import json from urllib.parse import urljoin import requests -import yaml2url + +try: + import yaml2url +except ImportError as error: + from advisors import yaml2url TIME_FORMAT = "%Y-%m-%dT%H:%M:%S%z" + def eprint(*args, **kwargs): """Helper for debug print""" print("DEBUG: ", *args, file=sys.stderr, **kwargs) + def load_last_query_result(info, force_reload=False): """ If there's last_query stored in yaml, load it @@ -98,6 +100,7 @@ def dirty_redirect_tricks(url, resp): cookie.remove("") return need_trick, new_url, list(cookie) + def check_hg_raw(info, clean_tag=True): """ Check hg version info via raw-tags @@ -259,6 +262,7 @@ def check_rubygem(info, clean_tag=True): tags = clean_tags(tags, info) return tags + def __check_subprocess(cmd_list): """ Helper to start and check subprocess result @@ -301,6 +305,7 @@ def __svn_resp_to_tags(resp): break return tags + def __git_resp_to_tags(resp): """ Helpers to convert git response to tags @@ -315,6 +320,7 @@ def __git_resp_to_tags(resp): tags.append(tag) return tags + def check_git(info, clean_tag=True): """ Check version info via git command @@ -331,9 +337,9 @@ def check_git(info, clean_tag=True): tags = __git_resp_to_tags(resp) if clean_tag: tags = clean_tags(tags, info) - return tags + def check_github(info, clean_tag=True): """ Check version info via github api @@ -357,6 +363,7 @@ def check_github(info, clean_tag=True): tags = clean_tags(tags, info) return tags + def check_gnu_ftp(info, clean_tag=True): """ Check version info via compare ftp release tar file for gnu @@ -378,6 +385,7 @@ def check_gnu_ftp(info, clean_tag=True): tags = clean_tags(tags, info) return tags + def check_ftp(info, clean_tag=True): """ Check version info via compare ftp release tar file @@ -399,6 +407,7 @@ def check_ftp(info, clean_tag=True): tags = clean_tags(tags, info) return tags + def check_gnome(info, clean_tag=True): """ Check version info via gitlab.gnome.org api @@ -418,6 +427,7 @@ def check_gnome(info, clean_tag=True): tags = clean_tags(tags, info) return tags + def check_gitee(info, clean_tag=True): """ Check version info via gitee @@ -436,6 +446,7 @@ def check_gitee(info, clean_tag=True): tags = clean_tags(tags, info) return tags + def check_svn(info, clean_tag=True): """ Check version info via svn diff --git a/advisors/create_repo.py b/advisors/create_repo.py index 01030a22aeb9ed6d0a161faa41d9face9327c965..904693d6fd1f6120a70b60f2068bbb2be1c9a425 100755 --- a/advisors/create_repo.py +++ b/advisors/create_repo.py @@ -3,12 +3,15 @@ This is a command line tool for adding new repo """ +import sys import argparse import yaml -import sys -if __name__ == "__main__": +def main(): + """ + Main entrance for command line + """ par = argparse.ArgumentParser() par.add_argument("-r", "--repo", help="YAML file for repositories", type=str, required=True) par.add_argument("-i", "--sigs", help="YAML file for sigs", type=str, required=True) @@ -19,26 +22,24 @@ if __name__ == "__main__": args = par.parse_args() - f = open(args.sigs) - sigs = yaml.load(f.read(), Loader=yaml.Loader) - if not sigs: - print("Failed to load {file}".format(file=args.sigs)) - sys.exit(1) - f.close() + with open(args.sigs) as sigs_file: + sigs = yaml.load(sigs_file.read(), Loader=yaml.Loader) + if not sigs: + print("Failed to load {file}".format(file=args.sigs)) + sys.exit(1) - f = open(args.repo) - repo = yaml.load(f.read(), Loader=yaml.Loader) - if not repo: - print("Failed to load {file}".format(file=args.repo)) - sys.exit(1) - f.close() + with open(args.repo) as repo_file: + repo = yaml.load(repo_file.read(), Loader=yaml.Loader) + if not repo: + print("Failed to load {file}".format(file=args.repo)) + sys.exit(1) - nr = {} - nr["name"] = args.name - nr["description"] = args.desc - nr["upstream"] = args.upstream - nr["protected_branches"] = ["master"] - nr["type"] = "public" + repo_info = {} + repo_info["name"] = args.name + repo_info["description"] = args.desc + repo_info["upstream"] = args.upstream + repo_info["protected_branches"] = ["master"] + repo_info["type"] = "public" exist = [x for x in repo["repositories"] if x["name"] == args.name] if exist != []: @@ -46,28 +47,30 @@ if __name__ == "__main__": sys.exit(1) if repo["community"] == "openeuler": - repo["repositories"].append(nr) + repo["repositories"].append(repo_info) elif repo["community"] == "src-openeuler": - nr["upstream"] = args.upstream - repo["repositories"].append(nr) + repo_info["upstream"] = args.upstream + repo["repositories"].append(repo_info) repo["repositories"].sort(key=lambda r: r["name"]) valid_sig = False - for s in sigs["sigs"]: - if s["name"] == args.sig: - s["repositories"].append(repo["community"] + "/" + args.name) - s["repositories"].sort() + for sig in sigs["sigs"]: + if sig["name"] == args.sig: + sig["repositories"].append(repo["community"] + "/" + args.name) + sig["repositories"].sort() valid_sig=True continue if valid_sig: - f = open(args.repo, "w") - yaml.dump(repo, f) - f.close() - f = open(args.sigs, "w") - yaml.dump(sigs, f) - f.close() + with open(args.repo, "w") as repo_file: + yaml.dump(repo, repo_file) + with open(args.sigs, "w") as sigs_file: + yaml.dump(sigs, sigs_file) else: print("SIG name is not valid") sys.exit(1) + + +if __name__ == "__main__": + main() diff --git a/advisors/create_repo_with_srpm b/advisors/create_repo_with_srpm.py similarity index 41% rename from advisors/create_repo_with_srpm rename to advisors/create_repo_with_srpm.py index 1eccf8728d9ff8dd29f0890a7d98b83a5ae16c1a..26b861fbc6f2d93474b4f6616422c8f436e8cb68 100755 --- a/advisors/create_repo_with_srpm +++ b/advisors/create_repo_with_srpm.py @@ -3,108 +3,121 @@ This is a command line tool for adding new repo """ -import argparse -import yaml -import sys from os import path +import sys +import argparse import subprocess +import yaml + def get_info(pkg): - nr = {} + """ + Get package rpm information + """ + pkg_info = {} proc = subprocess.Popen(["rpm", "-qpi", pkg], stdout=subprocess.PIPE) - while (True): + while True: line = proc.stdout.readline() if not line: - break; + break info = str(line.strip().decode()).split(':') - if (len(info) < 2): + if len(info) < 2: continue info[0] = info[0].strip() info[1] = info[1].strip() - if (info[0] == "Name"): - nr["name"] = info[1] - elif (info[0] == "Summary"): - nr["description"] = info[1] - elif (info[0] == "URL"): - if (len(info) >= 3): - nr["upstream"] = info[1] + ":" + info[2] + if info[0] == "Name": + pkg_info["name"] = info[1] + elif info[0] == "Summary": + pkg_info["description"] = info[1] + elif info[0] == "URL": + if len(info) >= 3: + pkg_info["upstream"] = info[1] + ":" + info[2] else: - nr["upstream"] = info[1] - + pkg_info["upstream"] = info[1] proc.stdout.close() proc.wait() + return pkg_info - return nr -if __name__ == "__main__": +def check_repo(repo): + """ + Check the condition for repo create + """ + if path.exists(repo) and path.isfile(repo): + pkg_info = get_info(repo) + if len(pkg_info) < 3: + print("Failed to parse the output of rpm -qpi {pkg}".format(pkg=repo)) + sys.exit(1) + else: + print("%s does not exist\n" & repo) + sys.exit(1) + + +def main(): + """ + Main entrance for command line + """ par = argparse.ArgumentParser() par.add_argument("-r", "--repo", help="YAML file for repositories", type=str, required=True) par.add_argument("-i", "--sigs", help="YAML file for sigs", type=str, required=True) - par.add_argument("-s", "--sig", help="The SIG which contains the package", type=str, required=True) + par.add_argument("-s", "--sig", help="The SIG which contains the package", + type=str, required=True) par.add_argument("-p", "--pkg", help="Package for upoad", type=str, required=True) - args = par.parse_args() - nr = {} - if (path.exists(args.pkg) and path.isfile(args.pkg)): - nr = get_info(args.pkg) - if (len(nr) < 3): - print("Failed to parse the output of rpm -qpi {pkg}".format(pkg=args.pkg)) - sys.exit(1) - else: - print("%s does not exist\n" & args.pkg) - sys.exit(1) + pkg_info = {} - f = open(args.sigs) - sigs = yaml.load(f.read(), Loader=yaml.Loader) - if not sigs: - print("Failed to load {file}".format(file=args.sigs)) - sys.exit(1) - f.close() + check_repo(args.pkg) - f = open(args.repo) - repo = yaml.load(f.read(), Loader=yaml.Loader) - if not repo: - print("Failed to load {file}".format(file=args.repo)) - sys.exit(1) - f.close() + with open(args.sigs) as sigs_file: + sigs = yaml.load(sigs_file.read(), Loader=yaml.Loader) + if not sigs: + print("Failed to load {file}".format(file=args.sigs)) + sys.exit(1) - nr["protected_branches"] = ["master"] - nr["type"] = "public" + with open(args.repo) as repo_file: + repo = yaml.load(repo_file.read(), Loader=yaml.Loader) + if not repo: + print("Failed to load {file}".format(file=args.repo)) + sys.exit(1) + + pkg_info["protected_branches"] = ["master"] + pkg_info["type"] = "public" - exist = [x for x in repo["repositories"] if x["name"] == nr["name"]] + exist = [x for x in repo["repositories"] if x["name"] == pkg_info["name"]] if exist != []: print("Repo already exist") sys.exit(1) if repo["community"] == "openeuler": - del nr["upstream"] - repo["repositories"].append(nr) + del pkg_info["upstream"] + repo["repositories"].append(pkg_info) elif repo["community"] == "src-openeuler": - repo["repositories"].append(nr) + repo["repositories"].append(pkg_info) repo["repositories"].sort(key=lambda r: r["name"]) valid_sig = False - for s in sigs["sigs"]: - if s["name"] == args.sig: - s["repositories"].append(repo["community"] + "/" + nr["name"]) - s["repositories"].sort() + for sig in sigs["sigs"]: + if sig["name"] == args.sig: + sig["repositories"].append(repo["community"] + "/" + pkg_info["name"]) + sig["repositories"].sort() valid_sig=True continue if valid_sig: - f = open(args.repo, "w") - yaml.dump(repo, f, sort_keys=False) - f.close() - f = open(args.sigs, "w") - yaml.dump(sigs, f, sort_keys=False) - f.close() + with open(args.repo, "w") as repo_file: + yaml.dump(repo, repo_file, sort_keys=False) + with open(args.sigs, "w") as sigs_file: + yaml.dump(sigs, sigs_file, sort_keys=False) else: print("SIG name is not valid") sys.exit(1) - - print("create repo %s successfully\n" % nr["name"]) + print("create repo %s successfully\n" % pkg_info["name"]) sys.exit(0) + + +if __name__ == "__main__": + main() diff --git a/advisors/match_patches.py b/advisors/match_patches.py index cae427fb90bcbb484cd9c6987e5480b09f8be83c..10e3a7f586a702bc2de5d11335733ba76993d1bc 100755 --- a/advisors/match_patches.py +++ b/advisors/match_patches.py @@ -22,10 +22,16 @@ import argparse import subprocess import yaml -import gitee -import yaml2url -import oa_upgradable -import simple_update_robot +try: + import gitee + import yaml2url + import oa_upgradable + import simple_update_robot +except ImportError as error: + from advisors import gitee + from advisors import yaml2url + from advisors import oa_upgradable + from advisors import simple_update_robot def _clone_repo(pkg_info): @@ -132,7 +138,10 @@ def patches_match(gt_api, pkg, c_ver, u_ver): return patch_match -if __name__ == "__main__": +def main(): + """ + Main entrance for command line + """ pars = argparse.ArgumentParser() pars.add_argument("pkg", type=str, help="The package to be matched.") pars.add_argument("branch", type=str, help="Branch to be matched.") @@ -145,3 +154,7 @@ if __name__ == "__main__": os.chdir(args.pkg) patches_match(user_gitee, args.pkg, args.cur_ver, args.up_ver) os.chdir(os.pardir) + + +if __name__ == "__main__": + main() diff --git a/advisors/oa_upgradable.py b/advisors/oa_upgradable.py index 286fff80a4740a7770aded087f56ad132ade0147..8e21153a1c2a61f428a607a3ad3cb6e0dd09c241 100755 --- a/advisors/oa_upgradable.py +++ b/advisors/oa_upgradable.py @@ -19,11 +19,16 @@ import sys import argparse import re from pyrpm.spec import Spec, replace_macros - import yaml -import gitee -import check_upstream -import version_recommend + +try: + import gitee + import check_upstream + import version_recommend +except ImportError as error: + from advisors import gitee + from advisors import check_upstream + from advisors import version_recommend def _filter_except(excpts, sources): diff --git a/advisors/psrtool.py b/advisors/psrtool.py index 84dcbd17d99062e65c3b33bfda68d3acddf8383d..7f6c2015627e4390448952395cfe6448aa7855f0 100755 --- a/advisors/psrtool.py +++ b/advisors/psrtool.py @@ -17,9 +17,11 @@ This script was inspired by previous work from @love_hangzhou """ import re +import sys import argparse import yaml + def list_packages(sigs, sig_name): """ List all packages managed by specific SIG @@ -92,7 +94,7 @@ def main(): except IOError: print("Failed to load information from %s" % args.yaml) parser.print_help() - exit(1) + sys.exit(1) if args.list: print_list(list_packages(sigs, args.list)) @@ -102,7 +104,7 @@ def main(): print_dict(package_to_sigs(sigs, args.query_packages)) else: pass - exit(0) + if __name__ == "__main__": main() diff --git a/advisors/review_tool.py b/advisors/review_tool.py index 9e9839525a9e15fa33f9c7ad90feb2b210151bbb..b340789f3b0002f469a57c4a0fdc1a974c982391 100755 --- a/advisors/review_tool.py +++ b/advisors/review_tool.py @@ -20,7 +20,12 @@ import argparse import subprocess import shutil import yaml -import gitee + +try: + import gitee +except ImportError as error: + from advisors import gitee + CHK_TABLE_HEADER = """ **以下为 openEuler-Advisor 的 review_tool 生成审视要求清单** @@ -81,8 +86,8 @@ def load_checklist(chklist_path): load configuration """ try: - with open(chklist_path, 'r', encoding = 'utf-8') as f: - return yaml.load(f.read(), Loader = yaml.Loader) + with open(chklist_path, 'r', encoding = 'utf-8') as check_file: + return yaml.load(check_file.read(), Loader = yaml.Loader) except OSError as reason: print("Load yaml failed!" + str(reason)) return None @@ -108,6 +113,7 @@ def check_repository_changes(): return True return False + def check_repository_mgmt_changes(sigs, info): """ Return additional checking item if management of repository has been changed @@ -277,7 +283,6 @@ def review(pull_request, repo_name, chklist_path): """ Return check list of this PR """ - if not pull_request["mergeable"]: return "PR中存在冲突,无法自动合并。需要先解决冲突,才可以开展评审。" @@ -359,5 +364,6 @@ def main(): user_gitee.create_pr_comment(repo_name, args.pull, review_comment, group) + if __name__ == "__main__": main() diff --git a/advisors/simple_update_robot.py b/advisors/simple_update_robot.py index b7e18c39f8d90a260a5cbafabd452fae78fcec34..06d0563cc2f17569d6cdae6670e9397e6e40cfac 100755 --- a/advisors/simple_update_robot.py +++ b/advisors/simple_update_robot.py @@ -35,10 +35,16 @@ import subprocess import yaml from pyrpm.spec import Spec, replace_macros -import gitee -import oa_upgradable -import version_recommend -import match_patches +try: + import gitee + import oa_upgradable + import version_recommend + import match_patches +except ImportError as error: + from advisors import gitee + from advisors import oa_upgradable + from advisors import version_recommend + from advisors import match_patches def download_source_url(pkg, spec, o_ver, n_ver): @@ -192,10 +198,11 @@ def modify_patch(repo, pkg_spec, patch_match): os.chdir(os.pardir) -def create_spec(repo, spec_str, o_ver, n_ver, src_fn=None): +def create_spec(gt_api, repo, spec_str, o_ver, n_ver): """ Create new spec file for upgraded package """ + pkg_spec = Spec.from_string(spec_str) os.rename("{}.spec".format(repo), "{}-old.spec".format(repo)) file_spec = open(repo + ".spec", "w") in_changelog = False @@ -204,10 +211,7 @@ def create_spec(repo, spec_str, o_ver, n_ver, src_fn=None): file_spec.write(re.sub(r"\d+", "1", line) + "\n") continue if line.startswith("Source:") or line.startswith("Source0:"): - if src_fn: - file_spec.write("Source: {src_fn}\n".format(src_fn=src_fn).replace(o_ver, n_ver)) - else: - file_spec.write(line.replace(o_ver, n_ver) + "\n") + file_spec.write(line.replace(o_ver, n_ver) + "\n") continue if not in_changelog: line = line.replace(o_ver, n_ver) @@ -223,6 +227,13 @@ def create_spec(repo, spec_str, o_ver, n_ver, src_fn=None): file_spec.close() os.chdir(os.pardir) + if len(pkg_spec.patches) >= 1: + os.chdir(repo) + patch_match = match_patches.patches_match(gt_api, repo, o_ver, n_ver) + os.chdir(os.pardir) + if patch_match is not None: + modify_patch(repo, pkg_spec, patch_match) + def build_pkg(u_pkg, u_branch): """ @@ -315,14 +326,7 @@ def auto_update_pkg(gt_api, u_pkg, u_branch, u_ver=None): if not download_src(gt_api, u_pkg, pkg_spec, pkg_ver, u_ver): return - create_spec(u_pkg, spec_str, pkg_ver, u_ver) - - if len(pkg_spec.patches) >= 1: - os.chdir(u_pkg) - patch_match = match_patches.patches_match(gt_api, u_pkg, pkg_ver, u_ver) - os.chdir(os.pardir) - if patch_match is not None: - modify_patch(u_pkg, pkg_spec, patch_match) + create_spec(gt_api, u_pkg, spec_str, pkg_ver, u_ver) if not build_pkg(u_pkg, u_branch): return @@ -352,7 +356,49 @@ def auto_update_repo(gt_api, u_repo, u_branch): auto_update_pkg(gt_api, pkg_name, u_branch, u_ver) -if __name__ == "__main__": +def __manual_operate(gt_api, op_args): + """ + Manual operation of this module + """ + spec_string = gt_api.get_spec(op_args.repo_pkg, op_args.branch) + if not spec_string: + print("WARNING: {pkg}.spec can't be found on the {br} branch.".format( + pkg=op_args.repo_pkg, br=op_args.branch)) + sys.exit(1) + spec_file = Spec.from_string(spec_string) + cur_version = replace_macros(spec_file.version, spec_file) + + if op_args.fork_then_clone: + fork_clone_repo(gt_api, op_args.repo_pkg, op_args.branch) + + if op_args.download or op_args.create_spec or op_args.push_create_pr_issue: + if not op_args.new_version: + print("Please specify the upgraded version of the {}".format(op_args.repo_pkg)) + sys.exit(1) + elif not update_ver_check(op_args.repo_pkg, cur_version, op_args.new_version): + sys.exit(1) + + if op_args.download: + if not download_src(gt_api, op_args.repo_pkg, spec_file, cur_version, + op_args.new_version): + sys.exit(1) + + if op_args.create_spec: + create_spec(gt_api, op_args.repo_pkg, spec_string, cur_version, op_args.new_version) + + if op_args.build_pkg: + if not build_pkg(op_args.u_repo_pkg, op_args.u_branch): + sys.exit(1) + + if op_args.push_create_pr_issue: + push_create_pr_issue(gt_api, op_args.repo_pkg, cur_version, op_args.new_version, + op_args.branch) + + +def main(): + """ + Main entrance for command line + """ pars = argparse.ArgumentParser() pars.add_argument("repo_pkg", type=str, help="The repository or package to be upgraded") pars.add_argument("branch", type=str, help="The branch that upgrade based") @@ -376,40 +422,8 @@ if __name__ == "__main__": else: auto_update_pkg(user_gitee, args.repo_pkg, args.branch, args.new_version) else: - spec_string = user_gitee.get_spec(args.repo_pkg, args.branch) - if not spec_string: - print("WARNING: {pkg}.spec can't be found on the {br} branch.".format( - pkg=args.repo_pkg, br=args.branch)) - sys.exit(1) - spec_file = Spec.from_string(spec_string) - cur_version = replace_macros(spec_file.version, spec_file) - - if args.fork_then_clone: - fork_clone_repo(user_gitee, args.repo_pkg, args.branch) - - if args.download or args.create_spec or args.push_create_pr_issue: - if not args.new_version: - print("Please specify the upgraded version of the {}".format(args.repo_pkg)) - sys.exit(1) - elif not update_ver_check(args.repo_pkg, cur_version, args.new_version): - sys.exit(1) - - if args.download: - if not download_src(user_gitee, args.repo_pkg, spec_file, cur_version, - args.new_version): - sys.exit(1) + __manual_operate(user_gitee, args) - if args.create_spec: - create_spec(args.repo_pkg, spec_string, cur_version, args.new_version) - if len(spec_file.patches) >= 1: - print("WARNING: {} has multiple patches, please analyse it.".format(args.repo_pkg)) - sys.exit(1) - - if args.build_pkg: - if not build_pkg(args.repo_pkg, args.branch): - sys.exit(1) - - if args.push_create_pr_issue: - push_create_pr_issue(user_gitee, args.repo_pkg, cur_version, args.new_version, - args.branch) +if __name__ == "__main__": + main() diff --git a/advisors/tc_reminder.py b/advisors/tc_reminder.py index 1c76f68aab91df38b9168c853335d169fb5a6038..f742cc1ad7259222fbc606f4b304f7403fad6683 100755 --- a/advisors/tc_reminder.py +++ b/advisors/tc_reminder.py @@ -3,16 +3,15 @@ This is a command line tool to create reminder list for TC member """ +import os +import json +import argparse import urllib import urllib.request import urllib.parse -import argparse -import json -import sys -import os -import yaml -from pprint import pprint from datetime import datetime +import yaml + class Advisor(object): """ @@ -21,7 +20,8 @@ class Advisor(object): def __init__(self): self.secret = open(os.path.expanduser("~/.gitee_personal_token.json"), "r") self.token = json.load(self.secret) - self.header = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0"} + self.header = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64; rv:50.0) "\ + "Gecko/20100101 Firefox/50.0"} self.tc_members = None self.time_format = "%Y-%m-%dT%H:%M:%S%z" @@ -31,12 +31,9 @@ class Advisor(object): """ headers = self.header.copy() headers["Content-Type"] = "application/json;charset=UTF-8" - req = urllib.request.Request(url = url, - headers = headers, - method = "GET") - - with urllib.request.urlopen(req) as u: - resp = json.loads(u.read().decode("utf-8")) + req = urllib.request.Request(url = url, headers = headers, method = "GET") + with urllib.request.urlopen(req) as result: + resp = json.loads(result.read().decode("utf-8")) return resp def get_file(self, repo, path): @@ -44,13 +41,9 @@ class Advisor(object): Get remote raw file """ url = "https://gitee.com/{repo}/raw/master/{path}".format(repo=repo, path=path) - req = urllib.request.Request(url = url, - headers = self.header, - method = "GET") - - with urllib.request.urlopen(req) as u: - resp = u.read() - + req = urllib.request.Request(url = url, headers = self.header, method = "GET") + with urllib.request.urlopen(req) as result: + resp = result.read() return resp def get_prs(self): @@ -58,7 +51,8 @@ class Advisor(object): Get list of PRs """ pulls_url = "https://gitee.com/api/v5/repos/openeuler/community/pulls" - list_url = pulls_url + "?access_token={token}&state=open&sort=created&direction=desc&page=1&per_page=100" + list_url = pulls_url + "?access_token={token}&state=open&sort=created&"\ + "direction=desc&page=1&per_page=100" url = list_url.format(token=self.token["access_token"]) return self.get_json(url) @@ -75,9 +69,10 @@ class Advisor(object): """ Get list of current TC members """ - m = yaml.load(adv.get_file("openeuler/community", "sig/TC/OWNERS"), Loader=yaml.Loader) - self.tc_members = m["maintainers"] - return m["maintainers"] + owners = yaml.load(self.get_file("openeuler/community", "sig/TC/OWNERS"), + Loader=yaml.Loader) + self.tc_members = owners["maintainers"] + return owners["maintainers"] def filter_out_tc(self, users): """ @@ -86,45 +81,49 @@ class Advisor(object): if not self.tc_members: self.get_tc_members() return [x for x in self.tc_members if x in users] - - -if __name__ == "__main__": - par = argparse.ArgumentParser() + +def main(): + """ + Main entrance of the functionality + """ + par = argparse.ArgumentParser() args = par.parse_args() - adv = Advisor() - PRs = adv.get_prs() - PRs.reverse() - for pr in PRs: + advisor = Advisor() + pr_list = advisor.get_prs() + pr_list.reverse() + for preq in pr_list: commenters = [] - commenters.append(pr["user"]["login"]) - last_update = pr["updated_at"] - print("URL: https://gitee.com/openeuler/community/pulls/{number}".format(number=pr["number"])) - print("Title: " + pr["title"]) - comments = adv.get_pr_comments(pr["number"]) - last_update = datetime.strptime(comments[0]["updated_at"], adv.time_format) + commenters.append(preq["user"]["login"]) + last_update = preq["updated_at"] + print("URL: https://gitee.com/openeuler/community/pulls/{}".format(preq["number"])) + print("Title: " + preq["title"]) + comments = advisor.get_pr_comments(preq["number"]) + last_update = datetime.strptime(comments[0]["updated_at"], advisor.time_format) comments.reverse() current_lgtm = 0 current_approve = False for comment in comments: - commenters.append(comment["user"]["login"]) + commenters.append(comment["user"]["login"]) if comment["body"].startswith("new changes are detected"): - last_update = datetime.strptime(comment["updated_at"], adv.time_format) + last_update = datetime.strptime(comment["updated_at"], advisor.time_format) break # older comments are ignored - elif comment["body"].startswith("***lgtm*** is added in this pull request"): + if comment["body"].startswith("***lgtm*** is added in this pull request"): current_lgtm = current_lgtm + 1 elif comment["body"].startswith("***approved*** is added in this pull request"): current_approve = True - tc = adv.filter_out_tc(commenters) + tc_member = advisor.filter_out_tc(commenters) age = datetime.now() - last_update.replace(tzinfo=None) age_days = max(age.days, 0) print("Currently {num} days old".format(num=age_days)) - print("Currently involved TC members: " + ", ".join(tc)) + print("Currently involved TC members: " + ", ".join(tc_member)) print("Currently has {num} /lgtm".format(num=current_lgtm)) if current_approve: print("Currently /approve") print("") +if __name__ == "__main__": + main() diff --git a/advisors/tc_statistic.py b/advisors/tc_statistic.py index c0b9d5a94c78f5324775918951fc99cbb3943770..ab62197a3a7c8d61d69950a3a7b871f2e76ef4ed 100755 --- a/advisors/tc_statistic.py +++ b/advisors/tc_statistic.py @@ -3,16 +3,14 @@ This is a command line tool to create reminder list for TC member """ +import os +import json import urllib import urllib.request import urllib.parse import argparse -import json -import sys -import os import yaml -from pprint import pprint -from datetime import datetime + class Advisor(object): """ @@ -21,7 +19,8 @@ class Advisor(object): def __init__(self): self.secret = open(os.path.expanduser("~/.gitee_personal_token.json"), "r") self.token = json.load(self.secret) - self.header = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0"} + self.header = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64; rv:50.0) "\ + "Gecko/20100101 Firefox/50.0"} self.tc_members = None self.time_format = "%Y-%m-%dT%H:%M:%S%z" @@ -31,12 +30,9 @@ class Advisor(object): """ headers = self.header.copy() headers["Content-Type"] = "application/json;charset=UTF-8" - req = urllib.request.Request(url = url, - headers = headers, - method = "GET") - - with urllib.request.urlopen(req) as u: - resp = json.loads(u.read().decode("utf-8")) + req = urllib.request.Request(url = url, headers = headers, method = "GET") + with urllib.request.urlopen(req) as result: + resp = json.loads(result.read().decode("utf-8")) return resp def get_file(self, repo, path): @@ -44,13 +40,9 @@ class Advisor(object): Get remote raw file """ url = "https://gitee.com/{repo}/raw/master/{path}".format(repo=repo, path=path) - req = urllib.request.Request(url = url, - headers = self.header, - method = "GET") - - with urllib.request.urlopen(req) as u: - resp = u.read() - + req = urllib.request.Request(url = url, headers = self.header, method = "GET") + with urllib.request.urlopen(req) as result: + resp = result.read() return resp def get_prs(self): @@ -58,7 +50,8 @@ class Advisor(object): Get list of PRs """ pulls_url = "https://gitee.com/api/v5/repos/openeuler/community/pulls" - list_url = pulls_url + "?access_token={token}&state=open&sort=created&direction=desc&page=1&per_page=100" + list_url = pulls_url + "?access_token={token}&state=open&sort=created&direction=desc&"\ + "page=1&per_page=100" url = list_url.format(token=self.token["access_token"]) return self.get_json(url) @@ -68,16 +61,13 @@ class Advisor(object): """ pulls_url = "https://gitee.com/api/v5/repos/openeuler/community/pulls" list_all_url = pulls_url + "?access_token={token}&state=all&sort=created&direction=desc&" - #list_all_url = pulls_url + "?access_token={token}&state=all&sort=created&direction=desc&per_page=100&page=" list_all_url = list_all_url.format(token=self.token["access_token"]) result = [] page = 1 - if num <= 100: list_all_url = list_all_url + "per_page={num}&page=1".format(num=num) return self.get_json(list_all_url) - list_all_url = list_all_url + "per_page=100&page=" while num > 100: @@ -102,9 +92,10 @@ class Advisor(object): """ Get list of current TC members """ - m = yaml.load(adv.get_file("openeuler/community", "sig/TC/OWNERS"), Loader=yaml.Loader) - self.tc_members = m["maintainers"] - return m["maintainers"] + owners = yaml.load(self.get_file("openeuler/community", "sig/TC/OWNERS"), + Loader=yaml.Loader) + self.tc_members = owners["maintainers"] + return owners["maintainers"] def filter_out_tc(self, users): """ @@ -113,33 +104,39 @@ class Advisor(object): if not self.tc_members: self.get_tc_members() return [x for x in self.tc_members if x in users] - - -if __name__ == "__main__": + + +def main(): + """ + Main entrance of the functionality + """ par = argparse.ArgumentParser() par.add_argument("-n", "--number", help="Number of recent PRs to be processed", default="100") args = par.parse_args() - adv = Advisor() - tc_members = adv.get_tc_members() + advisor = Advisor() + tc_members = advisor.get_tc_members() print("Current TC members :", tc_members) tc_statistic = {} - for t in tc_members: - tc_statistic[t] = 0 - PRs = adv.get_recent_prs(int(args.number)) - print("Statistic of recent {num} PRs".format(num=len(PRs))) + for member in tc_members: + tc_statistic[member] = 0 + pr_list = advisor.get_recent_prs(int(args.number)) + print("Statistic of recent {num} PRs".format(num=len(pr_list))) - for pr in PRs: - commenter = pr["user"]["login"] + for preq in pr_list: + commenter = preq["user"]["login"] if commenter in tc_members: tc_statistic[commenter] += 1 - comments = adv.get_pr_comments(pr["number"]) + comments = advisor.get_pr_comments(preq["number"]) for comment in comments: commenter = comment["user"]["login"] if commenter in tc_members: tc_statistic[commenter] += 1 - - for tc in tc_statistic.keys(): - print("{tc} made {num} comments".format(tc=tc, num=tc_statistic[tc])) + for tc_member in tc_statistic: + print("{tc} made {num} comments".format(tc=tc_member, num=tc_statistic[tc_member])) + + +if __name__ == "__main__": + main() diff --git a/advisors/which_archived.py b/advisors/which_archived.py index 535e9e5ad21bc07255c42140b0ba80de363058d5..bd4f5d04771fac7c3cc10907a1a5aab2c170636c 100755 --- a/advisors/which_archived.py +++ b/advisors/which_archived.py @@ -31,8 +31,15 @@ import requests import yaml import bs4 import urllib3 -import gitee -import yaml2url + +try: + import gitee + import yaml2url +except ImportError as error: + from advisors import gitee + from advisors import yaml2url + + urllib3.disable_warnings() GET_METHOD_PEOJECTS = "/projects" @@ -43,6 +50,7 @@ gitlab_list = ['gnome', 'freedesktop'] RECORDER_YAML = ".query_result_lasttime" GNU_SOFTWARE_PAGE = "https://www.gnu.org/software/" + def __gitlab_get_method(query_url, token, params=None): """ Get method @@ -60,8 +68,8 @@ def __gitlab_get_method(query_url, token, params=None): data = json.loads(content) return data return None - except requests.RequestException as e: - logging.error("request failed, reason=%s", e) + except requests.RequestException as excpt: + logging.error("request failed, reason=%s", excpt) return None @@ -91,19 +99,19 @@ def record_pkginfo(py_object): """ record package info for running quickly next time """ - with open(RECORDER_YAML, 'w', encoding='utf-8') as f: - yaml.dump(py_object, f) - f.close() + with open(RECORDER_YAML, 'w', encoding='utf-8') as record_file: + yaml.dump(py_object, record_file) + record_file.close() def read_pkginfo_lasttime(): """ read package info record last time """ - record_file = os.path.join(os.getcwd(), RECORDER_YAML) + file_name = os.path.join(os.getcwd(), RECORDER_YAML) try: - with open(record_file, 'r', encoding='utf-8') as f: - return yaml.load(f.read(), Loader = yaml.Loader) + with open(file_name, 'r', encoding='utf-8') as record_file: + return yaml.load(record_file.read(), Loader = yaml.Loader) except FileNotFoundError: return {} @@ -146,8 +154,8 @@ def load_config(): load configuration """ try: - with open(COMMUNITY_ARCHIVED_YAML, 'r', encoding = 'utf-8') as f: - return yaml.load(f.read(), Loader = yaml.Loader) + with open(COMMUNITY_ARCHIVED_YAML, 'r', encoding = 'utf-8') as archived_file: + return yaml.load(archived_file.read(), Loader = yaml.Loader) except OSError as reason: print("Load yaml failed!" + str(reason)) return None diff --git a/command/check_missing_specs b/command/check_missing_specs new file mode 100644 index 0000000000000000000000000000000000000000..cdffa17f188fea21bfc4548ec77ba5b3bf4efe97 --- /dev/null +++ b/command/check_missing_specs @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 + +import sys +import signal +from signal import SIG_DFL + +try: + def sig_handler(signum, frame): + print('Exit command mode') + sys.exit(0) + + signal.signal(signal.SIGINT, sig_handler) + signal.signal(signal.SIGPIPE, SIG_DFL) +except: + pass + +from advisors.check_missing_specs import main + + +if __name__ == '__main__': + try: + main() + except Exception as error: + print("WARNING: Command execution error") + print(error.message) diff --git a/command/check_repeated_repo b/command/check_repeated_repo new file mode 100644 index 0000000000000000000000000000000000000000..9cf897fd9b901041c7734c5c330fdd129c83c954 --- /dev/null +++ b/command/check_repeated_repo @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 + +import sys +import signal +from signal import SIG_DFL + +try: + def sig_handler(signum, frame): + print('Exit command mode') + sys.exit(0) + + signal.signal(signal.SIGINT, sig_handler) + signal.signal(signal.SIGPIPE, SIG_DFL) +except: + pass + +from advisors.check_repeated_repo import main + + +if __name__ == '__main__': + try: + main() + except Exception as error: + print("WARNING: Command execution error") + print(error.message) diff --git a/command/check_source_url b/command/check_source_url new file mode 100644 index 0000000000000000000000000000000000000000..e9179f2785b050f170efb290231b7e2df25f75ee --- /dev/null +++ b/command/check_source_url @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 + +import sys +import signal +from signal import SIG_DFL + +try: + def sig_handler(signum, frame): + print('Exit command mode') + sys.exit(0) + + signal.signal(signal.SIGINT, sig_handler) + signal.signal(signal.SIGPIPE, SIG_DFL) +except: + pass + +from advisors.check_source_url import main + + +if __name__ == '__main__': + try: + main() + except Exception as error: + print("WARNING: Command execution error") + print(error.message) diff --git a/command/create_repo b/command/create_repo new file mode 100644 index 0000000000000000000000000000000000000000..0f9b9cc72884df560b9133dc805037687dc58274 --- /dev/null +++ b/command/create_repo @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 + +import sys +import signal +from signal import SIG_DFL + +try: + def sig_handler(signum, frame): + print('Exit command mode') + sys.exit(0) + + signal.signal(signal.SIGINT, sig_handler) + signal.signal(signal.SIGPIPE, SIG_DFL) +except: + pass + +from advisors.create_repo import main + + +if __name__ == '__main__': + try: + main() + except Exception as error: + print("WARNING: Command execution error") + print(error.message) diff --git a/command/create_repo_with_srpm b/command/create_repo_with_srpm new file mode 100644 index 0000000000000000000000000000000000000000..6a4b189e1e47a83fe14da45a810673cfbf81a29b --- /dev/null +++ b/command/create_repo_with_srpm @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 + +import sys +import signal +from signal import SIG_DFL + +try: + def sig_handler(signum, frame): + print('Exit command mode') + sys.exit(0) + + signal.signal(signal.SIGINT, sig_handler) + signal.signal(signal.SIGPIPE, SIG_DFL) +except: + pass + +from advisors.create_repo_with_srpm import main + + +if __name__ == '__main__': + try: + main() + except Exception as error: + print("WARNING: Command execution error") + print(error.message) diff --git a/command/match_patches b/command/match_patches new file mode 100644 index 0000000000000000000000000000000000000000..a6bb103ceae05147f26daed80fbb7ec3995ade15 --- /dev/null +++ b/command/match_patches @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 + +import sys +import signal +from signal import SIG_DFL + +try: + def sig_handler(signum, frame): + print('Exit command mode') + sys.exit(0) + + signal.signal(signal.SIGINT, sig_handler) + signal.signal(signal.SIGPIPE, SIG_DFL) +except: + pass + +from advisors.match_patches import main + + +if __name__ == '__main__': + try: + main() + except Exception as error: + print("WARNING: Command execution error") + print(error.message) diff --git a/command/oa_upgradable b/command/oa_upgradable new file mode 100644 index 0000000000000000000000000000000000000000..0f29fdb713185aff8a788efd3dcf89e33978278c --- /dev/null +++ b/command/oa_upgradable @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 + +import sys +import signal +from signal import SIG_DFL + +try: + def sig_handler(signum, frame): + print('Exit command mode') + sys.exit(0) + + signal.signal(signal.SIGINT, sig_handler) + signal.signal(signal.SIGPIPE, SIG_DFL) +except: + pass + +from advisors.oa_upgradable import main + + +if __name__ == '__main__': + try: + main() + except Exception as error: + print("WARNING: Command execution error") + print(error.message) diff --git a/command/psrtool b/command/psrtool new file mode 100644 index 0000000000000000000000000000000000000000..2a50677f902766fd4c9738f0b87669bc2a5c04e9 --- /dev/null +++ b/command/psrtool @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 + +import sys +import signal +from signal import SIG_DFL + +try: + def sig_handler(signum, frame): + print('Exit command mode') + sys.exit(0) + + signal.signal(signal.SIGINT, sig_handler) + signal.signal(signal.SIGPIPE, SIG_DFL) +except: + pass + +from advisors.psrtool import main + + +if __name__ == '__main__': + try: + main() + except Exception as error: + print("WARNING: Command execution error") + print(error.message) diff --git a/command/review_tool b/command/review_tool new file mode 100644 index 0000000000000000000000000000000000000000..d18adcf15530f4113d99a533cecf2c15cae8bcd1 --- /dev/null +++ b/command/review_tool @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 + +import sys +import signal +from signal import SIG_DFL + +try: + def sig_handler(signum, frame): + print('Exit command mode') + sys.exit(0) + + signal.signal(signal.SIGINT, sig_handler) + signal.signal(signal.SIGPIPE, SIG_DFL) +except: + pass + +from advisors.review_tool import main + + +if __name__ == '__main__': + try: + main() + except Exception as error: + print("WARNING: Command execution error") + print(error.message) diff --git a/command/simple_update_robot b/command/simple_update_robot new file mode 100644 index 0000000000000000000000000000000000000000..5188ae0ac4f6dc3bb70dd80788a208080cbf1c54 --- /dev/null +++ b/command/simple_update_robot @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 + +import sys +import signal +from signal import SIG_DFL + +try: + def sig_handler(signum, frame): + print('Exit command mode') + sys.exit(0) + + signal.signal(signal.SIGINT, sig_handler) + signal.signal(signal.SIGPIPE, SIG_DFL) +except: + pass + +from advisors.simple_update_robot import main + + +if __name__ == '__main__': + try: + main() + except Exception as error: + print("WARNING: Command execution error") + print(error.message) diff --git a/command/tc_reminder b/command/tc_reminder new file mode 100644 index 0000000000000000000000000000000000000000..d394a08b1832113ee1d369b22c3d15bb1fa3b497 --- /dev/null +++ b/command/tc_reminder @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 + +import sys +import signal +from signal import SIG_DFL + +try: + def sig_handler(signum, frame): + print('Exit command mode') + sys.exit(0) + + signal.signal(signal.SIGINT, sig_handler) + signal.signal(signal.SIGPIPE, SIG_DFL) +except: + pass + +from advisors.tc_reminder import main + + +if __name__ == '__main__': + try: + main() + except Exception as error: + print("WARNING: Command execution error") + print(error.message) diff --git a/command/tc_statistic b/command/tc_statistic new file mode 100644 index 0000000000000000000000000000000000000000..1c515202f84795d2ae057a7335f9ac83a21a14df --- /dev/null +++ b/command/tc_statistic @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 + +import sys +import signal +from signal import SIG_DFL + +try: + def sig_handler(signum, frame): + print('Exit command mode') + sys.exit(0) + + signal.signal(signal.SIGINT, sig_handler) + signal.signal(signal.SIGPIPE, SIG_DFL) +except: + pass + +from advisors.tc_statistic import main + + +if __name__ == '__main__': + try: + main() + except Exception as error: + print("WARNING: Command execution error") + print(error.message) diff --git a/command/which_archived b/command/which_archived new file mode 100644 index 0000000000000000000000000000000000000000..f2cb7e9b584e3379767365d2d944bcac40e1a354 --- /dev/null +++ b/command/which_archived @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 + +import sys +import signal +from signal import SIG_DFL + +try: + def sig_handler(signum, frame): + print('Exit command mode') + sys.exit(0) + + signal.signal(signal.SIGINT, sig_handler) + signal.signal(signal.SIGPIPE, SIG_DFL) +except: + pass + +from advisors.which_archived import main + + +if __name__ == '__main__': + try: + main() + except Exception as error: + print("WARNING: Command execution error") + print(error.message) diff --git a/openEuler-Advisor.spec b/openEuler-Advisor.spec new file mode 100644 index 0000000000000000000000000000000000000000..a44a256a3d7e7c7526dc924fa1761306967f8fcc --- /dev/null +++ b/openEuler-Advisor.spec @@ -0,0 +1,52 @@ +Name: openEuler-Advisor +Version: 1.0 +Release: 1 +Summary: Collection of automatic tools for easily maintaining openEuler +Group: Application +License: Mulan PSL v2 +URL: https://gitee.com/openeuler/openEuler-Advisor +Source0: https://gitee.com/openeuler/openEuler-Advisor/%{name}-%{version}.tar.gz +BuildArch: noarch +BuildRequires: python3 pytest +Requires: python3-pyrpm python3-pyyaml python36-requests rpmdevtools python-BeautifulSoup + +%description +Collection of automatic tools for easily maintaining openEuler + +%prep +%autosetup -n %{name}-%{version} -p1 + +%build +%py3_build + +%install +%py3_install + +%check +py.test-%{python3_version} -vv tests || : + +%post + +%postun + +%files +%doc README.* AUTHORS RELEASES.md +%license LICENSE +%{python3_sitelib}/* +%attr(0755,root,root) %{_bindir}/simple_update_robot +%attr(0755,root,root) %{_bindir}/oa_upgradable +%attr(0755,root,root) %{_bindir}/match_patches +%attr(0755,root,root) %{_bindir}/check_missing_specs +%attr(0755,root,root) %{_bindir}/check_repeated_repo +%attr(0755,root,root) %{_bindir}/check_source_url +%attr(0755,root,root) %{_bindir}/create_repo +%attr(0755,root,root) %{_bindir}/create_repo_with_srpm +%attr(0755,root,root) %{_bindir}/psrtool +%attr(0755,root,root) %{_bindir}/review_tool +%attr(0755,root,root) %{_bindir}/tc_reminder +%attr(0755,root,root) %{_bindir}/tc_statistic +%attr(0755,root,root) %{_bindir}/which_archived + +%changelog +* Sat Oct 17 2020 Leo Fang - 1.0-1 +- Package init diff --git a/setup.py b/setup.py new file mode 100644 index 0000000000000000000000000000000000000000..cdef276bee1ff6986c2dd4c0c0f90d887346052d --- /dev/null +++ b/setup.py @@ -0,0 +1,55 @@ +#!/usr/bin/python3 +""" +Package management program installation configuration +file for openEuler-Advisor +""" +from distutils.core import setup + + +setup( + name='openEuler-Advisor', + version='1.0', + py_modules=[ + 'advisors.simple_update_robot', + 'advisors.oa_upgradable', + 'advisors.check_upstream', + 'advisors.version_recommend', + 'advisors.match_patches', + 'advisors.check_missing_specs', + 'advisors.check_repeated_repo', + 'advisors.check_source_url', + 'advisors.create_repo', + 'advisors.create_repo_with_srpm', + 'advisors.psrtool', + 'advisors.review_tool', + 'advisors.tc_reminder', + 'advisors.tc_statistic', + 'advisors.which_archived', + 'advisors.yaml2url', + 'advisors.gitee', + 'legacy.python-packager', + 'legacy.who_maintain', + 'tests.test_yaml2url'], + requires=['python_rpm_spec (>=0.10)', + 'PyYAML (>=5.3.1)', + 'requests (>=2.24.0)', + 'rpmdevtools (>=8.3)', + 'bs4 (>=0.0.1)'], + license='Mulan PSL v2', + author=open('AUTHORS', encoding='utf-8').read(), + description='collection of automatic tools for easily maintaining openEuler', + data_files=[ + ('/usr/bin/', ['command/simple_update_robot']), + ('/usr/bin/', ['command/oa_upgradable']), + ('/usr/bin/', ['command/match_patches']), + ('/usr/bin/', ['command/check_missing_specs']), + ('/usr/bin/', ['command/check_repeated_repo']), + ('/usr/bin/', ['command/check_source_url']), + ('/usr/bin/', ['command/create_repo']), + ('/usr/bin/', ['command/create_repo_with_srpm']), + ('/usr/bin/', ['command/psrtool']), + ('/usr/bin/', ['command/review_tool']), + ('/usr/bin/', ['command/tc_reminder']), + ('/usr/bin/', ['command/tc_statistic']), + ('/usr/bin/', ['command/which_archived'])] +) diff --git a/advisors/test/__init__.py b/tests/__init__.py similarity index 100% rename from advisors/test/__init__.py rename to tests/__init__.py diff --git a/advisors/test/test_yaml2url.py b/tests/test_yaml2url.py similarity index 96% rename from advisors/test/test_yaml2url.py rename to tests/test_yaml2url.py index 930a4b6d020db5a1def7f718cbdfd87c4516a319..dc880da4d8879da931f40ceddfe777b0b595e715 100644 --- a/advisors/test/test_yaml2url.py +++ b/tests/test_yaml2url.py @@ -16,7 +16,8 @@ This is an test script for get url from repo name """ import yaml -import yaml2url +from advisors import yaml2url + YAML_DOC = """ version_control: {version_control}