mirror of https://github.com/ARMmbed/mbed-os.git
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
parent
162aad2072
commit
fc5774131c
|
@ -33,7 +33,7 @@ sys.path.append(ROOT)
|
||||||
|
|
||||||
from workspace_tools.settings import MBED_ORG_PATH, MBED_ORG_USER, BUILD_DIR
|
from workspace_tools.settings import MBED_ORG_PATH, MBED_ORG_USER, BUILD_DIR
|
||||||
from workspace_tools.paths import LIB_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"
|
MBED_URL = "mbed.org"
|
||||||
|
|
||||||
|
@ -112,6 +112,11 @@ def ignore_path(name, reg_exps):
|
||||||
class MbedOfficialRepository:
|
class MbedOfficialRepository:
|
||||||
URL = "http://" + MBED_URL + "/users/mbed_official/code/%s/"
|
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):
|
def __init__(self, name):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.path = join(MBED_ORG_PATH, name)
|
self.path = join(MBED_ORG_PATH, name)
|
||||||
|
@ -121,21 +126,20 @@ class MbedOfficialRepository:
|
||||||
if not exists(MBED_ORG_PATH):
|
if not exists(MBED_ORG_PATH):
|
||||||
makedirs(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:
|
else:
|
||||||
# Update
|
# Update
|
||||||
cmd(['hg', 'pull'], cwd=self.path)
|
self.run_and_print(['hg', 'pull'], cwd=self.path)
|
||||||
cmd(['hg', 'update'], cwd=self.path)
|
self.run_and_print(['hg', 'update'], cwd=self.path)
|
||||||
|
|
||||||
def publish(self):
|
def publish(self):
|
||||||
# The maintainer has to evaluate the changes first and explicitly accept them
|
# 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)
|
stdout, _, _ = run_cmd(['hg', 'status'], wd=self.path)
|
||||||
if stdout == '':
|
if stdout == '':
|
||||||
print "No changes"
|
print "No changes"
|
||||||
return False
|
return False
|
||||||
|
|
||||||
print stdout
|
print stdout
|
||||||
if quiet:
|
if quiet:
|
||||||
commit = 'Y'
|
commit = 'Y'
|
||||||
|
@ -145,9 +149,9 @@ class MbedOfficialRepository:
|
||||||
args = ['hg', 'commit', '-u', MBED_ORG_USER]
|
args = ['hg', 'commit', '-u', MBED_ORG_USER]
|
||||||
if commit_msg:
|
if commit_msg:
|
||||||
args = args + ['-m', commit_msg]
|
args = args + ['-m', commit_msg]
|
||||||
cmd(args, cwd=self.path)
|
self.run_and_print(args, cwd=self.path)
|
||||||
if push_remote:
|
if push_remote:
|
||||||
cmd(['hg', 'push'], cwd=self.path)
|
self.run_and_print(['hg', 'push'], cwd=self.path)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# Check if a file is a text file or a binary file
|
# Check if a file is a text file or a binary file
|
||||||
|
|
|
@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
"""
|
"""
|
||||||
import sys
|
import sys
|
||||||
from subprocess import Popen, PIPE, call
|
from subprocess import Popen, PIPE, STDOUT, call
|
||||||
from os import listdir, remove, makedirs
|
from os import listdir, remove, makedirs
|
||||||
from os.path import isdir, join, exists, split, relpath, splitext
|
from os.path import isdir, join, exists, split, relpath, splitext
|
||||||
from shutil import copyfile
|
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))
|
raise Exception('ERROR %d: "%s"' % (rc, text))
|
||||||
|
|
||||||
|
|
||||||
def run_cmd(command, wd=None):
|
def run_cmd(command, wd=None, redirect=False):
|
||||||
p = Popen(command, stdout=PIPE, stderr=PIPE, cwd=wd)
|
p = Popen(command, stdout=PIPE, stderr=STDOUT if redirect else PIPE, cwd=wd)
|
||||||
stdout, stderr = p.communicate()
|
stdout, stderr = p.communicate()
|
||||||
|
|
||||||
return stdout, stderr, p.returncode
|
return stdout, stderr, p.returncode
|
||||||
|
|
Loading…
Reference in New Issue