From fc5774131c210e5619f7f623da5ced930971aa08 Mon Sep 17 00:00:00 2001 From: Bogdan Marinescu Date: Wed, 11 Sep 2013 14:57:06 +0100 Subject: [PATCH] More changes to the synchronization script 1. added the possibility to redirect stderr to stdout in utils.run_cmd 2. synch.py now calls the above run_cmd in redirect mode instead of the old 'cmd' that doesn't intercept standard streams. This makes it easier for an external tool to intercept the output of 'hg'. --- workspace_tools/synch.py | 20 ++++++++++++-------- workspace_tools/utils.py | 6 +++--- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/workspace_tools/synch.py b/workspace_tools/synch.py index 4db00ceda7..afe6ae6a02 100644 --- a/workspace_tools/synch.py +++ b/workspace_tools/synch.py @@ -33,7 +33,7 @@ sys.path.append(ROOT) from workspace_tools.settings import MBED_ORG_PATH, MBED_ORG_USER, BUILD_DIR from workspace_tools.paths import LIB_DIR -from workspace_tools.utils import cmd, run_cmd +from workspace_tools.utils import run_cmd MBED_URL = "mbed.org" @@ -111,6 +111,11 @@ def ignore_path(name, reg_exps): class MbedOfficialRepository: URL = "http://" + MBED_URL + "/users/mbed_official/code/%s/" + + @staticmethod + def run_and_print(command, cwd): + stdout, _, _ = run_cmd(command, wd=cwd, redirect=True) + print(stdout) def __init__(self, name): self.name = name @@ -121,21 +126,20 @@ class MbedOfficialRepository: if not exists(MBED_ORG_PATH): makedirs(MBED_ORG_PATH) - cmd(['hg', 'clone', MbedOfficialRepository.URL % name], cwd=MBED_ORG_PATH) + self.run_and_print(['hg', 'clone', MbedOfficialRepository.URL % name], cwd=MBED_ORG_PATH) else: # Update - cmd(['hg', 'pull'], cwd=self.path) - cmd(['hg', 'update'], cwd=self.path) + self.run_and_print(['hg', 'pull'], cwd=self.path) + self.run_and_print(['hg', 'update'], cwd=self.path) def publish(self): # The maintainer has to evaluate the changes first and explicitly accept them - cmd(['hg', 'addremove'], cwd=self.path) + self.run_and_print(['hg', 'addremove'], cwd=self.path) stdout, _, _ = run_cmd(['hg', 'status'], wd=self.path) if stdout == '': print "No changes" return False - print stdout if quiet: commit = 'Y' @@ -145,9 +149,9 @@ class MbedOfficialRepository: args = ['hg', 'commit', '-u', MBED_ORG_USER] if commit_msg: args = args + ['-m', commit_msg] - cmd(args, cwd=self.path) + self.run_and_print(args, cwd=self.path) if push_remote: - cmd(['hg', 'push'], cwd=self.path) + self.run_and_print(['hg', 'push'], cwd=self.path) return True # Check if a file is a text file or a binary file diff --git a/workspace_tools/utils.py b/workspace_tools/utils.py index ebcc36adb6..3995f0c918 100644 --- a/workspace_tools/utils.py +++ b/workspace_tools/utils.py @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. """ import sys -from subprocess import Popen, PIPE, call +from subprocess import Popen, PIPE, STDOUT, call from os import listdir, remove, makedirs from os.path import isdir, join, exists, split, relpath, splitext from shutil import copyfile @@ -31,8 +31,8 @@ def cmd(l, check=True, verbose=False, shell=False, cwd=None): raise Exception('ERROR %d: "%s"' % (rc, text)) -def run_cmd(command, wd=None): - p = Popen(command, stdout=PIPE, stderr=PIPE, cwd=wd) +def run_cmd(command, wd=None, redirect=False): + p = Popen(command, stdout=PIPE, stderr=STDOUT if redirect else PIPE, cwd=wd) stdout, stderr = p.communicate() return stdout, stderr, p.returncode