joey shelton / LED_Demo

Dependencies:   MAX44000 PWM_Tone_Library nexpaq_mdk

Fork of LED_Demo by Maxim nexpaq

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 import sys
00020 from os.path import isdir, abspath, dirname, join
00021 from os import _exit
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.build_api import get_config
00030 from config import Config
00031 from utils import argparse_filestring_type
00032 try:
00033     import tools.private_settings as ps
00034 except:
00035     ps = object()
00036 
00037 if __name__ == '__main__':
00038     # Parse Options
00039     parser = get_default_options_parser(add_clean=False, add_options=False)
00040     parser.add_argument("--source", dest="source_dir", type=argparse_filestring_type, required=True,
00041                         default=[], help="The source (input) directory", action="append")
00042     parser.add_argument("--prefix", dest="prefix", action="append",
00043                       default=[], help="Restrict listing to parameters that have this prefix")
00044     parser.add_argument("-v", "--verbose", action="store_true", dest="verbose",
00045                       default=False, help="Verbose diagnostic output")
00046 
00047     options = parser.parse_args()
00048 
00049     # Target
00050     if options.mcu is None :
00051         args_error(parser, "argument -m/--mcu is required")
00052     target = options.mcu[0]
00053 
00054     # Toolchain
00055     if options.tool is None:
00056         args_error(parser, "argument -t/--toolchain is required")
00057     toolchain = options.tool[0]
00058 
00059     options.prefix = options.prefix or [""]
00060 
00061     try:
00062         params, macros, features = get_config(options.source_dir, target, toolchain)
00063         if not params and not macros:
00064             print "No configuration data available."
00065             _exit(0)
00066         if params:
00067             print "Configuration parameters"
00068             print "------------------------"
00069             for p in params:
00070                 for s in options.prefix:
00071                     if p.startswith(s):
00072                         print(str(params[p]) if not options.verbose else params[p].get_verbose_description())
00073                         break
00074             print ""
00075 
00076         print "Macros"
00077         print "------"
00078         if macros:
00079             print 'Defined with "macros":', Config.config_macros_to_macros(macros)
00080         print "Generated from configuration parameters:", Config.parameters_to_macros(params)
00081 
00082     except KeyboardInterrupt, e:
00083         print "\n[CTRL+c] exit"
00084     except Exception,e:
00085         if options.verbose:
00086             import traceback
00087             traceback.print_exc(file=sys.stdout)
00088         else:
00089             print "[ERROR] %s" % str(e)
00090 
00091         sys.exit(1)