nkjnm
Dependencies: MAX44000 nexpaq_mdk
Fork of LED_Demo by
mbd_os/tools/get_config.py@7:3a65ef12ba31, 2016-11-04 (annotated)
- Committer:
- nitsshukla
- Date:
- Fri Nov 04 12:06:04 2016 +0000
- Revision:
- 7:3a65ef12ba31
- Parent:
- 1:55a6170b404f
kghj;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nexpaq | 1:55a6170b404f | 1 | #! /usr/bin/env python2 |
nexpaq | 1:55a6170b404f | 2 | """ |
nexpaq | 1:55a6170b404f | 3 | mbed SDK |
nexpaq | 1:55a6170b404f | 4 | Copyright (c) 2011-2013 ARM Limited |
nexpaq | 1:55a6170b404f | 5 | |
nexpaq | 1:55a6170b404f | 6 | Licensed under the Apache License, Version 2.0 (the "License"); |
nexpaq | 1:55a6170b404f | 7 | you may not use this file except in compliance with the License. |
nexpaq | 1:55a6170b404f | 8 | You may obtain a copy of the License at |
nexpaq | 1:55a6170b404f | 9 | |
nexpaq | 1:55a6170b404f | 10 | http://www.apache.org/licenses/LICENSE-2.0 |
nexpaq | 1:55a6170b404f | 11 | |
nexpaq | 1:55a6170b404f | 12 | Unless required by applicable law or agreed to in writing, software |
nexpaq | 1:55a6170b404f | 13 | distributed under the License is distributed on an "AS IS" BASIS, |
nexpaq | 1:55a6170b404f | 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
nexpaq | 1:55a6170b404f | 15 | See the License for the specific language governing permissions and |
nexpaq | 1:55a6170b404f | 16 | limitations under the License. |
nexpaq | 1:55a6170b404f | 17 | |
nexpaq | 1:55a6170b404f | 18 | """ |
nexpaq | 1:55a6170b404f | 19 | import sys |
nexpaq | 1:55a6170b404f | 20 | from os.path import isdir, abspath, dirname, join |
nexpaq | 1:55a6170b404f | 21 | from os import _exit |
nexpaq | 1:55a6170b404f | 22 | |
nexpaq | 1:55a6170b404f | 23 | # Be sure that the tools directory is in the search path |
nexpaq | 1:55a6170b404f | 24 | ROOT = abspath(join(dirname(__file__), "..")) |
nexpaq | 1:55a6170b404f | 25 | sys.path.insert(0, ROOT) |
nexpaq | 1:55a6170b404f | 26 | |
nexpaq | 1:55a6170b404f | 27 | from tools.utils import args_error |
nexpaq | 1:55a6170b404f | 28 | from tools.options import get_default_options_parser |
nexpaq | 1:55a6170b404f | 29 | from tools.build_api import get_config |
nexpaq | 1:55a6170b404f | 30 | from config import Config |
nexpaq | 1:55a6170b404f | 31 | from utils import argparse_filestring_type |
nexpaq | 1:55a6170b404f | 32 | try: |
nexpaq | 1:55a6170b404f | 33 | import tools.private_settings as ps |
nexpaq | 1:55a6170b404f | 34 | except: |
nexpaq | 1:55a6170b404f | 35 | ps = object() |
nexpaq | 1:55a6170b404f | 36 | |
nexpaq | 1:55a6170b404f | 37 | if __name__ == '__main__': |
nexpaq | 1:55a6170b404f | 38 | # Parse Options |
nexpaq | 1:55a6170b404f | 39 | parser = get_default_options_parser(add_clean=False, add_options=False) |
nexpaq | 1:55a6170b404f | 40 | parser.add_argument("--source", dest="source_dir", type=argparse_filestring_type, required=True, |
nexpaq | 1:55a6170b404f | 41 | default=[], help="The source (input) directory", action="append") |
nexpaq | 1:55a6170b404f | 42 | parser.add_argument("--prefix", dest="prefix", action="append", |
nexpaq | 1:55a6170b404f | 43 | default=[], help="Restrict listing to parameters that have this prefix") |
nexpaq | 1:55a6170b404f | 44 | parser.add_argument("-v", "--verbose", action="store_true", dest="verbose", |
nexpaq | 1:55a6170b404f | 45 | default=False, help="Verbose diagnostic output") |
nexpaq | 1:55a6170b404f | 46 | |
nexpaq | 1:55a6170b404f | 47 | options = parser.parse_args() |
nexpaq | 1:55a6170b404f | 48 | |
nexpaq | 1:55a6170b404f | 49 | # Target |
nexpaq | 1:55a6170b404f | 50 | if options.mcu is None : |
nexpaq | 1:55a6170b404f | 51 | args_error(parser, "argument -m/--mcu is required") |
nexpaq | 1:55a6170b404f | 52 | target = options.mcu[0] |
nexpaq | 1:55a6170b404f | 53 | |
nexpaq | 1:55a6170b404f | 54 | # Toolchain |
nexpaq | 1:55a6170b404f | 55 | if options.tool is None: |
nexpaq | 1:55a6170b404f | 56 | args_error(parser, "argument -t/--toolchain is required") |
nexpaq | 1:55a6170b404f | 57 | toolchain = options.tool[0] |
nexpaq | 1:55a6170b404f | 58 | |
nexpaq | 1:55a6170b404f | 59 | options.prefix = options.prefix or [""] |
nexpaq | 1:55a6170b404f | 60 | |
nexpaq | 1:55a6170b404f | 61 | try: |
nexpaq | 1:55a6170b404f | 62 | params, macros, features = get_config(options.source_dir, target, toolchain) |
nexpaq | 1:55a6170b404f | 63 | if not params and not macros: |
nexpaq | 1:55a6170b404f | 64 | print "No configuration data available." |
nexpaq | 1:55a6170b404f | 65 | _exit(0) |
nexpaq | 1:55a6170b404f | 66 | if params: |
nexpaq | 1:55a6170b404f | 67 | print "Configuration parameters" |
nexpaq | 1:55a6170b404f | 68 | print "------------------------" |
nexpaq | 1:55a6170b404f | 69 | for p in params: |
nexpaq | 1:55a6170b404f | 70 | for s in options.prefix: |
nexpaq | 1:55a6170b404f | 71 | if p.startswith(s): |
nexpaq | 1:55a6170b404f | 72 | print(str(params[p]) if not options.verbose else params[p].get_verbose_description()) |
nexpaq | 1:55a6170b404f | 73 | break |
nexpaq | 1:55a6170b404f | 74 | print "" |
nexpaq | 1:55a6170b404f | 75 | |
nexpaq | 1:55a6170b404f | 76 | print "Macros" |
nexpaq | 1:55a6170b404f | 77 | print "------" |
nexpaq | 1:55a6170b404f | 78 | if macros: |
nexpaq | 1:55a6170b404f | 79 | print 'Defined with "macros":', Config.config_macros_to_macros(macros) |
nexpaq | 1:55a6170b404f | 80 | print "Generated from configuration parameters:", Config.parameters_to_macros(params) |
nexpaq | 1:55a6170b404f | 81 | |
nexpaq | 1:55a6170b404f | 82 | except KeyboardInterrupt, e: |
nexpaq | 1:55a6170b404f | 83 | print "\n[CTRL+c] exit" |
nexpaq | 1:55a6170b404f | 84 | except Exception,e: |
nexpaq | 1:55a6170b404f | 85 | if options.verbose: |
nexpaq | 1:55a6170b404f | 86 | import traceback |
nexpaq | 1:55a6170b404f | 87 | traceback.print_exc(file=sys.stdout) |
nexpaq | 1:55a6170b404f | 88 | else: |
nexpaq | 1:55a6170b404f | 89 | print "[ERROR] %s" % str(e) |
nexpaq | 1:55a6170b404f | 90 | |
nexpaq | 1:55a6170b404f | 91 | sys.exit(1) |