[sysadmin-bin] Add run_command wrapper
- From: Bartłomiej Piotrowski <bpiotrowski src gnome org>
- To: gnome-sysadmin gnome org,commits-list gnome org
- Subject: [sysadmin-bin] Add run_command wrapper
- Date: Tue, 29 Oct 2019 07:53:04 +0000 (UTC)
commit 8cf241d59d84ad73a12ab566817c7fa686c1eb51
Author: Bartłomiej Piotrowski <bpiotrowski gnome org>
Date: Tue Oct 29 08:52:49 2019 +0100
Add run_command wrapper
git/post-receive-mirror-github | 24 +++++++++++++++++++++---
1 file changed, 21 insertions(+), 3 deletions(-)
---
diff --git a/git/post-receive-mirror-github b/git/post-receive-mirror-github
index f6e86af..ee076d4 100755
--- a/git/post-receive-mirror-github
+++ b/git/post-receive-mirror-github
@@ -192,6 +192,24 @@ def get_doap_settings(repo_name):
"branches": branches,
}
+
+def run_command(command):
+ try:
+ out = tempfile.NamedTemporaryFile(prefix="github",suffix="std")
+ err = tempfile.NamedTemporaryFile(prefix="github",suffix="err")
+ subprocess.check_call(shlex.split(command), stderr=err, stdout=out)
+ out.close()
+ err.close()
+ except subprocess.CalledProcessError:
+ out = open(out.name, "r")
+ err = open(err.name, "r")
+ error_msg = """
+Error trying to run command
+
+{}
+"""
+ raise Exception(error_msg.format(command))
+
def main():
repo_name = get_repo_name()
@@ -218,17 +236,17 @@ def main():
github_repo_name = gh.normalize_name(repo_name)
push_command = "git push --force git github com:{}/{} {}:mainline {}"
command = push_command.format(gh.organization, github_repo_name, doap_settings['default_branch'], "
".join(refs))
- subprocess.run(command, shell=True, check=True)
+ run_command(command)
if github_settings['default_branch'] != "mainline":
gh.update_github_repo(repo_name, 'default_branch', "mainline")
github_branches = gh.get_branches(repo_name)
if 'master' in github_branches:
- subprocess.run("git push --force git github com:{}/{} :master".format(gh.organization,
github_repo_name), shell=True, check=True)
+ run_command("git push --force git github com:{}/{} :master".format(gh.organization,
github_repo_name))
for org in ADITIONAL_ORGANIZATIONS.get(repo_name, []):
- subprocess.run("git push --mirror git github com:{}/{}".format(org, github_repo_name), shell=True,
check=True)
+ run_command("git push --mirror git github com:{}/{}".format(org, github_repo_name))
if __name__ == "__main__":
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]