forked from platformio/platformio-core
Cleanup click-based source code
This commit is contained in:
1 parent
affb47b82e
commit
8596d271a2
13 files changed
+139
-130
No files matched your search
@@ -1,20 +1,20 @@
|
||||
# Copyright (C) Ivan Kravets <me@ikravets.com>
|
||||
# See LICENSE for details.
|
||||
|
||||
from click import argument, command, option, secho
|
||||
import click
|
||||
|
||||
from platformio.platforms.base import PlatformFactory
|
||||
|
||||
|
||||
@command("install", short_help="Install new platforms")
|
||||
@argument("platforms", nargs=-1)
|
||||
@option("--with-package", multiple=True, metavar="<package>")
|
||||
@option("--without-package", multiple=True, metavar="<package>")
|
||||
@option("--skip-default-package", is_flag=True)
|
||||
@click.command("install", short_help="Install new platforms")
|
||||
@click.argument("platforms", nargs=-1)
|
||||
@click.option("--with-package", multiple=True, metavar="<package>")
|
||||
@click.option("--without-package", multiple=True, metavar="<package>")
|
||||
@click.option("--skip-default-package", is_flag=True)
|
||||
def cli(platforms, with_package, without_package, skip_default_package):
|
||||
|
||||
for platform in platforms:
|
||||
p = PlatformFactory().newPlatform(platform)
|
||||
p = PlatformFactory.newPlatform(platform)
|
||||
if p.install(with_package, without_package, skip_default_package):
|
||||
secho("The platform '%s' has been successfully installed!" %
|
||||
platform, fg="green")
|
||||
click.secho("The platform '%s' has been successfully installed!" %
|
||||
platform, fg="green")
|
||||
@@ -1,12 +1,12 @@
|
||||
# Copyright (C) Ivan Kravets <me@ikravets.com>
|
||||
# See LICENSE for details.
|
||||
|
||||
from click import command, echo, style
|
||||
import click
|
||||
|
||||
from platformio.platforms.base import PlatformFactory
|
||||
|
||||
|
||||
@command("list", short_help="List installed platforms")
|
||||
@click.command("list", short_help="List installed platforms")
|
||||
def cli():
|
||||
|
||||
installed_platforms = PlatformFactory.get_platforms(
|
||||
@@ -14,8 +14,8 @@ def cli():
|
||||
installed_platforms.sort()
|
||||
|
||||
for platform in installed_platforms:
|
||||
p = PlatformFactory().newPlatform(platform)
|
||||
echo("{name:<20} with packages: {pkgs}".format(
|
||||
name=style(p.get_name(), fg="cyan"),
|
||||
p = PlatformFactory.newPlatform(platform)
|
||||
click.echo("{name:<20} with packages: {pkgs}".format(
|
||||
name=click.style(p.get_name(), fg="cyan"),
|
||||
pkgs=", ".join(p.get_installed_packages())
|
||||
))
|
||||
+21
-17
@@ -1,43 +1,44 @@
|
||||
# Copyright (C) Ivan Kravets <me@ikravets.com>
|
||||
# See LICENSE for details.
|
||||
|
||||
from click import command, echo, option, secho, style
|
||||
import click
|
||||
|
||||
from platformio import telemetry
|
||||
from platformio.exception import (InvalidEnvName, ProjectEnvsNotAvaialable,
|
||||
UndefinedEnvPlatform, UnknownEnvNames)
|
||||
from platformio import exception, telemetry
|
||||
from platformio.commands.install import cli as cmd_install
|
||||
from platformio.platforms.base import PlatformFactory
|
||||
from platformio.util import get_project_config
|
||||
|
||||
|
||||
@command("run", short_help="Process project environments")
|
||||
@option("--environment", "-e", multiple=True, metavar="<environment>")
|
||||
@option("--target", "-t", multiple=True, metavar="<target>")
|
||||
@option("--upload-port", metavar="<upload port>")
|
||||
def cli(environment, target, upload_port):
|
||||
@click.command("run", short_help="Process project environments")
|
||||
@click.option("--environment", "-e", multiple=True, metavar="<environment>")
|
||||
@click.option("--target", "-t", multiple=True, metavar="<target>")
|
||||
@click.option("--upload-port", metavar="<upload port>")
|
||||
@click.pass_context
|
||||
def cli(ctx, environment, target, upload_port):
|
||||
|
||||
config = get_project_config()
|
||||
|
||||
if not config.sections():
|
||||
raise ProjectEnvsNotAvaialable()
|
||||
raise exception.ProjectEnvsNotAvaialable()
|
||||
|
||||
unknown = set(environment) - set([s[4:] for s in config.sections()])
|
||||
if unknown:
|
||||
raise UnknownEnvNames(", ".join(unknown))
|
||||
raise exception.UnknownEnvNames(", ".join(unknown))
|
||||
|
||||
for section in config.sections():
|
||||
# skip main configuration section
|
||||
if section == "platformio":
|
||||
continue
|
||||
elif section[:4] != "env:":
|
||||
raise InvalidEnvName(section)
|
||||
raise exception.InvalidEnvName(section)
|
||||
|
||||
envname = section[4:]
|
||||
if environment and envname not in environment:
|
||||
# echo("Skipped %s environment" % style(envname, fg="yellow"))
|
||||
continue
|
||||
|
||||
echo("Processing %s environment:" % style(envname, fg="cyan"))
|
||||
click.echo("Processing %s environment:" %
|
||||
click.style(envname, fg="cyan"))
|
||||
|
||||
variables = ["PIOENV=" + envname]
|
||||
if upload_port:
|
||||
@@ -55,7 +56,8 @@ def cli(environment, target, upload_port):
|
||||
envtargets = config.get(section, "targets").split()
|
||||
|
||||
if not config.has_option(section, "platform"):
|
||||
raise UndefinedEnvPlatform(envname)
|
||||
raise exception.UndefinedEnvPlatform(envname)
|
||||
platform = config.get(section, "platform")
|
||||
|
||||
telemetry.on_run_environment(config.items(section), envtargets)
|
||||
|
||||
@@ -63,7 +65,9 @@ def cli(environment, target, upload_port):
|
||||
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)
|
||||
secho(result['out'], fg="green")
|
||||
secho(result['err'],
|
||||
fg="red" if "Error" in result['err'] else "yellow")
|
||||
click.secho(result['out'], fg="green")
|
||||
click.secho(result['err'],
|
||||
fg="red" if "Error" in result['err'] else "yellow")
|
||||
@@ -1,16 +1,16 @@
|
||||
# Copyright (C) Ivan Kravets <me@ikravets.com>
|
||||
# See LICENSE for details.
|
||||
|
||||
from click import argument, command, echo, style
|
||||
import click
|
||||
|
||||
from platformio.platforms.base import PlatformFactory
|
||||
|
||||
|
||||
@command("search", short_help="Search for development platforms")
|
||||
@argument("query", required=False)
|
||||
@click.command("search", short_help="Search for development platforms")
|
||||
@click.argument("query", required=False)
|
||||
def cli(query):
|
||||
for platform in PlatformFactory.get_platforms().keys():
|
||||
p = PlatformFactory().newPlatform(platform)
|
||||
p = PlatformFactory.newPlatform(platform)
|
||||
name = p.get_name()
|
||||
shinfo = p.get_short_info()
|
||||
|
||||
@@ -21,5 +21,5 @@ def cli(query):
|
||||
if query and query.lower() not in search_data.lower():
|
||||
continue
|
||||
|
||||
echo("{name:<20} - {info}".format(name=style(name, fg="cyan"),
|
||||
info=shinfo))
|
||||
click.echo("{name:<20} - {info}".format(
|
||||
name=click.style(name, fg="cyan"), info=shinfo))
|
||||
@@ -3,13 +3,13 @@
|
||||
|
||||
import sys
|
||||
|
||||
from click import Choice, echo, group, option, secho
|
||||
import click
|
||||
from serial.tools import miniterm
|
||||
|
||||
from platformio.util import get_serialports
|
||||
|
||||
|
||||
@group(short_help="List or Monitor Serial ports")
|
||||
@click.group(short_help="List or Monitor Serial ports")
|
||||
def cli():
|
||||
pass
|
||||
|
||||
@@ -18,48 +18,49 @@ def cli():
|
||||
def serialports_list():
|
||||
|
||||
for item in get_serialports():
|
||||
secho(item['port'], fg="cyan")
|
||||
echo("----------")
|
||||
echo("Hardware ID: %s" % item['hwid'])
|
||||
echo("Description: %s" % item['description'])
|
||||
echo("")
|
||||
click.secho(item['port'], fg="cyan")
|
||||
click.echo("----------")
|
||||
click.echo("Hardware ID: %s" % item['hwid'])
|
||||
click.echo("Description: %s" % item['description'])
|
||||
click.echo("")
|
||||
|
||||
|
||||
@cli.command("monitor", short_help="Monitor Serial port")
|
||||
@option("--port", "-p", help="Port, a number or a device name")
|
||||
@option("--baud", "-b", type=int, default=9600,
|
||||
help="Set baud rate, default=9600")
|
||||
@option("--parity", default="N", type=Choice(["N", "E", "O", "S", "M"]),
|
||||
help="Set parity, default=N")
|
||||
@option("--rtscts", is_flag=True,
|
||||
help="Enable RTS/CTS flow control, default=Off")
|
||||
@option("--xonxoff", is_flag=True,
|
||||
help="Enable software flow control, default=Off")
|
||||
@option("--rts", default="0", type=Choice(["0", "1"]),
|
||||
help="Set initial RTS line state, default=0")
|
||||
@option("--dtr", default="0", type=Choice(["0", "1"]),
|
||||
help="Set initial DTR line state, default=0")
|
||||
@option("--echo", is_flag=True,
|
||||
help="Enable local echo, default=Off")
|
||||
@option("--cr", is_flag=True,
|
||||
help="Do not send CR+LF, send CR only, default=Off")
|
||||
@option("--lf", is_flag=True,
|
||||
help="Do not send CR+LF, send LF only, default=Off")
|
||||
@option("--debug", "-d", count=True,
|
||||
help="""Debug received data (escape non-printable chars)
|
||||
@click.option("--port", "-p", help="Port, a number or a device name")
|
||||
@click.option("--baud", "-b", type=int, default=9600,
|
||||
help="Set baud rate, default=9600")
|
||||
@click.option("--parity", default="N",
|
||||
type=click.Choice(["N", "E", "O", "S", "M"]),
|
||||
help="Set parity, default=N")
|
||||
@click.option("--rtscts", is_flag=True,
|
||||
help="Enable RTS/CTS flow control, default=Off")
|
||||
@click.option("--xonxoff", is_flag=True,
|
||||
help="Enable software flow control, default=Off")
|
||||
@click.option("--rts", default="0", type=click.Choice(["0", "1"]),
|
||||
help="Set initial RTS line state, default=0")
|
||||
@click.option("--dtr", default="0", type=click.Choice(["0", "1"]),
|
||||
help="Set initial DTR line state, default=0")
|
||||
@click.option("--echo", is_flag=True,
|
||||
help="Enable local echo, default=Off")
|
||||
@click.option("--cr", is_flag=True,
|
||||
help="Do not send CR+LF, send CR only, default=Off")
|
||||
@click.option("--lf", is_flag=True,
|
||||
help="Do not send CR+LF, send LF only, default=Off")
|
||||
@click.option("--debug", "-d", count=True,
|
||||
help="""Debug received data (escape non-printable chars)
|
||||
# --debug can be given multiple times:
|
||||
# 0: just print what is received
|
||||
# 1: escape non-printable characters, do newlines as unusual
|
||||
# 2: escape non-printable characters, newlines too
|
||||
# 3: hex dump everything""")
|
||||
@option("--exit-char", type=int, default=0x1d,
|
||||
help="ASCII code of special character that is used to exit the "
|
||||
"application, default=0x1d")
|
||||
@option("--menu-char", type=int, default=0x14,
|
||||
help="ASCII code of special character that is used to control "
|
||||
"miniterm (menu), default=0x14")
|
||||
@option("--quiet", is_flag=True,
|
||||
help="Diagnostics: suppress non-error messages, default=Off")
|
||||
@click.option("--exit-char", type=int, default=0x1d,
|
||||
help="ASCII code of special character that is used to exit the "
|
||||
"application, default=0x1d")
|
||||
@click.option("--menu-char", type=int, default=0x14,
|
||||
help="ASCII code of special character that is used to control "
|
||||
"miniterm (menu), default=0x14")
|
||||
@click.option("--quiet", is_flag=True,
|
||||
help="Diagnostics: suppress non-error messages, default=Off")
|
||||
def serialports_monitor(**_):
|
||||
sys.argv = sys.argv[3:]
|
||||
try:
|
||||
|
||||
+14
-12
@@ -3,16 +3,18 @@
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from click import argument, command, echo, style
|
||||
import click
|
||||
|
||||
from platformio.commands.install import cli as cmd_install
|
||||
from platformio.exception import PlatformNotInstalledYet
|
||||
from platformio.pkgmanager import PackageManager
|
||||
from platformio.platforms.base import PlatformFactory
|
||||
|
||||
|
||||
@command("show", short_help="Show details about installed platforms")
|
||||
@argument("platform")
|
||||
def cli(platform):
|
||||
@click.command("show", short_help="Show details about installed platforms")
|
||||
@click.argument("platform")
|
||||
@click.pass_context
|
||||
def cli(ctx, platform):
|
||||
|
||||
installed_platforms = PlatformFactory.get_platforms(
|
||||
installed=True).keys()
|
||||
@@ -24,18 +26,18 @@ def cli(platform):
|
||||
else:
|
||||
raise PlatformNotInstalledYet(platform)
|
||||
|
||||
p = PlatformFactory().newPlatform(platform)
|
||||
echo("{name:<20} - {info}".format(name=style(p.get_name(), fg="cyan"),
|
||||
info=p.get_short_info()))
|
||||
p = PlatformFactory.newPlatform(platform)
|
||||
click.echo("{name:<20} - {info}".format(
|
||||
name=click.style(p.get_name(), fg="cyan"), info=p.get_short_info()))
|
||||
|
||||
installed_packages = PackageManager.get_installed()
|
||||
for name in p.get_installed_packages():
|
||||
data = installed_packages[name]
|
||||
pkgalias = p.get_pkg_alias(name)
|
||||
echo("----------")
|
||||
echo("Package: %s" % style(name, fg="yellow"))
|
||||
click.echo("----------")
|
||||
click.echo("Package: %s" % click.style(name, fg="yellow"))
|
||||
if pkgalias:
|
||||
echo("Alias: %s" % pkgalias)
|
||||
echo("Version: %d" % int(data['version']))
|
||||
echo("Installed: %s" % datetime.fromtimestamp(
|
||||
click.echo("Alias: %s" % pkgalias)
|
||||
click.echo("Version: %d" % int(data['version']))
|
||||
click.echo("Installed: %s" % datetime.fromtimestamp(
|
||||
data['time']).strftime("%Y-%m-%d %H:%M:%S"))
|
||||
@@ -1,17 +1,17 @@
|
||||
# Copyright (C) Ivan Kravets <me@ikravets.com>
|
||||
# See LICENSE for details.
|
||||
|
||||
from click import argument, command, secho
|
||||
import click
|
||||
|
||||
from platformio.platforms.base import PlatformFactory
|
||||
|
||||
|
||||
@command("uninstall", short_help="Uninstall platforms")
|
||||
@argument("platforms", nargs=-1)
|
||||
@click.command("uninstall", short_help="Uninstall platforms")
|
||||
@click.argument("platforms", nargs=-1)
|
||||
def cli(platforms):
|
||||
|
||||
for platform in platforms:
|
||||
p = PlatformFactory().newPlatform(platform)
|
||||
p = PlatformFactory.newPlatform(platform)
|
||||
if p.uninstall():
|
||||
secho("The platform '%s' has been successfully "
|
||||
"uninstalled!" % platform, fg="green")
|
||||
click.secho("The platform '%s' has been successfully "
|
||||
"uninstalled!" % platform, fg="green")
|
||||
@@ -1,12 +1,12 @@
|
||||
# Copyright (C) Ivan Kravets <me@ikravets.com>
|
||||
# See LICENSE for details.
|
||||
|
||||
from click import command, echo, style
|
||||
import click
|
||||
|
||||
from platformio.platforms.base import PlatformFactory
|
||||
|
||||
|
||||
@command("update", short_help="Update installed platforms")
|
||||
@click.command("update", short_help="Update installed platforms")
|
||||
def cli():
|
||||
|
||||
installed_platforms = PlatformFactory.get_platforms(
|
||||
@@ -14,7 +14,7 @@ def cli():
|
||||
installed_platforms.sort()
|
||||
|
||||
for platform in installed_platforms:
|
||||
echo("\nPlatform %s" % style(platform, fg="cyan"))
|
||||
echo("--------")
|
||||
p = PlatformFactory().newPlatform(platform)
|
||||
click.echo("\nPlatform %s" % click.style(platform, fg="cyan"))
|
||||
click.echo("--------")
|
||||
p = PlatformFactory.newPlatform(platform)
|
||||
p.update()
|
||||
@@ -1,15 +1,16 @@
|
||||
# Copyright (C) Ivan Kravets <me@ikravets.com>
|
||||
# See LICENSE for details.
|
||||
|
||||
from click import command, secho
|
||||
from requests import get
|
||||
import click
|
||||
import requests
|
||||
|
||||
from platformio import __version__
|
||||
from platformio.exception import GetLatestVersionError
|
||||
from platformio.util import exec_command
|
||||
|
||||
|
||||
@command("upgrade", short_help="Upgrade PlatformIO to the latest version")
|
||||
@click.command("upgrade",
|
||||
short_help="Upgrade PlatformIO to the latest version")
|
||||
def cli():
|
||||
try:
|
||||
last = get_latest_version()
|
||||
@@ -17,14 +18,17 @@ def cli():
|
||||
raise GetLatestVersionError()
|
||||
|
||||
if __version__ == last:
|
||||
return secho("You're up-to-date!\nPlatformIO %s is currently the "
|
||||
"newest version available." % __version__, fg="green")
|
||||
return click.secho(
|
||||
"You're up-to-date!\nPlatformIO %s is currently the "
|
||||
"newest version available." % __version__, fg="green"
|
||||
)
|
||||
else:
|
||||
result = exec_command(["pip", "install", "--upgrade", "platformio"])
|
||||
secho(result['out'], fg="green")
|
||||
secho(result['err'], fg="red")
|
||||
click.secho(result['out'], fg="green")
|
||||
click.secho(result['err'], fg="red")
|
||||
|
||||
|
||||
def get_latest_version():
|
||||
pkgdata = get("https://pypi.python.org/pypi/platformio/json").json()
|
||||
pkgdata = requests.get(
|
||||
"https://pypi.python.org/pypi/platformio/json").json()
|
||||
return pkgdata['info']['version']
|
||||
Reference in new issue
Block a user