Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed-os
Diff: neo.py
- Revision:
- 8:1a673572accd
- Parent:
- 7:caeff556648e
- Child:
- 9:6066c45a1655
--- a/neo.py Tue Mar 29 23:47:28 2016 -0500 +++ b/neo.py Wed Mar 30 00:30:25 2016 -0500 @@ -7,6 +7,7 @@ import os import contextlib import collections +import shutil # Subparser handling parser = argparse.ArgumentParser() @@ -19,11 +20,15 @@ for arg in args: if arg.endswith('?'): subparser.add_argument(arg.strip('?'), nargs='?') + elif arg.endswith('*'): + pass else: subparser.add_argument(arg) def thunk(parsed_args): - ordered_args = [vars(parsed_args)[arg.strip('?')] for arg in args] + ordered_args = [vars(parsed_args)[arg.strip('?*')] + if not arg.endswith('*') else remainder + for arg in args] return command(*ordered_args) subparser.set_defaults(command=thunk) @@ -34,16 +39,16 @@ class ProcessException(Exception): pass -def popen(command, stdin=None): +def popen(command, stdin=None, **kwargs): # print for debugging print ' '.join(command) - proc = subprocess.Popen(command) + proc = subprocess.Popen(command, **kwargs) if proc.wait() != 0: raise ProcessException(proc.returncode) -def pquery(command, stdin=None): - proc = subprocess.Popen(command, stdout=subprocess.PIPE) +def pquery(command, stdin=None, **kwargs): + proc = subprocess.Popen(command, stdout=subprocess.PIPE, **kwargs) stdout, _ = proc.communicate(stdin) if proc.returncode != 0: @@ -162,7 +167,7 @@ import_(url, lib) # Install/uninstall command -@subcommand('add', 'url', 'name?' +@subcommand('add', 'url', 'name?', help='add a library to the current repository') def add(url, name): cwd = Repo() @@ -205,20 +210,23 @@ popen([cwd.type, 'add', repo.lib]) # Compile command -@subcommand('compile', 'toolchain', 'target', +@subcommand('compile', 'args*', help='compile project using workspace_tools') -def compile(toolchain, target): +def compile(args): cwd = Repo() + if not os.path.isfile('mbed_settings.py'): + shutil.copy('mbed-os/tools/settings.py', 'mbed_settings.py') + + env = os.environ.copy() + env['PYTHONPATH'] = '.' popen(['python', 'mbed-os/tools/make.py', '--source=%s' % cwd.path, - '--build=%s' % os.path.join(cwd.path, '.build'), - '-D', 'YOTTA_CFG', '-D', 'YOTTA_CONFIG', - '-D', 'TARGET_LIKE_MBED', '-D', 'TARGET_LIKE_CORTEX_M4', - '-t', toolchain.upper(), '-m', target.upper(), '-j', '0']) + '--build=%s' % os.path.join(cwd.path, '.build')] + args, + env=env) # Parse/run command -args = parser.parse_args() +args, remainder = parser.parse_known_args() status = args.command(args) sys.exit(status or 0)