Code improvements

This commit is contained in:
Ivan Kravets
2014-12-04 23:17:45 +02:00
parent 8596d271a2
commit d8863d1861
5 changed files with 38 additions and 33 deletions

View File

@@ -19,7 +19,7 @@ def cli(ctx, environment, target, upload_port):
config = get_project_config()
if not config.sections():
raise exception.ProjectEnvsNotAvaialable()
raise exception.ProjectEnvsNotAvailable()
unknown = set(environment) - set([s[4:] for s in config.sections()])
if unknown:
@@ -40,34 +40,41 @@ def cli(ctx, environment, target, upload_port):
click.echo("Processing %s environment:" %
click.style(envname, fg="cyan"))
variables = ["PIOENV=" + envname]
if upload_port:
variables.append("UPLOAD_PORT=%s" % upload_port)
options = {}
for k, v in config.items(section):
k = k.upper()
if k == "TARGETS" or (k == "UPLOAD_PORT" and upload_port):
continue
variables.append("%s=%s" % (k.upper(), v))
options[k] = v
process_environment(ctx, envname, options, target, upload_port)
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 exception.UndefinedEnvPlatform(envname)
platform = config.get(section, "platform")
def process_environment(ctx, name, options, targets, upload_port):
variables = ["PIOENV=" + name]
if upload_port:
variables.append("UPLOAD_PORT=%s" % upload_port)
for k, v in options.items():
k = k.upper()
if k == "TARGETS" or (k == "UPLOAD_PORT" and upload_port):
continue
variables.append("%s=%s" % (k.upper(), v))
telemetry.on_run_environment(config.items(section), envtargets)
envtargets = []
if targets:
envtargets = [t for t in targets]
elif "targets" in options:
envtargets = options['targets'].split()
if (platform not in PlatformFactory.get_platforms(installed=True) and
click.confirm("The platform '%s' has not been installed yet. "
"Would you like to install it now?" % platform)):
ctx.invoke(cmd_install, platforms=[platform])
if "platform" not in options:
raise exception.UndefinedEnvPlatform(name)
platform = options['platform']
p = PlatformFactory.newPlatform(platform)
result = p.run(variables, envtargets)
click.secho(result['out'], fg="green")
click.secho(result['err'],
fg="red" if "Error" in result['err'] else "yellow")
telemetry.on_run_environment(options, envtargets)
if (platform not in PlatformFactory.get_platforms(installed=True) and
click.confirm("The platform '%s' has not been installed yet. "
"Would you like to install it now?" % platform)):
ctx.invoke(cmd_install, platforms=[platform])
p = PlatformFactory.newPlatform(platform)
result = p.run(variables, envtargets)
click.secho(result['out'], fg="green")
click.secho(result['err'],
fg="red" if "Error" in result['err'] else "yellow")