Make examples commands return a failure

Currently the following commands in examples.py,
do_import()
do_deploy()
do_versionning()
do_clone()

all return a success status (ie 0) irrespective of any errors
originating from their sub-functions.

This PR fixes this. Now these commands will return one of:
0 - success
1 - general failure
x - failure returned by a subprocess.call function
pull/8605/head
adbridge 2018-10-31 17:40:15 +00:00
parent 56293af0e7
commit a7c777d5c1
2 changed files with 23 additions and 12 deletions

View File

@ -97,20 +97,17 @@ def do_export(args, config, examples):
def do_import(_, config, examples):
"""Do the import step of this process"""
lib.source_repos(config, examples)
return 0
return lib.source_repos(config, examples)
def do_clone(_, config, examples):
"""Do the clone step of this process"""
lib.clone_repos(config, examples)
return 0
return lib.clone_repos(config, examples)
def do_deploy(_, config, examples):
"""Do the deploy step of this process"""
lib.deploy_repos(config, examples)
return 0
return lib.deploy_repos(config, examples)
def do_compile(args, config, examples):
@ -125,8 +122,7 @@ def do_compile(args, config, examples):
def do_versionning(args, config, examples):
""" Test update the mbed-os to the version specified by the tag """
lib.update_mbedos_version(config, args.tag, examples)
return 0
return lib.update_mbedos_version(config, args.tag, examples)
if __name__ == "__main__":

View File

@ -169,7 +169,11 @@ def source_repos(config, examples):
print("'%s' example directory already exists. Deleting..." % name)
rmtree(name)
subprocess.call(["mbed-cli", "import", repo_info['repo']])
result = subprocess.call(["mbed-cli", "import", repo_info['repo']])
if result:
return result
return 0
def clone_repos(config, examples , retry = 3):
""" Clones each of the repos associated with the specific examples name from the
@ -192,6 +196,8 @@ def clone_repos(config, examples , retry = 3):
break
else:
print("ERROR : unable to clone the repo {}".format(name))
return 1
return 0
def deploy_repos(config, examples):
""" If the example directory exists as provided by the json config file,
@ -207,11 +213,15 @@ def deploy_repos(config, examples):
if name in examples:
if os.path.exists(name):
os.chdir(name)
subprocess.call(["mbed-cli", "deploy"])
result = subprocess.call(["mbed-cli", "deploy"])
os.chdir("..")
if result:
print("mbed-cli deploy command failed for '%s'" % name)
return result
else:
print("'%s' example directory doesn't exist. Skipping..." % name)
return 1
return 0
def get_num_failures(results, export=False):
""" Returns the number of failed compilations from the results summary
@ -405,5 +415,10 @@ def update_mbedos_version(config, tag, examples):
update_dir = basename(repo_info['repo']) + "/mbed-os"
print("\nChanging dir to %s\n" % update_dir)
os.chdir(update_dir)
subprocess.call(["mbed-cli", "update", tag, "--clean"])
result = subprocess.call(["mbed-cli", "update", tag, "--clean"])
os.chdir("../..")
if result:
return result:
return 0