You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

create_sig_info_template.py 5.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import os
  2. import yaml
  3. import sys
  4. def load_yaml(file_path):
  5. """
  6. load yaml
  7. :param file_path: yaml file path
  8. :return: content of yaml
  9. """
  10. with open(file_path, encoding="utf-8") as fp:
  11. try:
  12. content = yaml.load(fp.read(), Loader=yaml.Loader)
  13. except yaml.MarkedYAMLError as e:
  14. print(e)
  15. sys.exit(1)
  16. return content
  17. def get_sig_owners_path(sig_name):
  18. cur_path = os.popen("pwd").read().replace("\n", "")
  19. sig_path = os.path.join(cur_path, sig_name)
  20. if not os.path.exists(sig_path):
  21. print("%s is not exist" % sig_path)
  22. sys.exit(1)
  23. owners_path = os.path.join(sig_path, "OWNERS")
  24. return sig_path, owners_path
  25. def make_template_file_data_and_write(sig_name, sig_path, owners_path):
  26. content = {}
  27. content["name"] = sig_name
  28. content["description"] = "TO_BE_CLARIFIED"
  29. content["created_on"] = "2019-12-31"
  30. content["mailing_list"] = "TO_BE_CLARIFIED"
  31. content["meeting_url"] = "TO_BE_CLARIFIED"
  32. content["mature_level"] = "startup"
  33. content["mentors"] = [{"gitee_id": "--xxx--", "name": "TO_BE_CLARIFIED", "organization": "TO_BE_CLARIFIED", "email": "TO_BE_CLARIFIED"}]
  34. # if sig_info.yaml exists
  35. if os.path.exists(os.path.join(sig_path, "sig-info.yaml")):
  36. sig_info_content = load_yaml(os.path.join(sig_path, "sig-info.yaml"))
  37. content["description"] = sig_info_content.get("description") if sig_info_content.get("description") else "TO_BE_CLARIFIED"
  38. content["meeting_url"] = sig_info_content.get("meeting_url") if sig_info_content.get("meeting_url") else "TO_BE_CLARIFIED"
  39. content["mailing_list"] = sig_info_content.get("mailing_list") if sig_info_content.get("mailing_list") else "TO_BE_CLARIFIED"
  40. mts_in_sig_info = []
  41. for i in sig_info_content.get("maintainers"):
  42. mts_in_sig_info.append(i["gitee_id"])
  43. v = []
  44. for m in decode_owners(owners_path):
  45. if m in mts_in_sig_info:
  46. for mr in sig_info_content.get("maintainers"):
  47. if m == mr["gitee_id"]:
  48. v.append({
  49. "gitee_id": m, "name": mr.get("name") if mr.get("name") else "TO_BE_CLARIFIED",
  50. "organization": mr.get("organization") if mr.get("organization") else "TO_BE_CLARIFIED",
  51. "email": mr.get("email") if mr.get("email") else "TO_BE_CLARIFIED",
  52. })
  53. else:
  54. v.append({"gitee_id": m, "name": "TO_BE_CLARIFIED", "organization": "TO_BE_CLARIFIED",
  55. "email": "TO_BE_CLARIFIED"})
  56. if len(v) == 0:
  57. content["maintainers"] = [
  58. {"gitee_id": "--xxx--", "name": "TO_BE_CLARIFIED", "organization": "TO_BE_CLARIFIED",
  59. "email": "TO_BE_CLARIFIED"}]
  60. else:
  61. content["maintainers"] = v
  62. else:
  63. v = []
  64. for m in decode_owners(owners_path):
  65. v.append({"gitee_id": m, "name": "TO_BE_CLARIFIED", "organization": "TO_BE_CLARIFIED",
  66. "email": "TO_BE_CLARIFIED"})
  67. if len(v) == 0:
  68. content["maintainers"] = [
  69. {"gitee_id": "--xxx--", "name": "TO_BE_CLARIFIED", "organization": "TO_BE_CLARIFIED",
  70. "email": "TO_BE_CLARIFIED"}]
  71. else:
  72. content["maintainers"] = v
  73. repos = []
  74. for root, dirs, files in os.walk(sig_path):
  75. if len(dirs) == 0:
  76. if len(files) == 0:
  77. break
  78. for f in files:
  79. if root.count("/") > 2 and f.endswith(".yaml"):
  80. repos.append(root.split("/")[-2] + '/' + f.split(".yaml")[0])
  81. else:
  82. continue
  83. if len(repos) == 0:
  84. content["repositories"] = [{"repo": ["example/repos1", "example/repos2"], "committers": [{"gitee_id": "--xxx--", "name": "TO_BE_CLARIFIED", "organization": "TO_BE_CLARIFIED", "email": "TO_BE_CLARIFIED"}],
  85. "contributors": [{"gitee_id": "--xxx--", "name": "TO_BE_CLARIFIED", "organization": "TO_BE_CLARIFIED", "email": "TO_BE_CLARIFIED"}],}, {"repo": ["example/repos1", "example/repos2"],}, ]
  86. else:
  87. content["repositories"] = [{"repo": repos, "committers": [{"gitee_id": "--xxx--", "name": "TO_BE_CLARIFIED", "organization": "TO_BE_CLARIFIED", "email": "TO_BE_CLARIFIED"}],
  88. "contributors": [{"gitee_id": "--xxx--", "name": "TO_BE_CLARIFIED", "organization": "TO_BE_CLARIFIED", "email": "TO_BE_CLARIFIED"}], }]
  89. write_yaml_to_sig(sig_path, content)
  90. def decode_owners(owners_path):
  91. if os.path.exists(owners_path):
  92. c = load_yaml(owners_path)
  93. return c["maintainers"]
  94. else:
  95. return []
  96. def write_yaml_to_sig(dst_path, data):
  97. file_path = os.path.join(dst_path, "sig-info.yaml")
  98. with open(file_path, 'w', encoding="utf-8") as f:
  99. yaml.dump(data, f, Dumper=yaml.Dumper, sort_keys=False)
  100. # you can use "python3 create_single_siginfo.py sig_name(example: security)" to auto make a sig_info.yaml for a sig,
  101. # make sure you trigger this command after you enter the "community/sigs" directory
  102. if __name__ == '__main__':
  103. if len(sys.argv) != 2:
  104. print('Required 1 parameters! The sig_name need to be transferred in sequence.')
  105. sys.exit(1)
  106. sig = sys.argv[1]
  107. s_path, o_path = get_sig_owners_path(sig)
  108. make_template_file_data_and_write(sig, s_path, o_path)