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'.
pull/64/merge
Bogdan Marinescu 2013-09-11 14:57:06 +01:00
parent 162aad2072
commit fc5774131c
2 changed files with 15 additions and 11 deletions

View File

@ -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

View File

@ -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