Skip to content

Commit fc57741

Browse files
author
Bogdan Marinescu
committed
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'.
1 parent 162aad2 commit fc57741

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

workspace_tools/synch.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
from workspace_tools.settings import MBED_ORG_PATH, MBED_ORG_USER, BUILD_DIR
3535
from workspace_tools.paths import LIB_DIR
36-
from workspace_tools.utils import cmd, run_cmd
36+
from workspace_tools.utils import run_cmd
3737

3838
MBED_URL = "mbed.org"
3939

@@ -111,6 +111,11 @@ def ignore_path(name, reg_exps):
111111

112112
class MbedOfficialRepository:
113113
URL = "http://" + MBED_URL + "/users/mbed_official/code/%s/"
114+
115+
@staticmethod
116+
def run_and_print(command, cwd):
117+
stdout, _, _ = run_cmd(command, wd=cwd, redirect=True)
118+
print(stdout)
114119

115120
def __init__(self, name):
116121
self.name = name
@@ -121,21 +126,20 @@ def __init__(self, name):
121126
if not exists(MBED_ORG_PATH):
122127
makedirs(MBED_ORG_PATH)
123128

124-
cmd(['hg', 'clone', MbedOfficialRepository.URL % name], cwd=MBED_ORG_PATH)
129+
self.run_and_print(['hg', 'clone', MbedOfficialRepository.URL % name], cwd=MBED_ORG_PATH)
125130

126131
else:
127132
# Update
128-
cmd(['hg', 'pull'], cwd=self.path)
129-
cmd(['hg', 'update'], cwd=self.path)
133+
self.run_and_print(['hg', 'pull'], cwd=self.path)
134+
self.run_and_print(['hg', 'update'], cwd=self.path)
130135

131136
def publish(self):
132137
# The maintainer has to evaluate the changes first and explicitly accept them
133-
cmd(['hg', 'addremove'], cwd=self.path)
138+
self.run_and_print(['hg', 'addremove'], cwd=self.path)
134139
stdout, _, _ = run_cmd(['hg', 'status'], wd=self.path)
135140
if stdout == '':
136141
print "No changes"
137142
return False
138-
139143
print stdout
140144
if quiet:
141145
commit = 'Y'
@@ -145,9 +149,9 @@ def publish(self):
145149
args = ['hg', 'commit', '-u', MBED_ORG_USER]
146150
if commit_msg:
147151
args = args + ['-m', commit_msg]
148-
cmd(args, cwd=self.path)
152+
self.run_and_print(args, cwd=self.path)
149153
if push_remote:
150-
cmd(['hg', 'push'], cwd=self.path)
154+
self.run_and_print(['hg', 'push'], cwd=self.path)
151155
return True
152156

153157
# Check if a file is a text file or a binary file

workspace_tools/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
limitations under the License.
1616
"""
1717
import sys
18-
from subprocess import Popen, PIPE, call
18+
from subprocess import Popen, PIPE, STDOUT, call
1919
from os import listdir, remove, makedirs
2020
from os.path import isdir, join, exists, split, relpath, splitext
2121
from shutil import copyfile
@@ -31,8 +31,8 @@ def cmd(l, check=True, verbose=False, shell=False, cwd=None):
3131
raise Exception('ERROR %d: "%s"' % (rc, text))
3232

3333

34-
def run_cmd(command, wd=None):
35-
p = Popen(command, stdout=PIPE, stderr=PIPE, cwd=wd)
34+
def run_cmd(command, wd=None, redirect=False):
35+
p = Popen(command, stdout=PIPE, stderr=STDOUT if redirect else PIPE, cwd=wd)
3636
stdout, stderr = p.communicate()
3737

3838
return stdout, stderr, p.returncode

0 commit comments

Comments
 (0)