代码拉取完成,页面将自动刷新
同步操作将从 openEuler/community 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#!/usr/bin/python3
"""
This is a tool to close unmaintained branches of openEuler community
"""
import yaml
import sys
import argparse
import os
import re
def load_yaml(d, f):
"""
Helper for load YAML database
"""
p = os.path.expanduser(os.path.join(d, f))
try:
y = yaml.load(open(p, encoding="utf-8"), Loader=yaml.Loader)
except FileNotFoundError:
print("Cannot Load {path}".format(path=p))
print("Could be wrong path")
sys.exit(1)
except yaml.scanner.ScannerError as e:
print("%s: Invalid YAML file"%(p))
print("Detailed Error Information:")
print(e)
sys.exit(1)
return y
def disable_src_openeuler_yamls(community, unmaintained_list):
"""
Disable branches in all src-openeuler repositories definition
"""
print("Disabling unmaintained branches for all repos definition in src-openeuler")
src_oe_repos = []
sig_path = os.path.expanduser(os.path.join(community, "sig"))
yaml_pattern = re.compile("(.*)/sig/(.*)/(src-openeuler)/([a-z])/(.*).yaml")
for root, dirs, files in os.walk(sig_path):
for f in files:
fn = os.path.join(root, f)
match_obj = yaml_pattern.match(fn)
if match_obj:
need_close = False
src_repo = load_yaml(root, f)
# print(f)
for branch in src_repo["branches"]:
if branch["name"] in unmaintained_list and branch["type"] != "readonly":
branch["type"] = "readonly"
need_close = True
if need_close:
src_oe_repos.append({'fn':fn, 'yaml':src_repo})
return src_oe_repos
if __name__ == "__main__":
par = argparse.ArgumentParser()
par.add_argument("community", type=str, help="Local path of community repository")
par.add_argument("-d", "--disable_branch", type=str, help="Additional branch name to disable", default="")
par.add_argument("-c", "--check-only", help="Do checking only, don't change any YAML file", action="store_true")
args = par.parse_args()
branches_file = "ci-scripts/unmaintained_branches.yaml"
unmaintained_list = load_yaml(args.community, branches_file)
print("Current disabled branches:")
print(unmaintained_list)
if args.disable_branch != "":
if args.disable_branch in unmaintained_list:
print("Already disabled branch " + args.disable_branch)
sys.exit(1)
else:
unmaintained_list.append(args.disable_branch)
unmaintained_set = set(unmaintained_list)
repos = disable_src_openeuler_yamls(args.community, unmaintained_set)
for repo in repos:
if not os.path.exists(repo['fn']):
print("Error while file not found: " + repo['fn'])
sys.exit(1)
if args.check_only:
print("{fn} has unmaintained branches, but not readonly".format(fn=repo['fn']))
else:
with open(repo['fn'], "w") as repo_yaml:
yaml.dump(repo['yaml'], repo_yaml, sort_keys=False)
if args.disable_branch != "":
print("Writing back additional disabled branch")
fn = os.path.join(args.community, branches_file)
with open(fn, "w") as bn:
yaml.dump(unmaintained_list, bn, sort_keys=False)
print("Finished!")
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。