forked from platformio/platformio-core
Code improvements
This commit is contained in:
@ -19,7 +19,7 @@ def cli(ctx, environment, target, upload_port):
|
|||||||
config = get_project_config()
|
config = get_project_config()
|
||||||
|
|
||||||
if not config.sections():
|
if not config.sections():
|
||||||
raise exception.ProjectEnvsNotAvaialable()
|
raise exception.ProjectEnvsNotAvailable()
|
||||||
|
|
||||||
unknown = set(environment) - set([s[4:] for s in config.sections()])
|
unknown = set(environment) - set([s[4:] for s in config.sections()])
|
||||||
if unknown:
|
if unknown:
|
||||||
@ -40,34 +40,41 @@ def cli(ctx, environment, target, upload_port):
|
|||||||
click.echo("Processing %s environment:" %
|
click.echo("Processing %s environment:" %
|
||||||
click.style(envname, fg="cyan"))
|
click.style(envname, fg="cyan"))
|
||||||
|
|
||||||
variables = ["PIOENV=" + envname]
|
options = {}
|
||||||
if upload_port:
|
|
||||||
variables.append("UPLOAD_PORT=%s" % upload_port)
|
|
||||||
for k, v in config.items(section):
|
for k, v in config.items(section):
|
||||||
k = k.upper()
|
options[k] = v
|
||||||
if k == "TARGETS" or (k == "UPLOAD_PORT" and upload_port):
|
process_environment(ctx, envname, options, target, upload_port)
|
||||||
continue
|
|
||||||
variables.append("%s=%s" % (k.upper(), v))
|
|
||||||
|
|
||||||
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"):
|
def process_environment(ctx, name, options, targets, upload_port):
|
||||||
raise exception.UndefinedEnvPlatform(envname)
|
variables = ["PIOENV=" + name]
|
||||||
platform = config.get(section, "platform")
|
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
|
if "platform" not in options:
|
||||||
click.confirm("The platform '%s' has not been installed yet. "
|
raise exception.UndefinedEnvPlatform(name)
|
||||||
"Would you like to install it now?" % platform)):
|
platform = options['platform']
|
||||||
ctx.invoke(cmd_install, platforms=[platform])
|
|
||||||
|
|
||||||
p = PlatformFactory.newPlatform(platform)
|
telemetry.on_run_environment(options, envtargets)
|
||||||
result = p.run(variables, envtargets)
|
|
||||||
click.secho(result['out'], fg="green")
|
if (platform not in PlatformFactory.get_platforms(installed=True) and
|
||||||
click.secho(result['err'],
|
click.confirm("The platform '%s' has not been installed yet. "
|
||||||
fg="red" if "Error" in result['err'] else "yellow")
|
"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")
|
||||||
|
@ -83,7 +83,7 @@ class ProjectInitialized(PlatformioException):
|
|||||||
"Process it with `platformio run` command")
|
"Process it with `platformio run` command")
|
||||||
|
|
||||||
|
|
||||||
class ProjectEnvsNotAvaialable(PlatformioException):
|
class ProjectEnvsNotAvailable(PlatformioException):
|
||||||
|
|
||||||
MESSAGE = "Please setup environments in `platformio.ini` file."
|
MESSAGE = "Please setup environments in `platformio.ini` file."
|
||||||
|
|
||||||
|
@ -121,8 +121,8 @@ class PackageManager(object):
|
|||||||
current_version = installed[name]['version']
|
current_version = installed[name]['version']
|
||||||
latest_version = self.get_info(name)['version']
|
latest_version = self.get_info(name)['version']
|
||||||
|
|
||||||
click.echo("Versions: Current=%d, Latest=%d \t " % (
|
click.echo("Versions: Current=%d, Latest=%d \t " %
|
||||||
current_version, latest_version), nl=False)
|
(current_version, latest_version), nl=False)
|
||||||
|
|
||||||
if current_version == latest_version:
|
if current_version == latest_version:
|
||||||
click.echo("[%s]" % (click.style("Up-to-date", fg="green")))
|
click.echo("[%s]" % (click.style("Up-to-date", fg="green")))
|
||||||
|
@ -135,9 +135,9 @@ def on_command(ctx): # pylint: disable=W0613
|
|||||||
|
|
||||||
|
|
||||||
def on_run_environment(options, targets):
|
def on_run_environment(options, targets):
|
||||||
opts = ["%s=%s" % (opt, value) for opt, value in sorted(options)]
|
opts = ["%s=%s" % (opt, value) for opt, value in sorted(options.items())]
|
||||||
targets = [t.title() for t in targets or ["run"]]
|
targets = [t.title() for t in targets or ["run"]]
|
||||||
on_event("Env", " ".join(targets), " ".join(opts))
|
on_event("Env", " ".join(targets), "&".join(opts))
|
||||||
|
|
||||||
|
|
||||||
def on_event(category, action, label=None, value=None, screen_name=None):
|
def on_event(category, action, label=None, value=None, screen_name=None):
|
||||||
|
@ -22,8 +22,6 @@ except ImportError:
|
|||||||
|
|
||||||
|
|
||||||
def get_systype():
|
def get_systype():
|
||||||
if system() == "Windows":
|
|
||||||
return "windows"
|
|
||||||
data = uname()
|
data = uname()
|
||||||
return ("%s_%s" % (data[0], data[4])).lower()
|
return ("%s_%s" % (data[0], data[4])).lower()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user