Skip to content

Commit b28d081

Browse files
committed
Fix up subprocess calls
subprocess.call() does not by default return a status value. Update the commands to add shell=True which forces a return value. Also convert the commands to a single string rather than a list as this plays more nicely with both linux and windows. Also fix a spurious :
1 parent a7c777d commit b28d081

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

tools/test/examples/examples_lib.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,10 @@ def source_repos(config, examples):
168168
if os.path.exists(name):
169169
print("'%s' example directory already exists. Deleting..." % name)
170170
rmtree(name)
171+
172+
cmd = "mbed-cli import %s" %repo_info['repo']
173+
result = subprocess.call(cmd, shell=True)
171174

172-
result = subprocess.call(["mbed-cli", "import", repo_info['repo']])
173175
if result:
174176
return result
175177

@@ -191,8 +193,9 @@ def clone_repos(config, examples , retry = 3):
191193
if os.path.exists(name):
192194
print("'%s' example directory already exists. Deleting..." % name)
193195
rmtree(name)
196+
cmd = "%s clone %s" %(repo_info['type'], repo_info['repo'])
194197
for i in range(0, retry):
195-
if subprocess.call([repo_info['type'], "clone", repo_info['repo']]) == 0:
198+
if not subprocess.call(cmd, shell=True):
196199
break
197200
else:
198201
print("ERROR : unable to clone the repo {}".format(name))
@@ -213,7 +216,7 @@ def deploy_repos(config, examples):
213216
if name in examples:
214217
if os.path.exists(name):
215218
os.chdir(name)
216-
result = subprocess.call(["mbed-cli", "deploy"])
219+
result = subprocess.call("mbed-cli deploy", shell=True)
217220
os.chdir("..")
218221
if result:
219222
print("mbed-cli deploy command failed for '%s'" % name)
@@ -415,10 +418,11 @@ def update_mbedos_version(config, tag, examples):
415418
update_dir = basename(repo_info['repo']) + "/mbed-os"
416419
print("\nChanging dir to %s\n" % update_dir)
417420
os.chdir(update_dir)
418-
result = subprocess.call(["mbed-cli", "update", tag, "--clean"])
421+
cmd = "mbed-cli update %s --clean" %tag
422+
result = subprocess.call(cmd, shell=True)
419423
os.chdir("../..")
420424
if result:
421-
return result:
425+
return result
422426

423427
return 0
424428

0 commit comments

Comments
 (0)