Greg Steiert / maxim_dev

Dependents:   sensomed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers examples.py Source File

examples.py

00001 """ import and bulid a bunch of example programs """
00002 
00003 from argparse import ArgumentParser
00004 import os
00005 from os.path import dirname, abspath, basename
00006 import os.path
00007 import sys
00008 import subprocess
00009 import json
00010 
00011 ROOT = abspath(dirname(dirname(dirname(dirname(__file__)))))
00012 sys.path.insert(0, ROOT)
00013 
00014 from tools.utils import argparse_force_uppercase_type
00015 import examples_lib as lib
00016 from examples_lib import SUPPORTED_TOOLCHAINS, SUPPORTED_IDES
00017 
00018 EXAMPLES = json.load(open(os.path.join(os.path.dirname(__file__),
00019                                        "examples.json")))
00020 
00021 
00022 def main ():
00023     """Entry point"""
00024     parser = ArgumentParser()
00025     parser.add_argument("-c", dest="config", default="examples.json")
00026     subparsers = parser.add_subparsers()
00027     import_cmd = subparsers.add_parser("import")
00028     import_cmd.set_defaults(fn=do_import)
00029     version_cmd = subparsers.add_parser("tag")
00030     version_cmd.add_argument("tag")
00031     version_cmd.set_defaults(fn=do_versionning)
00032     compile_cmd = subparsers.add_parser("compile")
00033     compile_cmd.set_defaults(fn=do_compile),
00034     compile_cmd.add_argument(
00035         "toolchains", nargs="*", default=SUPPORTED_TOOLCHAINS,
00036         type=argparse_force_uppercase_type(SUPPORTED_TOOLCHAINS,
00037                                            "toolchain")),
00038     export_cmd = subparsers.add_parser("export")
00039     export_cmd.set_defaults(fn=do_export),
00040     export_cmd.add_argument(
00041         "ide", nargs="*", default=SUPPORTED_IDES,
00042         type=argparse_force_uppercase_type(SUPPORTED_IDES,
00043                                            "ide"))
00044     args = parser.parse_args()
00045     config = json.load(open(os.path.join(os.path.dirname(__file__),
00046                                args.config)))
00047     return args.fn(args, config)
00048 
00049 
00050 def do_export (args, config):
00051     """Do export and build step"""
00052     results = {}
00053     results = lib.export_repos(config, args.ide)
00054 
00055     lib.print_summary(results, export=True)
00056     failures = lib.get_num_failures(results, export=True)
00057     print("Number of failures = %d" % failures)
00058     return failures
00059 
00060 
00061 def do_import (_, config):
00062     """Do the import step of this process"""
00063     lib.source_repos(config)
00064     return 0
00065 
00066 
00067 def do_compile (args, config):
00068     """Do the compile step"""
00069     results = {}
00070     results = lib.compile_repos(config, args.toolchains)
00071     
00072     lib.print_summary(results)
00073     failures = lib.get_num_failures(results)
00074     print("Number of failures = %d" % failures)
00075     return failures 
00076     
00077 def do_versionning (args, config):
00078     """ Test update the mbed-os to the version specified by the tag """
00079     lib.update_mbedos_version(config, args.tag)        
00080     return 0
00081 
00082 
00083 if __name__ == "__main__":
00084     sys.exit(main())