[sysadmin-bin] Add run_command wrapper



commit ded7c67c0ade43870f6184ff349a2d4ac9085534
Author: Bartłomiej Piotrowski <bpiotrowski gnome org>
Date:   Tue Oct 29 09:18:41 2019 +0100

    Add run_command wrapper
    
    This reverts commit 8d4a76521a2c88778de1f3a63715cf05d8d46755.

 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 4e42600..235a504 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]