2014-06-03 21:27:36 +03:00
|
|
|
# Copyright (C) Ivan Kravets <me@ikravets.com>
|
|
|
|
# See LICENSE for details.
|
|
|
|
|
2014-06-07 13:34:31 +03:00
|
|
|
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
|
2014-06-12 23:29:47 +03:00
|
|
|
from platformio.platforms._base import PlatformFactory
|
2014-06-07 13:34:31 +03:00
|
|
|
from platformio.util import get_project_config
|
2014-06-03 21:27:36 +03:00
|
|
|
|
|
|
|
|
|
|
|
@command("run", short_help="Process project environments")
|
2014-06-12 21:17:45 +03:00
|
|
|
@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-07 13:34:31 +03:00
|
|
|
|
2014-06-03 21:27:36 +03:00
|
|
|
config = get_project_config()
|
2014-06-12 21:17:45 +03:00
|
|
|
|
|
|
|
if not config.sections():
|
2014-06-16 12:07:37 +03:00
|
|
|
raise ProjectEnvsNotAvaialable()
|
2014-06-12 21:17:45 +03:00
|
|
|
|
2014-06-03 21:27:36 +03:00
|
|
|
for section in config.sections():
|
|
|
|
if section[:4] != "env:":
|
|
|
|
continue
|
|
|
|
|
2014-06-07 13:34:31 +03:00
|
|
|
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()
|
|
|
|
|
2014-06-07 13:34:31 +03:00
|
|
|
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")
|