From d2f9932bfe0f31e8e6bec6773d33338f3f52ae2c Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Wed, 21 Dec 2011 16:23:31 +0000 Subject: [PATCH] Remove the commands module and use subprocess. Change-Id: I791a79c510da92f51120974f3c765e05bedfea8e --- git-review | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/git-review b/git-review index 66e1690..3911905 100755 --- a/git-review +++ b/git-review @@ -16,7 +16,6 @@ implied. See the License for the specific language governing permissions and limitations under the License.""" -import commands import optparse import urllib import json @@ -29,6 +28,8 @@ import os import sys import time import re +import shlex +import subprocess version = "1.7" @@ -42,17 +43,22 @@ _branch_name = None _has_color = None -def run_command(cmd, status=False): +def run_command(cmd, status=False, env={}): if VERBOSE: print "Running:", cmd - stat, out = commands.getstatusoutput(cmd) + cmd_list = shlex.split(cmd) + newenv = os.environ + newenv.update(env) + p = subprocess.Popen(cmd_list, stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, env=newenv) + (out, nothing) = p.communicate() if status: - return (stat, out) - return out + return (p.returncode, out.strip()) + return out.strip() -def run_command_status(cmd): - return run_command(cmd, True) +def run_command_status(cmd, env={}): + return run_command(cmd, True, env) def update_latest_version(version_file_path): @@ -115,7 +121,7 @@ def set_hooks_commit_msg(remote): if not os.access(target_file, os.X_OK): os.chmod(target_file, os.path.stat.S_IREAD | os.path.stat.S_IEXEC) - run_command("GIT_EDITOR=true git commit --amend") + run_command("git commit --amend", env=dict(GIT_EDITOR='true')) def test_remote(username, hostname, port, project): @@ -321,8 +327,8 @@ def rebase_changes(branch, remote): print output return False - cmd = "GIT_EDITOR=true git rebase -i %s" % remote_branch - (status, output) = run_command_status(cmd) + cmd = "git rebase -i %s" % remote_branch + (status, output) = run_command_status(cmd, env=dict(GIT_EDITOR='true')) if status != 0: print "Errors running %s" % cmd print output