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

View File

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