6 Star 1 Fork 6

BigSkySea/mkbshare

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
add_branch_for_pkg.py 1.81 KB
一键复制 编辑 原始数据 按行查看 历史
BigSkySea 提交于 2021-02-04 17:19 +08:00 . update
#!/bin/env python3
# coding:utf-8
import os
import sys
import yaml
from collections import OrderedDict
# obs project name, which new branch for package will be created from
obs_project = sys.argv[1]
# new branch name
branch_name = sys.argv[2]
# new branch created from
branch_from = sys.argv[3]
# community repository path
community_path = sys.argv[4]
src_yaml_file_path = os.path.join(community_path, "repository", "src-openeuler.yaml")
sigs_yaml_file_path = os.path.join(community_path, "sig", "sigs.yaml")
cmd = "osc list %s" % obs_project
pkgs = list(set(os.popen(cmd).read().split("\n")) - set(['']))
def read_yaml(file_path):
file_msg = None
if os.path.exists(file_path):
with open(file_path, "r", encoding='utf-8') as f:
file_msg = yaml.load(f, Loader=yaml.FullLoader)
return file_msg
def write_yaml(dict_msg, file_path):
with open(file_path, "w", encoding='utf-8') as f:
yaml.dump(dict_msg, f, default_flow_style=False, sort_keys=False)
def add_branch():
recycle_pkgs = []
dict_msg = read_yaml(src_yaml_file_path)
sigs_list = read_yaml(sigs_yaml_file_path)["sigs"]
for sig in sigs_list:
if sig["name"] == "sig-recycle":
recycle_pkgs = sig["repositories"]
if recycle_pkgs:
for i in range(len(recycle_pkgs)):
recycle_pkgs[i] = recycle_pkgs[i].split("/")[1]
for pkg in dict_msg["repositories"]:
flag = False
if pkg["name"] in pkgs and pkg["name"] not in recycle_pkgs:
for bm in pkg["branches"]:
if bm["name"] == branch_name:
flag = True
break
if not flag:
pkg["branches"].append({'name': branch_name, 'type':"protected", 'create_from':branch_from})
write_yaml(dict_msg, src_yaml_file_path)
add_branch()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/BigSkySea/mkbshare.git
git@gitee.com:BigSkySea/mkbshare.git
BigSkySea
mkbshare
mkbshare
master

搜索帮助