Anders Blomdell / mbed-sdk-tools
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers get_config.py Source File

get_config.py

00001 #! /usr/bin/env python2
00002 """
00003 mbed SDK
00004 Copyright (c) 2011-2013 ARM Limited
00005 
00006 Licensed under the Apache License, Version 2.0 (the "License");
00007 you may not use this file except in compliance with the License.
00008 You may obtain a copy of the License at
00009 
00010     http://www.apache.org/licenses/LICENSE-2.0
00011 
00012 Unless required by applicable law or agreed to in writing, software
00013 distributed under the License is distributed on an "AS IS" BASIS,
00014 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015 See the License for the specific language governing permissions and
00016 limitations under the License.
00017 
00018 """
00019 from __future__ import print_function
00020 import sys
00021 from os.path import abspath, dirname, join
00022 
00023 # Be sure that the tools directory is in the search path
00024 ROOT = abspath(join(dirname(__file__), ".."))
00025 sys.path.insert(0, ROOT)
00026 
00027 from tools.utils import args_error
00028 from tools.options import get_default_options_parser
00029 from tools.options import extract_mcus
00030 from tools.build_api import get_config
00031 from tools.config import Config
00032 from tools.utils import argparse_filestring_type
00033 
00034 if __name__ == '__main__':
00035     # Parse Options
00036     parser = get_default_options_parser(add_clean=False, add_options=False,
00037                                         add_app_config=True)
00038     parser.add_argument(
00039         "--source", dest="source_dir", type=argparse_filestring_type,
00040         required=True, default=[], help="The source (input) directory",
00041         action="append")
00042     parser.add_argument(
00043         "--prefix", dest="prefix", action="append", default=[],
00044         help="Restrict listing to parameters that have this prefix")
00045     parser.add_argument(
00046         "-v", "--verbose", action="store_true", dest="verbose", default=False,
00047         help="Verbose diagnostic output")
00048 
00049     options = parser.parse_args()
00050 
00051     # Target
00052     if options.mcu is None :
00053         args_error(parser, "argument -m/--mcu is required")
00054     target = extract_mcus(parser, options)[0]
00055 
00056     options.prefix = options.prefix or [""]
00057 
00058     try:
00059         params, macros, features = get_config(
00060             options.source_dir,
00061             target,
00062             options.tool[0] if options.tool else None,
00063             app_config=options.app_config
00064         )
00065         if not params and not macros:
00066             print("No configuration data available.")
00067             sys.exit(0)
00068         if params:
00069             print("Configuration parameters")
00070             print("------------------------")
00071             for p in sorted(list(params.keys())):
00072                 if any(p.startswith(s) for s in options.prefix):
00073                     if options.verbose:
00074                         print(params[p].get_verbose_description())
00075                     else:
00076                         print(str(params[p]))
00077             print("")
00078 
00079         print("Macros")
00080         print("------")
00081         for m in Config.config_macros_to_macros(macros):
00082             if any(m.startswith(s) for s in options.prefix):
00083                 print(m)
00084 
00085     except KeyboardInterrupt as e:
00086         print("\n[CTRL+c] exit")
00087     except Exception as e:
00088         if options.verbose:
00089             import traceback
00090             traceback.print_exc(file=sys.stdout)
00091         else:
00092             print("[ERROR] %s" % str(e))
00093 
00094         sys.exit(1)