Files
platformio-core/platformio/commands/run.py

48 lines
1.6 KiB
Python
Raw Normal View History

2014-06-03 21:27:36 +03:00
# Copyright (C) Ivan Kravets <me@ikravets.com>
# See LICENSE for details.
from click import command, echo, option, secho, style
2014-06-03 21:27:36 +03:00
2014-06-16 12:07:37 +03:00
from platformio.exception import ProjectEnvsNotAvaialable, UndefinedEnvPlatform
from platformio.platforms._base import PlatformFactory
from platformio.util import get_project_config
2014-06-03 21:27:36 +03:00
@command("run", short_help="Process project environments")
@option("--environment", "-e", multiple=True, metavar="<environment>")
@option("--target", "-t", multiple=True, metavar="<target>")
2014-06-03 21:27:36 +03:00
def cli(environment, target):
2014-06-03 21:27:36 +03:00
config = get_project_config()
if not config.sections():
2014-06-16 12:07:37 +03:00
raise ProjectEnvsNotAvaialable()
2014-06-03 21:27:36 +03:00
for section in config.sections():
if section[:4] != "env:":
continue
envname = section[4:]
2014-06-03 21:27:36 +03:00
if environment and envname not in environment:
echo("Skipped %s environment" % style(envname, fg="yellow"))
continue
echo("Processing %s environment:" % style(envname, fg="cyan"))
variables = ["%s=%s" % (o.upper(), v) for o, v in config.items(section)
if o != "targets"]
variables.append("PIOENV=" + envname)
envtargets = []
if target:
envtargets = [t for t in target]
elif config.has_option(section, "targets"):
envtargets = config.get(section, "targets").split()
if not config.has_option(section, "platform"):
raise UndefinedEnvPlatform(envname)
p = PlatformFactory().newPlatform(config.get(section, "platform"))
result = p.run(variables, envtargets)
secho(result['out'], fg="green")
secho(result['err'], fg="red")