Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 93 additions & 6 deletions bin/update_depths.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ def write_line_break(self, data=None):
if len(self.indents) == 1:
super().write_line_break()


def increase_indent(self, flow=False, indentless=False):
return super(MyDumper, self).increase_indent(flow, False)
return super(CustomDumper, self).increase_indent(flow, False)


def split_line(line):
Expand Down Expand Up @@ -155,7 +156,7 @@ def process_depth(splitted_merge, branchname, main_branch, main_branch_name, rep
stdout=PIPE,
stderr=PIPE,
)
.stdout.decode("utf-8")
.stderr.decode("utf-8")
.replace("\n", "")
)
if not lastrev:
Expand All @@ -182,13 +183,67 @@ def process_depth(splitted_merge, branchname, main_branch, main_branch_name, rep
# Should log/print some error here.
return 1024

def has_connection(remote, repo_path):
os.chdir(repo_path)
import pudb
pudb.set_trace()
exit_code = (
run(
[
"git",
"ls-remote",
"--heads",
"--exit-code",
"".join([remote]) ,
],
stdout=PIPE,
stderr=PIPE,
)
)
std_error = exit_code.stderr.decode("utf-8").replace("\n", "")
if std_error != '':
return False
return True
def branch_exists(remote, splitted_merge, branchname, repo_path):
os.chdir(repo_path)
# make sure we have the latest available.
run(
[
"git",
"fetch",
splitted_merge[0],
branchname,
],
stdout=PIPE,
stderr=PIPE,
)
exit_code = (
run(
[
"git",
"ls-remote",
"--heads",
"--exit-code",
"".join([remote]) ,
"refs/heads/"+ branchname,
],
stdout=PIPE,
stderr=PIPE,
)
.stdout.decode("utf-8")
.replace("\n", "")
)
if exit_code == '':
return False
return True

def main():
"""
parsing directly repos.yaml, if something is not in addons.yaml, branch will still
be in folder, but may not be included in addons. Nothing changes.
"""
changes = ''
removals = ''
with open(REPOS_YAML) as yaml_file:
for doc in yaml.safe_load_all(yaml_file):
for repo in doc:
Expand All @@ -211,9 +266,36 @@ def main():
merge_type = get_merge_type(splitted_merge, repo)
branchname = get_branchname(splitted_merge, merge_type)
if branchname:
# if branchname does not exist , comment out and do next merge
remote = doc[repo]['remotes'][splitted_merge[0]]
# before checking if branch exists , we check if
# connection is accessible. This will avoid commenting out all
# merges if there is no connection or server down.
connected =has_connection(remote, repo_path)
exists = branch_exists(
remote, splitted_merge, branchname, repo_path)
if not exists and connected:
# before commenting out we check connection again.
# merge does not exist, comment it out and continue
index = doc[repo]['merges'].index(merge)
print("# Removing and dumping in comment section non-existing merge %s from repo %s \n " % (doc[repo]['merges'][index] , doc[repo]))
import pudb
pudb.set_trace()
msg = "# Removing and dumping in comment section non-existing merge %s from repo %s , remote: %s \n " % (
"- " + " ".join(splitted_merge) ,
repo,
":".join(list([x for x in doc[repo]['remotes'].items() if x[0] == splitted_merge[0]][-1])
))
print(msg)
changes += msg
removals += msg
del doc[repo]['merges'][index]
continue


# compute depth only for merges with branchname
min_depth = process_depth(
splitted_merge,
splitted_merge,
branchname,
main_branch,
main_branch_name,
Expand All @@ -237,27 +319,32 @@ def main():
waft_depth = os.environ.get("WAFT_DEPTH_DEFAULT") or 1
waft_depth = int(waft_depth)
if repo_min_depth[repo] > waft_depth:
changes += ("\n\t Increasing depth of %s from %s to %s"
changes += ("# Increasing depth of %s from %s to %s \n"
% (
repo,
doc[repo]["defaults"]["depth"],
str(repo_min_depth[repo]),
)
)
doc[repo]["defaults"]["depth"] = repo_min_depth[repo]

import pudb
pudb.set_trace()
CustomDumper.add_representer(
dict, CustomDumper.represent_dict_preserve_order
)

if changes:
print("========Applying Depth changes to repos.yaml:")
print("========Applying Depth changes and merged branch cleanup to repos.yaml:")
print(changes)
print("=======================================")
yaml_file = open(REPOS_YAML, "w")
yaml_file.write(yaml.dump(doc, Dumper=CustomDumper, default_flow_style=False))
yaml_file.write(removals)
yaml_file.close()




if os.path.isfile(REPOS_YAML) and __name__ == "__main__":
main()
else:
Expand Down