From 90d59cb760ccd13ceab0d8168815cf400e2869af Mon Sep 17 00:00:00 2001 From: Shinwell Hu Date: Mon, 1 Jun 2020 03:20:30 +0000 Subject: [PATCH 1/6] rewrite sanity_check in python3 --- .../governance/sanity_check.py | 211 ++++++++++++++++++ .../governance/sanity_check.rb | 164 -------------- 2 files changed, 211 insertions(+), 164 deletions(-) create mode 100644 zh/technical-committee/governance/sanity_check.py delete mode 100644 zh/technical-committee/governance/sanity_check.rb diff --git a/zh/technical-committee/governance/sanity_check.py b/zh/technical-committee/governance/sanity_check.py new file mode 100644 index 000000000..ba12222c2 --- /dev/null +++ b/zh/technical-committee/governance/sanity_check.py @@ -0,0 +1,211 @@ +#!/usr/bin/python3 +import yaml +import sys +import argparse +import os.path + +def check_1(sigs, exps): + """ + Repository in src-openeuler and openeuler should be managed by the single SIG. + """ + print("Repository in src-openeuler and openeuler should be managed by the single SIG.") + + repositories = {} + errors_found = 0 + + for sig in sigs: + if sig["name"] == "Private": + continue + for repo in sig["repositories"]: + repo_name = repo.replace("src-openeuler/", "").replace("openeuler/", "") + supervisor = repositories.get(repo_name, set()) + supervisor.add(sig["name"]) + repositories[repo_name] = supervisor + + for k in repositories: + v = repositories[k] + if len(v) != 1: + if k in exps: + continue + print("WARNING! " + k + ": Co-managed by these SIGs " + str(v) + "\n") + errors_found = errors_found + 1 + + if errors_found == 0: + print("PASS WITHOUT ISSUES FOUND.") + return errors_found + + +def check_2(sigs, exps): + """ + Repository in src-openeuler or openeuler should never be duplicated. + """ + print("Repository in src-openeuler or openeuler should never be duplicated.") + + repositories = {} + errors_found = 0 + + for sig in sigs: + if sig["name"] == "Private": + continue + for repo in sig["repositories"]: + supervisor = repositories.get(repo, set()) + if sig["name"] in supervisor: + print("WARNING! " + repo + " has been managed by " + sig["name"] + " multiple times.\n") + errors_found = errors_found + 1 + else: + supervisor.add(sig["name"]) + repositories[repo] = supervisor + + for k in repositories: + v = repositories[k] + if len(v) != 1: + if k in exps: + continue + print(repo + ": " + v + "\n") + errors_found = errors_found + 1 + + if errors_found == 0: + print("PASS WITHOUT ISSUES FOUND.") + return errors_found + + +def check_3(sigs): + """ + Repository managed by both SIG and Private. + """ + print("Repository managed by both SIG and Private.") + + supervisors = {} + + for sig in sigs: + for repo in sig["repositories"]: + supervisor = supervisors.get(repo, set()) + supervisor.add(sig["name"]) + supervisors[repo] = supervisor + + print("There're " + str(len(supervisors)) + " repositories in total.") + + co_managed = 0 + private_only = 0 + + for k in supervisors: + v = supervisors[k] + if "Private" in v: + if len(v) != 1: + co_managed = co_managed + 1 + else: + private_only = private_only + 1 + print("There're " + str(co_managed) + " repositories co-managed by Private") + print("There're " + str(private_only) + " repositories managed by Private only") + return supervisors + + +def check_4(sigs, exps, prefix, oe_repos, supervisors, cross_checked_repo): + """ + YAML in repository/ should be consisitent with sigs.yaml + """ + print("repository/{prefix}.yaml should be consisitent with sigs.yaml".format(prefix=prefix)) + + errors_found = 0 + + for repo in oe_repos: + name = prefix + "/" + repo["name"] + if name in cross_checked_repo: + print("WARNING! Repository {name} in {prefix}.yaml has duplication.".format(name=name, prefix=prefix)) + errors_found = errors_found + 1 + if not supervisors.get(name, False): + if name not in exps: + print("WARNING! Repository {name} in {prefix}.yaml cannot be found in sigs.yaml".format(name=name, prefix=prefix)) + errors_found = errors_found + 1 + if repo["type"] == "public" and "Private" in supervisors.get(name, set()): + print("WARNING! Repository {name} marked as public in {prefix}.yaml, but listed in Private SIG.".format(name=name, prefix=prefix)) + errors_found = errors_found + 1 + + if repo["type"] == "private" and "Private" not in supervisors.get(name, set()): + print("WARNING! Repository {name} marked as private in {prefix}.yaml, but not listed in Private SIG.".format(name=name, prefix=prefix)) + errors_found = errors_found + 1 + + cross_checked_repo.add(name) + + if errors_found == 0: + print("PASS WITHOUT ISSUES FOUND.") + return errors_found, cross_checked_repo + + +def check_6(cross_checked_repo, supervisors): + """ + All repositories in sigs.yaml must list in either openeuler.yaml or src-openeuler.yaml + """ + print("All repositories in sigs.yaml must list in either openeuler.yaml or src-openeuler.yaml") + errors_found = 0 + + if len(cross_checked_repo) != len(supervisors): + for repo in supervisors: + if not repo in cross_checked_repo: + print("WARNING! {name} listed in sigs.yaml, but neither openeuler.yaml nor src-openeuler.yaml".format(name=reop)) + errors_found = errors_found + 1 + + if errors_found == 0: + print("PASS WITHOUT ISSUES FOUND.") + + return errors_found + + +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), Loader=yaml.Loader) + except FileNotFoundError: + print("Cannot Load {path}".format(path=p)) + print("Could be wrong path") + sys.exit(1) + return y + + +if __name__ == "__main__": + """ + Sanity check among different YAML database inside openEuler community + """ + par = argparse.ArgumentParser() + + par.add_argument("community", type=str, help="Local path of community repository") + args = par.parse_args() + + sigs_yaml = load_yaml(args.community, "sig/sigs.yaml") + sigs = sigs_yaml["sigs"] + known_exceptions_yaml = load_yaml(args.community, "zh/technical-committee/governance/exceptions.yaml") + exps = known_exceptions_yaml["exceptions"] + openeuler_repo_yaml = load_yaml(args.community, "repository/openeuler.yaml") + openeuler_repos = openeuler_repo_yaml["repositories"] + srcopeneuler_repo_yaml = load_yaml(args.community, "repository/src-openeuler.yaml") + srcopeneuler_repos = srcopeneuler_repo_yaml["repositories"] + + supervisors = {} + cross_checked_repo = set() + + print("Sanity Check among different YAML database inside openEuler community.") + issues_found = 0 + print("\nCheck 1:") + issues_found = issues_found + check_1(sigs, exps) + + print("\nCheck 2:") + issues_found = issues_found + check_2(sigs, exps) + + print("\nCheck 3:") + supervisors = check_3(sigs) + + print("\nCheck 4:") + issues, cross_checked_repo = check_4(sigs, exps, "openeuler", openeuler_repos, supervisors, cross_checked_repo) + issues_found = issues_found + issues + + print("\nCheck 5:") + issues, cross_checked_repo = check_4(sigs, exps, "src-openeuler", srcopeneuler_repos, supervisors, cross_checked_repo) + issues_found = issues_found + issues + + print("\nCheck 6:") + issues_found = issues_found + check_6(cross_checked_repo, supervisors) + + sys.exit(issues_found) diff --git a/zh/technical-committee/governance/sanity_check.rb b/zh/technical-committee/governance/sanity_check.rb deleted file mode 100644 index bf942b1b5..000000000 --- a/zh/technical-committee/governance/sanity_check.rb +++ /dev/null @@ -1,164 +0,0 @@ -#!/usr/bin/ruby -require 'yaml' -require 'set' - -errors_found = 0 - -sigs = YAML.load(File.read("sig/sigs.yaml")) -known_exceptions_load = YAML.load(File.read("zh/technical-committee/governance/exceptions.yaml")) -exp_set = Array.new known_exceptions_load["exceptions"] - -print "Sanity Check among different YAML database inside openEuler community." - -print "\n\nCheck 1: " -print "Repository in src-openeuler and openeuler should be managed by the single SIG.\n" -repositories = Hash.new -for s in sigs do - s[1].each { |sig| - next if sig["name"] == "Private" - sig["repositories"].each { |repo| - repo_name = repo.gsub("src-openeuler/", "").gsub("openeuler/", "") - if repositories[repo_name] == nil then - repositories[repo_name] = Set.new - repositories[repo_name] << sig["name"] - else - repositories[repo_name] << sig["name"] - end - } - } -end -repositories.each_key { |repo| - if repositories[repo].length != 1 then - next if exp_set.include?(repo) - print repo, ": ", repositories[repo], "\n" - errors_found = errors_found + 1 - end -} - -print "\n\nCheck 2: " -print "Repository in src-openeuler or openeuler should never be duplicated.\n" -repositories = Hash.new -for s in sigs do - s[1].each { |sig| - next if sig["name"] == "Private" - sig["repositories"].each { |repo| - if repositories[repo] == nil then - repositories[repo] = Set.new - repositories[repo] << sig["name"] - elsif repositories[repo].include?(sig["name"]) - print repo, " has been managed by ", sig["name"], " more than 1 time.\n" - errors_found = errors_found + 1 - else - repositories[repo] << sig["name"] - end - } - } -end -repositories.each_key { |repo| - if repositories[repo].length != 1 then - next if exp_set.include?(repo) - print repo, ": ", repositories[repo], "\n" - errors_found = errors_found + 1 - end -} - -print "\n\nCheck 3: " -print "Repository managed by both SIG and Private.\n" -repositories = Hash.new -for s in sigs do - s[1].each { |sig| - sig["repositories"].each { |repo| - if repositories[repo] == nil then - repositories[repo] = Set.new - repositories[repo] << sig["name"] - else - repositories[repo] << sig["name"] - end - } - } -end - -print "There're ", repositories.length, " repositories in total.\n" -count = 0 -private_only = 0 -repositories.each_key { |repo| - if repositories[repo].length != 1 then - if repositories[repo].include?("Private") then - count = count + 1 - end - else - if repositories[repo].include?("Private") then - private_only = private_only + 1 - end - end -} -print "There're ", count, " repositories co-managed by Private\n" -print "There're ", private_only, " repositories managed by Private only\n" - -cross_checked_repo = Set.new - -print "\n\nCheck 4: " -print "repository/openeuler.yaml should be consisitent with sigs.yaml\n" -openeuler_repo_load = YAML.load(File.read("repository/openeuler.yaml")) -openeuler_repos = openeuler_repo_load["repositories"] -openeuler_repos.each { |openeuler_repo| - name = "openeuler/"+openeuler_repo["name"] - if cross_checked_repo.include?(name) then - print "Repository ", name, " in openeuler.yaml has duplication.\n" - errors_found = errors_found + 1 - end - if repositories[name] == nil then - next if exp_set.include?(name) - print "Repository ", name, " in openeuler.yaml cannot be found in sigs.yaml\n" - errors_found = errors_found + 1 - next - end - if openeuler_repo["type"] == "public" and repositories[name].include?("Private") then - print "Repository ", name, " marked as public in openeuler.yaml, but listed in Private SIG.\n" - errors_found = errors_found + 1 - end - if openeuler_repo["type"] == "private" and not repositories[name].include?("Private") then - print "Repository ", name, " marked as private in openeuler.yaml, but not listed in Private SIG.\n" - errors_found = errors_found + 1 - end - cross_checked_repo << name -} - -print "\n\nCheck 5: " -print "repository/src-openeuler.yaml should be consistent with sigs.yaml\n" -srcopeneuler_repo_load = YAML.load(File.read("repository/src-openeuler.yaml")) -srcopeneuler_repos = srcopeneuler_repo_load["repositories"] -srcopeneuler_repos.each { |srcopeneuler_repo| - name = "src-openeuler/"+srcopeneuler_repo["name"] - if cross_checked_repo.include?(name) then - print "Repository ", name, " in src-openeuler.yaml has duplication.\n" - errors_found = errors_found + 1 - end - if repositories[name] == nil then - print "Repository ", name, " in src-openeuler.yaml cannot be found in sigs.yaml\n" - errors_found = errors_found + 1 - next - end - if srcopeneuler_repo["type"] == "public" and repositories[name].include?("Private") then - print "Repository ", name, " marked as public in src-openeuler.yaml, but listed in Private SIG.\n" - errors_found = errors_found + 1 - end - if srcopeneuler_repo["type"] == "private" and not repositories[name].include?("Private") then - print "Repository ", name, " marked as private in src-openeuler.yaml, but not listed in Private SIG.\n" - errors_found = errors_found + 1 - end - cross_checked_repo << name -} - -print "\n\nCheck 6: " -print "All repositories in sigs.yaml must list in either openeuler.yaml or src-openeuler.yaml\n" - -if cross_checked_repo.length != repositories.length then - repositories.each_key { |n| - next if cross_checked_repo.include?(n) - print n, " listed in sigs.yaml, but neither openeuler.yaml nor src-openeuler.yaml\n" - errors_found = errors_found + 1 - } -end - -return errors_found -- Gitee From c7f6829e04b46ae319bc68a468ea5d6f80421624 Mon Sep 17 00:00:00 2001 From: Shinwell Hu Date: Mon, 1 Jun 2020 03:25:49 +0000 Subject: [PATCH 2/6] readd lateset sanity_check.rb --- .../governance/sanity_check.rb | 184 ++++++++++++++++++ 1 file changed, 184 insertions(+) create mode 100644 zh/technical-committee/governance/sanity_check.rb diff --git a/zh/technical-committee/governance/sanity_check.rb b/zh/technical-committee/governance/sanity_check.rb new file mode 100644 index 000000000..0c32e7dc5 --- /dev/null +++ b/zh/technical-committee/governance/sanity_check.rb @@ -0,0 +1,184 @@ +#!/usr/bin/ruby +require 'yaml' +require 'set' + +errors_found = 0 + +sigs = YAML.load(File.read("sig/sigs.yaml")) +known_exceptions_load = YAML.load(File.read("zh/technical-committee/governance/exceptions.yaml")) +exp_set = Array.new known_exceptions_load["exceptions"] + +print "Sanity check among YAML databases inside openEuler community." + +print "\n\nCheck 1: " +print "Repository in src-openeuler and openeuler usually be managed by the same SIG.\n" +repositories = Hash.new +for s in sigs do + s[1].each { |sig| + next if sig["name"] == "Private" + sig["repositories"].each { |repo| + repo_name = repo.gsub("src-openeuler/", "").gsub("openeuler/", "") + if repositories[repo_name] == nil then + repositories[repo_name] = Set.new + repositories[repo_name] << sig["name"] + else + repositories[repo_name] << sig["name"] + end + } + } +end +repositories.each_key { |repo| + if repositories[repo].length != 1 then + next if exp_set.include?(repo) + print repo, ": ", repositories[repo], "\n" + errors_found = errors_found + 1 + end +} +if errors_found == 0 then + print "No issues found. PASS!" +end +errors_found = 0 + +print "\n\nCheck 2: " +print "Repositories in src-openeuler or openeuler should not be managed by multiple SIGs.\n" +repositories = Hash.new +for s in sigs do + s[1].each { |sig| + next if sig["name"] == "Private" + sig["repositories"].each { |repo| + if repositories[repo] == nil then + repositories[repo] = Set.new + repositories[repo] << sig["name"] + elsif repositories[repo].include?(sig["name"]) + print repo, " has been managed by ", sig["name"], " more than 1 time.\n" + errors_found = errors_found + 1 + else + repositories[repo] << sig["name"] + end + } + } +end +repositories.each_key { |repo| + if repositories[repo].length != 1 then + next if exp_set.include?(repo) + print repo, ": ", repositories[repo], "\n" + errors_found = errors_found + 1 + end +} +if errors_found == 0 then + print "No issues found. PASS!" +end +errors_found = 0 + +print "\n\nCheck 3: " +print "We are working on reducing Private repos, this checking is purely informative.\n" +repositories = Hash.new +for s in sigs do + s[1].each { |sig| + sig["repositories"].each { |repo| + if repositories[repo] == nil then + repositories[repo] = Set.new + repositories[repo] << sig["name"] + else + repositories[repo] << sig["name"] + end + } + } +end + +print "There're ", repositories.length, " repositories in total.\n" +count = 0 +private_only = 0 +repositories.each_key { |repo| + if repositories[repo].length != 1 then + if repositories[repo].include?("Private") then + count = count + 1 + end + else + if repositories[repo].include?("Private") then + private_only = private_only + 1 + end + end +} +print "There're ", count, " repositories co-managed by Private\n" +print "There're ", private_only, " repositories managed by Private only\n" + +cross_checked_repo = Set.new + +print "\n\nCheck 4: " +print "repository/openeuler.yaml should be consisitent with sigs.yaml\n" +openeuler_repo_load = YAML.load(File.read("repository/openeuler.yaml")) +openeuler_repos = openeuler_repo_load["repositories"] +openeuler_repos.each { |openeuler_repo| + name = "openeuler/"+openeuler_repo["name"] + if cross_checked_repo.include?(name) then + print "Repository ", name, " in openeuler.yaml has duplication.\n" + errors_found = errors_found + 1 + end + if repositories[name] == nil then + next if exp_set.include?(name) + print "Repository ", name, " in openeuler.yaml cannot be found in sigs.yaml\n" + errors_found = errors_found + 1 + next + end + if openeuler_repo["type"] == "public" and repositories[name].include?("Private") then + print "Repository ", name, " marked as public in openeuler.yaml, but listed in Private SIG.\n" + errors_found = errors_found + 1 + end + if openeuler_repo["type"] == "private" and not repositories[name].include?("Private") then + print "Repository ", name, " marked as private in openeuler.yaml, but not listed in Private SIG.\n" + errors_found = errors_found + 1 + end + cross_checked_repo << name +} + +if errors_found == 0 then + print "No issues found. PASS!" +end +errors_found = 0 + +print "\n\nCheck 5: " +print "repository/src-openeuler.yaml should be consistent with sigs.yaml\n" +srcopeneuler_repo_load = YAML.load(File.read("repository/src-openeuler.yaml")) +srcopeneuler_repos = srcopeneuler_repo_load["repositories"] +srcopeneuler_repos.each { |srcopeneuler_repo| + name = "src-openeuler/"+srcopeneuler_repo["name"] + if cross_checked_repo.include?(name) then + print "Repository ", name, " in src-openeuler.yaml has duplication.\n" + errors_found = errors_found + 1 + end + if repositories[name] == nil then + print "Repository ", name, " in src-openeuler.yaml cannot be found in sigs.yaml\n" + errors_found = errors_found + 1 + next + end + if srcopeneuler_repo["type"] == "public" and repositories[name].include?("Private") then + print "Repository ", name, " marked as public in src-openeuler.yaml, but listed in Private SIG.\n" + errors_found = errors_found + 1 + end + if srcopeneuler_repo["type"] == "private" and not repositories[name].include?("Private") then + print "Repository ", name, " marked as private in src-openeuler.yaml, but not listed in Private SIG.\n" + errors_found = errors_found + 1 + end + cross_checked_repo << name +} + +if errors_found == 0 then + print "No issues found. PASS!" +end +errors_found = 0 + +print "\n\nCheck 6: " +print "All repositories in sigs.yaml must list in either openeuler.yaml or src-openeuler.yaml\n" + +if cross_checked_repo.length != repositories.length then + repositories.each_key { |n| + next if cross_checked_repo.include?(n) + print n, " listed in sigs.yaml, but neither openeuler.yaml nor src-openeuler.yaml\n" + errors_found = errors_found + 1 + } +end + +if errors_found == 0 then + print "No issues found. PASS!\n" +end -- Gitee From 2149e5e4a8d43bb31198f63ff2549ce0ca0cb15f Mon Sep 17 00:00:00 2001 From: Shinwell Hu Date: Mon, 1 Jun 2020 09:12:29 +0000 Subject: [PATCH 3/6] pylint issues fixing --- zh/technical-committee/governance/sanity_check.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/zh/technical-committee/governance/sanity_check.py b/zh/technical-committee/governance/sanity_check.py index ba12222c2..877241e87 100644 --- a/zh/technical-committee/governance/sanity_check.py +++ b/zh/technical-committee/governance/sanity_check.py @@ -1,4 +1,7 @@ #!/usr/bin/python3 +""" +This is a sanity checking tool for openEuler community database +""" import yaml import sys import argparse @@ -61,7 +64,7 @@ def check_2(sigs, exps): if len(v) != 1: if k in exps: continue - print(repo + ": " + v + "\n") + print(k + ": " + str(v) + "\n") errors_found = errors_found + 1 if errors_found == 0: @@ -100,7 +103,7 @@ def check_3(sigs): return supervisors -def check_4(sigs, exps, prefix, oe_repos, supervisors, cross_checked_repo): +def check_4(exps, prefix, oe_repos, supervisors, cross_checked_repo): """ YAML in repository/ should be consisitent with sigs.yaml """ @@ -198,11 +201,11 @@ if __name__ == "__main__": supervisors = check_3(sigs) print("\nCheck 4:") - issues, cross_checked_repo = check_4(sigs, exps, "openeuler", openeuler_repos, supervisors, cross_checked_repo) + issues, cross_checked_repo = check_4(exps, "openeuler", openeuler_repos, supervisors, cross_checked_repo) issues_found = issues_found + issues print("\nCheck 5:") - issues, cross_checked_repo = check_4(sigs, exps, "src-openeuler", srcopeneuler_repos, supervisors, cross_checked_repo) + issues, cross_checked_repo = check_4(exps, "src-openeuler", srcopeneuler_repos, supervisors, cross_checked_repo) issues_found = issues_found + issues print("\nCheck 6:") -- Gitee From 04760a83e43e9e3d141058a262a19e333865c454 Mon Sep 17 00:00:00 2001 From: Shinwell Hu Date: Tue, 2 Jun 2020 12:49:24 +0000 Subject: [PATCH 4/6] fix lint issues and remove ruby implmentation --- .../governance/sanity_check.py | 24 +-- .../governance/sanity_check.rb | 184 ------------------ 2 files changed, 12 insertions(+), 196 deletions(-) delete mode 100644 zh/technical-committee/governance/sanity_check.rb diff --git a/zh/technical-committee/governance/sanity_check.py b/zh/technical-committee/governance/sanity_check.py index 877241e87..0dbae3478 100644 --- a/zh/technical-committee/governance/sanity_check.py +++ b/zh/technical-committee/governance/sanity_check.py @@ -145,7 +145,7 @@ def check_6(cross_checked_repo, supervisors): if len(cross_checked_repo) != len(supervisors): for repo in supervisors: if not repo in cross_checked_repo: - print("WARNING! {name} listed in sigs.yaml, but neither openeuler.yaml nor src-openeuler.yaml".format(name=reop)) + print("WARNING! {name} listed in sigs.yaml, but neither openeuler.yaml nor src-openeuler.yaml".format(name=repo)) errors_found = errors_found + 1 if errors_found == 0: @@ -170,7 +170,7 @@ def load_yaml(d, f): if __name__ == "__main__": """ - Sanity check among different YAML database inside openEuler community + Sanity check among different YAML database inside openEuler community """ par = argparse.ArgumentParser() @@ -178,37 +178,37 @@ if __name__ == "__main__": args = par.parse_args() sigs_yaml = load_yaml(args.community, "sig/sigs.yaml") - sigs = sigs_yaml["sigs"] + sig_list = sigs_yaml["sigs"] known_exceptions_yaml = load_yaml(args.community, "zh/technical-committee/governance/exceptions.yaml") - exps = known_exceptions_yaml["exceptions"] + exception_list = known_exceptions_yaml["exceptions"] openeuler_repo_yaml = load_yaml(args.community, "repository/openeuler.yaml") openeuler_repos = openeuler_repo_yaml["repositories"] srcopeneuler_repo_yaml = load_yaml(args.community, "repository/src-openeuler.yaml") srcopeneuler_repos = srcopeneuler_repo_yaml["repositories"] - supervisors = {} - cross_checked_repo = set() + repo_supervisors = {} + repo_cross_checked = set() print("Sanity Check among different YAML database inside openEuler community.") issues_found = 0 print("\nCheck 1:") - issues_found = issues_found + check_1(sigs, exps) + issues_found = issues_found + check_1(sig_list, exception_list) print("\nCheck 2:") - issues_found = issues_found + check_2(sigs, exps) + issues_found = issues_found + check_2(sig_list, exception_list) print("\nCheck 3:") - supervisors = check_3(sigs) + repo_supervisors = check_3(sig_list) print("\nCheck 4:") - issues, cross_checked_repo = check_4(exps, "openeuler", openeuler_repos, supervisors, cross_checked_repo) + issues, repo_cross_checked = check_4(exception_list, "openeuler", openeuler_repos, repo_supervisors, repo_cross_checked) issues_found = issues_found + issues print("\nCheck 5:") - issues, cross_checked_repo = check_4(exps, "src-openeuler", srcopeneuler_repos, supervisors, cross_checked_repo) + issues, repo_cross_checked = check_4(exception_list, "src-openeuler", srcopeneuler_repos, repo_supervisors, repo_cross_checked) issues_found = issues_found + issues print("\nCheck 6:") - issues_found = issues_found + check_6(cross_checked_repo, supervisors) + issues_found = issues_found + check_6(repo_cross_checked, repo_supervisors) sys.exit(issues_found) diff --git a/zh/technical-committee/governance/sanity_check.rb b/zh/technical-committee/governance/sanity_check.rb deleted file mode 100644 index 0c32e7dc5..000000000 --- a/zh/technical-committee/governance/sanity_check.rb +++ /dev/null @@ -1,184 +0,0 @@ -#!/usr/bin/ruby -require 'yaml' -require 'set' - -errors_found = 0 - -sigs = YAML.load(File.read("sig/sigs.yaml")) -known_exceptions_load = YAML.load(File.read("zh/technical-committee/governance/exceptions.yaml")) -exp_set = Array.new known_exceptions_load["exceptions"] - -print "Sanity check among YAML databases inside openEuler community." - -print "\n\nCheck 1: " -print "Repository in src-openeuler and openeuler usually be managed by the same SIG.\n" -repositories = Hash.new -for s in sigs do - s[1].each { |sig| - next if sig["name"] == "Private" - sig["repositories"].each { |repo| - repo_name = repo.gsub("src-openeuler/", "").gsub("openeuler/", "") - if repositories[repo_name] == nil then - repositories[repo_name] = Set.new - repositories[repo_name] << sig["name"] - else - repositories[repo_name] << sig["name"] - end - } - } -end -repositories.each_key { |repo| - if repositories[repo].length != 1 then - next if exp_set.include?(repo) - print repo, ": ", repositories[repo], "\n" - errors_found = errors_found + 1 - end -} -if errors_found == 0 then - print "No issues found. PASS!" -end -errors_found = 0 - -print "\n\nCheck 2: " -print "Repositories in src-openeuler or openeuler should not be managed by multiple SIGs.\n" -repositories = Hash.new -for s in sigs do - s[1].each { |sig| - next if sig["name"] == "Private" - sig["repositories"].each { |repo| - if repositories[repo] == nil then - repositories[repo] = Set.new - repositories[repo] << sig["name"] - elsif repositories[repo].include?(sig["name"]) - print repo, " has been managed by ", sig["name"], " more than 1 time.\n" - errors_found = errors_found + 1 - else - repositories[repo] << sig["name"] - end - } - } -end -repositories.each_key { |repo| - if repositories[repo].length != 1 then - next if exp_set.include?(repo) - print repo, ": ", repositories[repo], "\n" - errors_found = errors_found + 1 - end -} -if errors_found == 0 then - print "No issues found. PASS!" -end -errors_found = 0 - -print "\n\nCheck 3: " -print "We are working on reducing Private repos, this checking is purely informative.\n" -repositories = Hash.new -for s in sigs do - s[1].each { |sig| - sig["repositories"].each { |repo| - if repositories[repo] == nil then - repositories[repo] = Set.new - repositories[repo] << sig["name"] - else - repositories[repo] << sig["name"] - end - } - } -end - -print "There're ", repositories.length, " repositories in total.\n" -count = 0 -private_only = 0 -repositories.each_key { |repo| - if repositories[repo].length != 1 then - if repositories[repo].include?("Private") then - count = count + 1 - end - else - if repositories[repo].include?("Private") then - private_only = private_only + 1 - end - end -} -print "There're ", count, " repositories co-managed by Private\n" -print "There're ", private_only, " repositories managed by Private only\n" - -cross_checked_repo = Set.new - -print "\n\nCheck 4: " -print "repository/openeuler.yaml should be consisitent with sigs.yaml\n" -openeuler_repo_load = YAML.load(File.read("repository/openeuler.yaml")) -openeuler_repos = openeuler_repo_load["repositories"] -openeuler_repos.each { |openeuler_repo| - name = "openeuler/"+openeuler_repo["name"] - if cross_checked_repo.include?(name) then - print "Repository ", name, " in openeuler.yaml has duplication.\n" - errors_found = errors_found + 1 - end - if repositories[name] == nil then - next if exp_set.include?(name) - print "Repository ", name, " in openeuler.yaml cannot be found in sigs.yaml\n" - errors_found = errors_found + 1 - next - end - if openeuler_repo["type"] == "public" and repositories[name].include?("Private") then - print "Repository ", name, " marked as public in openeuler.yaml, but listed in Private SIG.\n" - errors_found = errors_found + 1 - end - if openeuler_repo["type"] == "private" and not repositories[name].include?("Private") then - print "Repository ", name, " marked as private in openeuler.yaml, but not listed in Private SIG.\n" - errors_found = errors_found + 1 - end - cross_checked_repo << name -} - -if errors_found == 0 then - print "No issues found. PASS!" -end -errors_found = 0 - -print "\n\nCheck 5: " -print "repository/src-openeuler.yaml should be consistent with sigs.yaml\n" -srcopeneuler_repo_load = YAML.load(File.read("repository/src-openeuler.yaml")) -srcopeneuler_repos = srcopeneuler_repo_load["repositories"] -srcopeneuler_repos.each { |srcopeneuler_repo| - name = "src-openeuler/"+srcopeneuler_repo["name"] - if cross_checked_repo.include?(name) then - print "Repository ", name, " in src-openeuler.yaml has duplication.\n" - errors_found = errors_found + 1 - end - if repositories[name] == nil then - print "Repository ", name, " in src-openeuler.yaml cannot be found in sigs.yaml\n" - errors_found = errors_found + 1 - next - end - if srcopeneuler_repo["type"] == "public" and repositories[name].include?("Private") then - print "Repository ", name, " marked as public in src-openeuler.yaml, but listed in Private SIG.\n" - errors_found = errors_found + 1 - end - if srcopeneuler_repo["type"] == "private" and not repositories[name].include?("Private") then - print "Repository ", name, " marked as private in src-openeuler.yaml, but not listed in Private SIG.\n" - errors_found = errors_found + 1 - end - cross_checked_repo << name -} - -if errors_found == 0 then - print "No issues found. PASS!" -end -errors_found = 0 - -print "\n\nCheck 6: " -print "All repositories in sigs.yaml must list in either openeuler.yaml or src-openeuler.yaml\n" - -if cross_checked_repo.length != repositories.length then - repositories.each_key { |n| - next if cross_checked_repo.include?(n) - print n, " listed in sigs.yaml, but neither openeuler.yaml nor src-openeuler.yaml\n" - errors_found = errors_found + 1 - } -end - -if errors_found == 0 then - print "No issues found. PASS!\n" -end -- Gitee From 1a0135cfa54793dbb1889a7ca2eb182c7ea69b79 Mon Sep 17 00:00:00 2001 From: Shinwell Hu Date: Tue, 2 Jun 2020 13:10:53 +0000 Subject: [PATCH 5/6] fix lint issue --- .../governance/sanity_check.py | 3 - .../governance/sanity_check.rb | 164 ++++++++++++++++++ 2 files changed, 164 insertions(+), 3 deletions(-) create mode 100644 zh/technical-committee/governance/sanity_check.rb diff --git a/zh/technical-committee/governance/sanity_check.py b/zh/technical-committee/governance/sanity_check.py index 0dbae3478..ab7284857 100644 --- a/zh/technical-committee/governance/sanity_check.py +++ b/zh/technical-committee/governance/sanity_check.py @@ -169,9 +169,6 @@ def load_yaml(d, f): if __name__ == "__main__": - """ - Sanity check among different YAML database inside openEuler community - """ par = argparse.ArgumentParser() par.add_argument("community", type=str, help="Local path of community repository") diff --git a/zh/technical-committee/governance/sanity_check.rb b/zh/technical-committee/governance/sanity_check.rb new file mode 100644 index 000000000..bf942b1b5 --- /dev/null +++ b/zh/technical-committee/governance/sanity_check.rb @@ -0,0 +1,164 @@ +#!/usr/bin/ruby +require 'yaml' +require 'set' + +errors_found = 0 + +sigs = YAML.load(File.read("sig/sigs.yaml")) +known_exceptions_load = YAML.load(File.read("zh/technical-committee/governance/exceptions.yaml")) +exp_set = Array.new known_exceptions_load["exceptions"] + +print "Sanity Check among different YAML database inside openEuler community." + +print "\n\nCheck 1: " +print "Repository in src-openeuler and openeuler should be managed by the single SIG.\n" +repositories = Hash.new +for s in sigs do + s[1].each { |sig| + next if sig["name"] == "Private" + sig["repositories"].each { |repo| + repo_name = repo.gsub("src-openeuler/", "").gsub("openeuler/", "") + if repositories[repo_name] == nil then + repositories[repo_name] = Set.new + repositories[repo_name] << sig["name"] + else + repositories[repo_name] << sig["name"] + end + } + } +end +repositories.each_key { |repo| + if repositories[repo].length != 1 then + next if exp_set.include?(repo) + print repo, ": ", repositories[repo], "\n" + errors_found = errors_found + 1 + end +} + +print "\n\nCheck 2: " +print "Repository in src-openeuler or openeuler should never be duplicated.\n" +repositories = Hash.new +for s in sigs do + s[1].each { |sig| + next if sig["name"] == "Private" + sig["repositories"].each { |repo| + if repositories[repo] == nil then + repositories[repo] = Set.new + repositories[repo] << sig["name"] + elsif repositories[repo].include?(sig["name"]) + print repo, " has been managed by ", sig["name"], " more than 1 time.\n" + errors_found = errors_found + 1 + else + repositories[repo] << sig["name"] + end + } + } +end +repositories.each_key { |repo| + if repositories[repo].length != 1 then + next if exp_set.include?(repo) + print repo, ": ", repositories[repo], "\n" + errors_found = errors_found + 1 + end +} + +print "\n\nCheck 3: " +print "Repository managed by both SIG and Private.\n" +repositories = Hash.new +for s in sigs do + s[1].each { |sig| + sig["repositories"].each { |repo| + if repositories[repo] == nil then + repositories[repo] = Set.new + repositories[repo] << sig["name"] + else + repositories[repo] << sig["name"] + end + } + } +end + +print "There're ", repositories.length, " repositories in total.\n" +count = 0 +private_only = 0 +repositories.each_key { |repo| + if repositories[repo].length != 1 then + if repositories[repo].include?("Private") then + count = count + 1 + end + else + if repositories[repo].include?("Private") then + private_only = private_only + 1 + end + end +} +print "There're ", count, " repositories co-managed by Private\n" +print "There're ", private_only, " repositories managed by Private only\n" + +cross_checked_repo = Set.new + +print "\n\nCheck 4: " +print "repository/openeuler.yaml should be consisitent with sigs.yaml\n" +openeuler_repo_load = YAML.load(File.read("repository/openeuler.yaml")) +openeuler_repos = openeuler_repo_load["repositories"] +openeuler_repos.each { |openeuler_repo| + name = "openeuler/"+openeuler_repo["name"] + if cross_checked_repo.include?(name) then + print "Repository ", name, " in openeuler.yaml has duplication.\n" + errors_found = errors_found + 1 + end + if repositories[name] == nil then + next if exp_set.include?(name) + print "Repository ", name, " in openeuler.yaml cannot be found in sigs.yaml\n" + errors_found = errors_found + 1 + next + end + if openeuler_repo["type"] == "public" and repositories[name].include?("Private") then + print "Repository ", name, " marked as public in openeuler.yaml, but listed in Private SIG.\n" + errors_found = errors_found + 1 + end + if openeuler_repo["type"] == "private" and not repositories[name].include?("Private") then + print "Repository ", name, " marked as private in openeuler.yaml, but not listed in Private SIG.\n" + errors_found = errors_found + 1 + end + cross_checked_repo << name +} + +print "\n\nCheck 5: " +print "repository/src-openeuler.yaml should be consistent with sigs.yaml\n" +srcopeneuler_repo_load = YAML.load(File.read("repository/src-openeuler.yaml")) +srcopeneuler_repos = srcopeneuler_repo_load["repositories"] +srcopeneuler_repos.each { |srcopeneuler_repo| + name = "src-openeuler/"+srcopeneuler_repo["name"] + if cross_checked_repo.include?(name) then + print "Repository ", name, " in src-openeuler.yaml has duplication.\n" + errors_found = errors_found + 1 + end + if repositories[name] == nil then + print "Repository ", name, " in src-openeuler.yaml cannot be found in sigs.yaml\n" + errors_found = errors_found + 1 + next + end + if srcopeneuler_repo["type"] == "public" and repositories[name].include?("Private") then + print "Repository ", name, " marked as public in src-openeuler.yaml, but listed in Private SIG.\n" + errors_found = errors_found + 1 + end + if srcopeneuler_repo["type"] == "private" and not repositories[name].include?("Private") then + print "Repository ", name, " marked as private in src-openeuler.yaml, but not listed in Private SIG.\n" + errors_found = errors_found + 1 + end + cross_checked_repo << name +} + +print "\n\nCheck 6: " +print "All repositories in sigs.yaml must list in either openeuler.yaml or src-openeuler.yaml\n" + +if cross_checked_repo.length != repositories.length then + repositories.each_key { |n| + next if cross_checked_repo.include?(n) + print n, " listed in sigs.yaml, but neither openeuler.yaml nor src-openeuler.yaml\n" + errors_found = errors_found + 1 + } +end + +return errors_found -- Gitee From e4fe472db7e92acd14a927c6a93a8d2dd3e8b749 Mon Sep 17 00:00:00 2001 From: Shinwell Hu Date: Tue, 2 Jun 2020 13:16:11 +0000 Subject: [PATCH 6/6] fix lint issue --- .../governance/sanity_check.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/zh/technical-committee/governance/sanity_check.py b/zh/technical-committee/governance/sanity_check.py index ab7284857..8e082c1e2 100644 --- a/zh/technical-committee/governance/sanity_check.py +++ b/zh/technical-committee/governance/sanity_check.py @@ -118,14 +118,17 @@ def check_4(exps, prefix, oe_repos, supervisors, cross_checked_repo): errors_found = errors_found + 1 if not supervisors.get(name, False): if name not in exps: - print("WARNING! Repository {name} in {prefix}.yaml cannot be found in sigs.yaml".format(name=name, prefix=prefix)) + print("WARNING! Repository {name} in {prefix}.yaml cannot be found in sigs.yaml" + .format(name=name, prefix=prefix)) errors_found = errors_found + 1 if repo["type"] == "public" and "Private" in supervisors.get(name, set()): - print("WARNING! Repository {name} marked as public in {prefix}.yaml, but listed in Private SIG.".format(name=name, prefix=prefix)) + print("WARNING! Repository {name} marked as public in {prefix}.yaml, but listed in Private SIG." + .format(name=name, prefix=prefix)) errors_found = errors_found + 1 if repo["type"] == "private" and "Private" not in supervisors.get(name, set()): - print("WARNING! Repository {name} marked as private in {prefix}.yaml, but not listed in Private SIG.".format(name=name, prefix=prefix)) + print("WARNING! Repository {name} marked as private in {prefix}.yaml, but not listed in Private SIG." + .format(name=name, prefix=prefix)) errors_found = errors_found + 1 cross_checked_repo.add(name) @@ -145,7 +148,8 @@ def check_6(cross_checked_repo, supervisors): if len(cross_checked_repo) != len(supervisors): for repo in supervisors: if not repo in cross_checked_repo: - print("WARNING! {name} listed in sigs.yaml, but neither openeuler.yaml nor src-openeuler.yaml".format(name=repo)) + print("WARNING! {name} listed in sigs.yaml, but neither openeuler.yaml nor src-openeuler.yaml" + .format(name=repo)) errors_found = errors_found + 1 if errors_found == 0: @@ -198,11 +202,13 @@ if __name__ == "__main__": repo_supervisors = check_3(sig_list) print("\nCheck 4:") - issues, repo_cross_checked = check_4(exception_list, "openeuler", openeuler_repos, repo_supervisors, repo_cross_checked) + issues, repo_cross_checked = check_4(exception_list, "openeuler", + openeuler_repos, repo_supervisors, repo_cross_checked) issues_found = issues_found + issues print("\nCheck 5:") - issues, repo_cross_checked = check_4(exception_list, "src-openeuler", srcopeneuler_repos, repo_supervisors, repo_cross_checked) + issues, repo_cross_checked = check_4(exception_list, "src-openeuler", + srcopeneuler_repos, repo_supervisors, repo_cross_checked) issues_found = issues_found + issues print("\nCheck 6:") -- Gitee