mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-31 10:37:13 +02:00
Cleanup click-based source code
This commit is contained in:
@ -1,20 +1,20 @@
|
|||||||
# Copyright (C) Ivan Kravets <me@ikravets.com>
|
# Copyright (C) Ivan Kravets <me@ikravets.com>
|
||||||
# See LICENSE for details.
|
# See LICENSE for details.
|
||||||
|
|
||||||
from click import argument, command, option, secho
|
import click
|
||||||
|
|
||||||
from platformio.platforms.base import PlatformFactory
|
from platformio.platforms.base import PlatformFactory
|
||||||
|
|
||||||
|
|
||||||
@command("install", short_help="Install new platforms")
|
@click.command("install", short_help="Install new platforms")
|
||||||
@argument("platforms", nargs=-1)
|
@click.argument("platforms", nargs=-1)
|
||||||
@option("--with-package", multiple=True, metavar="<package>")
|
@click.option("--with-package", multiple=True, metavar="<package>")
|
||||||
@option("--without-package", multiple=True, metavar="<package>")
|
@click.option("--without-package", multiple=True, metavar="<package>")
|
||||||
@option("--skip-default-package", is_flag=True)
|
@click.option("--skip-default-package", is_flag=True)
|
||||||
def cli(platforms, with_package, without_package, skip_default_package):
|
def cli(platforms, with_package, without_package, skip_default_package):
|
||||||
|
|
||||||
for platform in platforms:
|
for platform in platforms:
|
||||||
p = PlatformFactory().newPlatform(platform)
|
p = PlatformFactory.newPlatform(platform)
|
||||||
if p.install(with_package, without_package, skip_default_package):
|
if p.install(with_package, without_package, skip_default_package):
|
||||||
secho("The platform '%s' has been successfully installed!" %
|
click.secho("The platform '%s' has been successfully installed!" %
|
||||||
platform, fg="green")
|
platform, fg="green")
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
# Copyright (C) Ivan Kravets <me@ikravets.com>
|
# Copyright (C) Ivan Kravets <me@ikravets.com>
|
||||||
# See LICENSE for details.
|
# See LICENSE for details.
|
||||||
|
|
||||||
from click import command, echo, style
|
import click
|
||||||
|
|
||||||
from platformio.platforms.base import PlatformFactory
|
from platformio.platforms.base import PlatformFactory
|
||||||
|
|
||||||
|
|
||||||
@command("list", short_help="List installed platforms")
|
@click.command("list", short_help="List installed platforms")
|
||||||
def cli():
|
def cli():
|
||||||
|
|
||||||
installed_platforms = PlatformFactory.get_platforms(
|
installed_platforms = PlatformFactory.get_platforms(
|
||||||
@ -14,8 +14,8 @@ def cli():
|
|||||||
installed_platforms.sort()
|
installed_platforms.sort()
|
||||||
|
|
||||||
for platform in installed_platforms:
|
for platform in installed_platforms:
|
||||||
p = PlatformFactory().newPlatform(platform)
|
p = PlatformFactory.newPlatform(platform)
|
||||||
echo("{name:<20} with packages: {pkgs}".format(
|
click.echo("{name:<20} with packages: {pkgs}".format(
|
||||||
name=style(p.get_name(), fg="cyan"),
|
name=click.style(p.get_name(), fg="cyan"),
|
||||||
pkgs=", ".join(p.get_installed_packages())
|
pkgs=", ".join(p.get_installed_packages())
|
||||||
))
|
))
|
||||||
|
@ -1,43 +1,44 @@
|
|||||||
# Copyright (C) Ivan Kravets <me@ikravets.com>
|
# Copyright (C) Ivan Kravets <me@ikravets.com>
|
||||||
# See LICENSE for details.
|
# See LICENSE for details.
|
||||||
|
|
||||||
from click import command, echo, option, secho, style
|
import click
|
||||||
|
|
||||||
from platformio import telemetry
|
from platformio import exception, telemetry
|
||||||
from platformio.exception import (InvalidEnvName, ProjectEnvsNotAvaialable,
|
from platformio.commands.install import cli as cmd_install
|
||||||
UndefinedEnvPlatform, UnknownEnvNames)
|
|
||||||
from platformio.platforms.base import PlatformFactory
|
from platformio.platforms.base import PlatformFactory
|
||||||
from platformio.util import get_project_config
|
from platformio.util import get_project_config
|
||||||
|
|
||||||
|
|
||||||
@command("run", short_help="Process project environments")
|
@click.command("run", short_help="Process project environments")
|
||||||
@option("--environment", "-e", multiple=True, metavar="<environment>")
|
@click.option("--environment", "-e", multiple=True, metavar="<environment>")
|
||||||
@option("--target", "-t", multiple=True, metavar="<target>")
|
@click.option("--target", "-t", multiple=True, metavar="<target>")
|
||||||
@option("--upload-port", metavar="<upload port>")
|
@click.option("--upload-port", metavar="<upload port>")
|
||||||
def cli(environment, target, upload_port):
|
@click.pass_context
|
||||||
|
def cli(ctx, environment, target, upload_port):
|
||||||
|
|
||||||
config = get_project_config()
|
config = get_project_config()
|
||||||
|
|
||||||
if not config.sections():
|
if not config.sections():
|
||||||
raise ProjectEnvsNotAvaialable()
|
raise exception.ProjectEnvsNotAvaialable()
|
||||||
|
|
||||||
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:
|
||||||
raise UnknownEnvNames(", ".join(unknown))
|
raise exception.UnknownEnvNames(", ".join(unknown))
|
||||||
|
|
||||||
for section in config.sections():
|
for section in config.sections():
|
||||||
# skip main configuration section
|
# skip main configuration section
|
||||||
if section == "platformio":
|
if section == "platformio":
|
||||||
continue
|
continue
|
||||||
elif section[:4] != "env:":
|
elif section[:4] != "env:":
|
||||||
raise InvalidEnvName(section)
|
raise exception.InvalidEnvName(section)
|
||||||
|
|
||||||
envname = section[4:]
|
envname = section[4:]
|
||||||
if environment and envname not in environment:
|
if environment and envname not in environment:
|
||||||
# echo("Skipped %s environment" % style(envname, fg="yellow"))
|
# echo("Skipped %s environment" % style(envname, fg="yellow"))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
echo("Processing %s environment:" % style(envname, fg="cyan"))
|
click.echo("Processing %s environment:" %
|
||||||
|
click.style(envname, fg="cyan"))
|
||||||
|
|
||||||
variables = ["PIOENV=" + envname]
|
variables = ["PIOENV=" + envname]
|
||||||
if upload_port:
|
if upload_port:
|
||||||
@ -55,7 +56,8 @@ def cli(environment, target, upload_port):
|
|||||||
envtargets = config.get(section, "targets").split()
|
envtargets = config.get(section, "targets").split()
|
||||||
|
|
||||||
if not config.has_option(section, "platform"):
|
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)
|
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. "
|
click.confirm("The platform '%s' has not been installed yet. "
|
||||||
"Would you like to install it now?" % platform)):
|
"Would you like to install it now?" % platform)):
|
||||||
ctx.invoke(cmd_install, platforms=[platform])
|
ctx.invoke(cmd_install, platforms=[platform])
|
||||||
|
|
||||||
|
p = PlatformFactory.newPlatform(platform)
|
||||||
result = p.run(variables, envtargets)
|
result = p.run(variables, envtargets)
|
||||||
secho(result['out'], fg="green")
|
click.secho(result['out'], fg="green")
|
||||||
secho(result['err'],
|
click.secho(result['err'],
|
||||||
fg="red" if "Error" in result['err'] else "yellow")
|
fg="red" if "Error" in result['err'] else "yellow")
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
# Copyright (C) Ivan Kravets <me@ikravets.com>
|
# Copyright (C) Ivan Kravets <me@ikravets.com>
|
||||||
# See LICENSE for details.
|
# See LICENSE for details.
|
||||||
|
|
||||||
from click import argument, command, echo, style
|
import click
|
||||||
|
|
||||||
from platformio.platforms.base import PlatformFactory
|
from platformio.platforms.base import PlatformFactory
|
||||||
|
|
||||||
|
|
||||||
@command("search", short_help="Search for development platforms")
|
@click.command("search", short_help="Search for development platforms")
|
||||||
@argument("query", required=False)
|
@click.argument("query", required=False)
|
||||||
def cli(query):
|
def cli(query):
|
||||||
for platform in PlatformFactory.get_platforms().keys():
|
for platform in PlatformFactory.get_platforms().keys():
|
||||||
p = PlatformFactory().newPlatform(platform)
|
p = PlatformFactory.newPlatform(platform)
|
||||||
name = p.get_name()
|
name = p.get_name()
|
||||||
shinfo = p.get_short_info()
|
shinfo = p.get_short_info()
|
||||||
|
|
||||||
@ -21,5 +21,5 @@ def cli(query):
|
|||||||
if query and query.lower() not in search_data.lower():
|
if query and query.lower() not in search_data.lower():
|
||||||
continue
|
continue
|
||||||
|
|
||||||
echo("{name:<20} - {info}".format(name=style(name, fg="cyan"),
|
click.echo("{name:<20} - {info}".format(
|
||||||
info=shinfo))
|
name=click.style(name, fg="cyan"), info=shinfo))
|
||||||
|
@ -3,13 +3,13 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from click import Choice, echo, group, option, secho
|
import click
|
||||||
from serial.tools import miniterm
|
from serial.tools import miniterm
|
||||||
|
|
||||||
from platformio.util import get_serialports
|
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():
|
def cli():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -18,48 +18,49 @@ def cli():
|
|||||||
def serialports_list():
|
def serialports_list():
|
||||||
|
|
||||||
for item in get_serialports():
|
for item in get_serialports():
|
||||||
secho(item['port'], fg="cyan")
|
click.secho(item['port'], fg="cyan")
|
||||||
echo("----------")
|
click.echo("----------")
|
||||||
echo("Hardware ID: %s" % item['hwid'])
|
click.echo("Hardware ID: %s" % item['hwid'])
|
||||||
echo("Description: %s" % item['description'])
|
click.echo("Description: %s" % item['description'])
|
||||||
echo("")
|
click.echo("")
|
||||||
|
|
||||||
|
|
||||||
@cli.command("monitor", short_help="Monitor Serial port")
|
@cli.command("monitor", short_help="Monitor Serial port")
|
||||||
@option("--port", "-p", help="Port, a number or a device name")
|
@click.option("--port", "-p", help="Port, a number or a device name")
|
||||||
@option("--baud", "-b", type=int, default=9600,
|
@click.option("--baud", "-b", type=int, default=9600,
|
||||||
help="Set baud rate, default=9600")
|
help="Set baud rate, default=9600")
|
||||||
@option("--parity", default="N", type=Choice(["N", "E", "O", "S", "M"]),
|
@click.option("--parity", default="N",
|
||||||
help="Set parity, default=N")
|
type=click.Choice(["N", "E", "O", "S", "M"]),
|
||||||
@option("--rtscts", is_flag=True,
|
help="Set parity, default=N")
|
||||||
help="Enable RTS/CTS flow control, default=Off")
|
@click.option("--rtscts", is_flag=True,
|
||||||
@option("--xonxoff", is_flag=True,
|
help="Enable RTS/CTS flow control, default=Off")
|
||||||
help="Enable software flow control, default=Off")
|
@click.option("--xonxoff", is_flag=True,
|
||||||
@option("--rts", default="0", type=Choice(["0", "1"]),
|
help="Enable software flow control, default=Off")
|
||||||
help="Set initial RTS line state, default=0")
|
@click.option("--rts", default="0", type=click.Choice(["0", "1"]),
|
||||||
@option("--dtr", default="0", type=Choice(["0", "1"]),
|
help="Set initial RTS line state, default=0")
|
||||||
help="Set initial DTR line state, default=0")
|
@click.option("--dtr", default="0", type=click.Choice(["0", "1"]),
|
||||||
@option("--echo", is_flag=True,
|
help="Set initial DTR line state, default=0")
|
||||||
help="Enable local echo, default=Off")
|
@click.option("--echo", is_flag=True,
|
||||||
@option("--cr", is_flag=True,
|
help="Enable local echo, default=Off")
|
||||||
help="Do not send CR+LF, send CR only, default=Off")
|
@click.option("--cr", is_flag=True,
|
||||||
@option("--lf", is_flag=True,
|
help="Do not send CR+LF, send CR only, default=Off")
|
||||||
help="Do not send CR+LF, send LF only, default=Off")
|
@click.option("--lf", is_flag=True,
|
||||||
@option("--debug", "-d", count=True,
|
help="Do not send CR+LF, send LF only, default=Off")
|
||||||
help="""Debug received data (escape non-printable chars)
|
@click.option("--debug", "-d", count=True,
|
||||||
|
help="""Debug received data (escape non-printable chars)
|
||||||
# --debug can be given multiple times:
|
# --debug can be given multiple times:
|
||||||
# 0: just print what is received
|
# 0: just print what is received
|
||||||
# 1: escape non-printable characters, do newlines as unusual
|
# 1: escape non-printable characters, do newlines as unusual
|
||||||
# 2: escape non-printable characters, newlines too
|
# 2: escape non-printable characters, newlines too
|
||||||
# 3: hex dump everything""")
|
# 3: hex dump everything""")
|
||||||
@option("--exit-char", type=int, default=0x1d,
|
@click.option("--exit-char", type=int, default=0x1d,
|
||||||
help="ASCII code of special character that is used to exit the "
|
help="ASCII code of special character that is used to exit the "
|
||||||
"application, default=0x1d")
|
"application, default=0x1d")
|
||||||
@option("--menu-char", type=int, default=0x14,
|
@click.option("--menu-char", type=int, default=0x14,
|
||||||
help="ASCII code of special character that is used to control "
|
help="ASCII code of special character that is used to control "
|
||||||
"miniterm (menu), default=0x14")
|
"miniterm (menu), default=0x14")
|
||||||
@option("--quiet", is_flag=True,
|
@click.option("--quiet", is_flag=True,
|
||||||
help="Diagnostics: suppress non-error messages, default=Off")
|
help="Diagnostics: suppress non-error messages, default=Off")
|
||||||
def serialports_monitor(**_):
|
def serialports_monitor(**_):
|
||||||
sys.argv = sys.argv[3:]
|
sys.argv = sys.argv[3:]
|
||||||
try:
|
try:
|
||||||
|
@ -3,16 +3,18 @@
|
|||||||
|
|
||||||
from datetime import datetime
|
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.exception import PlatformNotInstalledYet
|
||||||
from platformio.pkgmanager import PackageManager
|
from platformio.pkgmanager import PackageManager
|
||||||
from platformio.platforms.base import PlatformFactory
|
from platformio.platforms.base import PlatformFactory
|
||||||
|
|
||||||
|
|
||||||
@command("show", short_help="Show details about installed platforms")
|
@click.command("show", short_help="Show details about installed platforms")
|
||||||
@argument("platform")
|
@click.argument("platform")
|
||||||
def cli(platform):
|
@click.pass_context
|
||||||
|
def cli(ctx, platform):
|
||||||
|
|
||||||
installed_platforms = PlatformFactory.get_platforms(
|
installed_platforms = PlatformFactory.get_platforms(
|
||||||
installed=True).keys()
|
installed=True).keys()
|
||||||
@ -24,18 +26,18 @@ def cli(platform):
|
|||||||
else:
|
else:
|
||||||
raise PlatformNotInstalledYet(platform)
|
raise PlatformNotInstalledYet(platform)
|
||||||
|
|
||||||
p = PlatformFactory().newPlatform(platform)
|
p = PlatformFactory.newPlatform(platform)
|
||||||
echo("{name:<20} - {info}".format(name=style(p.get_name(), fg="cyan"),
|
click.echo("{name:<20} - {info}".format(
|
||||||
info=p.get_short_info()))
|
name=click.style(p.get_name(), fg="cyan"), info=p.get_short_info()))
|
||||||
|
|
||||||
installed_packages = PackageManager.get_installed()
|
installed_packages = PackageManager.get_installed()
|
||||||
for name in p.get_installed_packages():
|
for name in p.get_installed_packages():
|
||||||
data = installed_packages[name]
|
data = installed_packages[name]
|
||||||
pkgalias = p.get_pkg_alias(name)
|
pkgalias = p.get_pkg_alias(name)
|
||||||
echo("----------")
|
click.echo("----------")
|
||||||
echo("Package: %s" % style(name, fg="yellow"))
|
click.echo("Package: %s" % click.style(name, fg="yellow"))
|
||||||
if pkgalias:
|
if pkgalias:
|
||||||
echo("Alias: %s" % pkgalias)
|
click.echo("Alias: %s" % pkgalias)
|
||||||
echo("Version: %d" % int(data['version']))
|
click.echo("Version: %d" % int(data['version']))
|
||||||
echo("Installed: %s" % datetime.fromtimestamp(
|
click.echo("Installed: %s" % datetime.fromtimestamp(
|
||||||
data['time']).strftime("%Y-%m-%d %H:%M:%S"))
|
data['time']).strftime("%Y-%m-%d %H:%M:%S"))
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
# Copyright (C) Ivan Kravets <me@ikravets.com>
|
# Copyright (C) Ivan Kravets <me@ikravets.com>
|
||||||
# See LICENSE for details.
|
# See LICENSE for details.
|
||||||
|
|
||||||
from click import argument, command, secho
|
import click
|
||||||
|
|
||||||
from platformio.platforms.base import PlatformFactory
|
from platformio.platforms.base import PlatformFactory
|
||||||
|
|
||||||
|
|
||||||
@command("uninstall", short_help="Uninstall platforms")
|
@click.command("uninstall", short_help="Uninstall platforms")
|
||||||
@argument("platforms", nargs=-1)
|
@click.argument("platforms", nargs=-1)
|
||||||
def cli(platforms):
|
def cli(platforms):
|
||||||
|
|
||||||
for platform in platforms:
|
for platform in platforms:
|
||||||
p = PlatformFactory().newPlatform(platform)
|
p = PlatformFactory.newPlatform(platform)
|
||||||
if p.uninstall():
|
if p.uninstall():
|
||||||
secho("The platform '%s' has been successfully "
|
click.secho("The platform '%s' has been successfully "
|
||||||
"uninstalled!" % platform, fg="green")
|
"uninstalled!" % platform, fg="green")
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
# Copyright (C) Ivan Kravets <me@ikravets.com>
|
# Copyright (C) Ivan Kravets <me@ikravets.com>
|
||||||
# See LICENSE for details.
|
# See LICENSE for details.
|
||||||
|
|
||||||
from click import command, echo, style
|
import click
|
||||||
|
|
||||||
from platformio.platforms.base import PlatformFactory
|
from platformio.platforms.base import PlatformFactory
|
||||||
|
|
||||||
|
|
||||||
@command("update", short_help="Update installed platforms")
|
@click.command("update", short_help="Update installed platforms")
|
||||||
def cli():
|
def cli():
|
||||||
|
|
||||||
installed_platforms = PlatformFactory.get_platforms(
|
installed_platforms = PlatformFactory.get_platforms(
|
||||||
@ -14,7 +14,7 @@ def cli():
|
|||||||
installed_platforms.sort()
|
installed_platforms.sort()
|
||||||
|
|
||||||
for platform in installed_platforms:
|
for platform in installed_platforms:
|
||||||
echo("\nPlatform %s" % style(platform, fg="cyan"))
|
click.echo("\nPlatform %s" % click.style(platform, fg="cyan"))
|
||||||
echo("--------")
|
click.echo("--------")
|
||||||
p = PlatformFactory().newPlatform(platform)
|
p = PlatformFactory.newPlatform(platform)
|
||||||
p.update()
|
p.update()
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
# Copyright (C) Ivan Kravets <me@ikravets.com>
|
# Copyright (C) Ivan Kravets <me@ikravets.com>
|
||||||
# See LICENSE for details.
|
# See LICENSE for details.
|
||||||
|
|
||||||
from click import command, secho
|
import click
|
||||||
from requests import get
|
import requests
|
||||||
|
|
||||||
from platformio import __version__
|
from platformio import __version__
|
||||||
from platformio.exception import GetLatestVersionError
|
from platformio.exception import GetLatestVersionError
|
||||||
from platformio.util import exec_command
|
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():
|
def cli():
|
||||||
try:
|
try:
|
||||||
last = get_latest_version()
|
last = get_latest_version()
|
||||||
@ -17,14 +18,17 @@ def cli():
|
|||||||
raise GetLatestVersionError()
|
raise GetLatestVersionError()
|
||||||
|
|
||||||
if __version__ == last:
|
if __version__ == last:
|
||||||
return secho("You're up-to-date!\nPlatformIO %s is currently the "
|
return click.secho(
|
||||||
"newest version available." % __version__, fg="green")
|
"You're up-to-date!\nPlatformIO %s is currently the "
|
||||||
|
"newest version available." % __version__, fg="green"
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
result = exec_command(["pip", "install", "--upgrade", "platformio"])
|
result = exec_command(["pip", "install", "--upgrade", "platformio"])
|
||||||
secho(result['out'], fg="green")
|
click.secho(result['out'], fg="green")
|
||||||
secho(result['err'], fg="red")
|
click.secho(result['err'], fg="red")
|
||||||
|
|
||||||
|
|
||||||
def get_latest_version():
|
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']
|
return pkgdata['info']['version']
|
||||||
|
@ -150,7 +150,7 @@ class UpgraderFailed(PlatformioException):
|
|||||||
class SConsNotInstalled(PlatformioException):
|
class SConsNotInstalled(PlatformioException):
|
||||||
|
|
||||||
MESSAGE = (
|
MESSAGE = (
|
||||||
"The `scons` tool isn't installed properly. "
|
"The PlatformIO and `scons` aren't installed properly. "
|
||||||
"Please use official installation procedure: "
|
"Please use official installation manual: "
|
||||||
"http://docs.platformio.ikravets.com/en/latest/installation.html"
|
"http://docs.platformio.ikravets.com/en/latest/installation.html"
|
||||||
)
|
)
|
||||||
|
@ -10,8 +10,8 @@ from time import time
|
|||||||
import click
|
import click
|
||||||
|
|
||||||
from platformio import __version__, app, telemetry
|
from platformio import __version__, app, telemetry
|
||||||
from platformio.commands.install import cli as cli_install
|
from platformio.commands.install import cli as cmd_install
|
||||||
from platformio.commands.lib import lib_update as cli_libraries_update
|
from platformio.commands.lib import lib_update as cmd_libraries_update
|
||||||
from platformio.commands.update import cli as cli_platforms_update
|
from platformio.commands.update import cli as cli_platforms_update
|
||||||
from platformio.commands.upgrade import get_latest_version
|
from platformio.commands.upgrade import get_latest_version
|
||||||
from platformio.exception import UpgraderFailed
|
from platformio.exception import UpgraderFailed
|
||||||
@ -75,7 +75,7 @@ class Upgrader(object):
|
|||||||
remove(join(get_home_dir(), fname))
|
remove(join(get_home_dir(), fname))
|
||||||
|
|
||||||
if prev_platforms:
|
if prev_platforms:
|
||||||
ctx.invoke(cli_install, platforms=prev_platforms)
|
ctx.invoke(cmd_install, platforms=prev_platforms)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -156,7 +156,7 @@ def check_internal_updates(ctx, what):
|
|||||||
outdated_items = []
|
outdated_items = []
|
||||||
if what == "platforms":
|
if what == "platforms":
|
||||||
for platform in PlatformFactory.get_platforms(installed=True).keys():
|
for platform in PlatformFactory.get_platforms(installed=True).keys():
|
||||||
p = PlatformFactory().newPlatform(platform)
|
p = PlatformFactory.newPlatform(platform)
|
||||||
if p.is_outdated():
|
if p.is_outdated():
|
||||||
outdated_items.append(platform)
|
outdated_items.append(platform)
|
||||||
elif what == "libraries":
|
elif what == "libraries":
|
||||||
@ -180,7 +180,7 @@ def check_internal_updates(ctx, what):
|
|||||||
if what == "platforms":
|
if what == "platforms":
|
||||||
ctx.invoke(cli_platforms_update)
|
ctx.invoke(cli_platforms_update)
|
||||||
elif what == "libraries":
|
elif what == "libraries":
|
||||||
ctx.invoke(cli_libraries_update)
|
ctx.invoke(cmd_libraries_update)
|
||||||
click.echo()
|
click.echo()
|
||||||
|
|
||||||
telemetry.on_event(category="Auto", action="Update",
|
telemetry.on_event(category="Auto", action="Update",
|
||||||
|
@ -6,13 +6,11 @@ from os.path import isdir, join
|
|||||||
from shutil import rmtree
|
from shutil import rmtree
|
||||||
from time import time
|
from time import time
|
||||||
|
|
||||||
from click import echo, secho, style
|
import click
|
||||||
|
|
||||||
from platformio import telemetry
|
from platformio import exception, telemetry
|
||||||
from platformio.app import get_state_item, set_state_item
|
from platformio.app import get_state_item, set_state_item
|
||||||
from platformio.downloader import FileDownloader
|
from platformio.downloader import FileDownloader
|
||||||
from platformio.exception import (InvalidPackageVersion, NonSystemPackage,
|
|
||||||
UnknownPackage)
|
|
||||||
from platformio.unpacker import FileUnpacker
|
from platformio.unpacker import FileUnpacker
|
||||||
from platformio.util import get_api_result, get_home_dir, get_systype
|
from platformio.util import get_api_result, get_home_dir, get_systype
|
||||||
|
|
||||||
@ -62,28 +60,28 @@ class PackageManager(object):
|
|||||||
def get_info(self, name, version=None):
|
def get_info(self, name, version=None):
|
||||||
manifest = self.get_manifest()
|
manifest = self.get_manifest()
|
||||||
if name not in manifest:
|
if name not in manifest:
|
||||||
raise UnknownPackage(name)
|
raise exception.UnknownPackage(name)
|
||||||
|
|
||||||
# check system platform
|
# check system platform
|
||||||
systype = get_systype()
|
systype = get_systype()
|
||||||
builds = ([b for b in manifest[name] if b['system'] == "all" or systype
|
builds = ([b for b in manifest[name] if b['system'] == "all" or systype
|
||||||
in b['system']])
|
in b['system']])
|
||||||
if not builds:
|
if not builds:
|
||||||
raise NonSystemPackage(name, systype)
|
raise exception.NonSystemPackage(name, systype)
|
||||||
|
|
||||||
if version:
|
if version:
|
||||||
for b in builds:
|
for b in builds:
|
||||||
if b['version'] == version:
|
if b['version'] == version:
|
||||||
return b
|
return b
|
||||||
raise InvalidPackageVersion(name, version)
|
raise exception.InvalidPackageVersion(name, version)
|
||||||
else:
|
else:
|
||||||
return sorted(builds, key=lambda s: s['version'])[-1]
|
return sorted(builds, key=lambda s: s['version'])[-1]
|
||||||
|
|
||||||
def install(self, name):
|
def install(self, name):
|
||||||
echo("Installing %s package:" % style(name, fg="cyan"))
|
click.echo("Installing %s package:" % click.style(name, fg="cyan"))
|
||||||
|
|
||||||
if self.is_installed(name):
|
if self.is_installed(name):
|
||||||
secho("Already installed", fg="yellow")
|
click.secho("Already installed", fg="yellow")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
info = self.get_info(name)
|
info = self.get_info(name)
|
||||||
@ -101,36 +99,36 @@ class PackageManager(object):
|
|||||||
category="PackageManager", action="Install", label=name)
|
category="PackageManager", action="Install", label=name)
|
||||||
|
|
||||||
def uninstall(self, name):
|
def uninstall(self, name):
|
||||||
echo("Uninstalling %s package: \t" % style(name, fg="cyan"),
|
click.echo("Uninstalling %s package: \t" %
|
||||||
nl=False)
|
click.style(name, fg="cyan"), nl=False)
|
||||||
|
|
||||||
if not self.is_installed(name):
|
if not self.is_installed(name):
|
||||||
secho("Not installed", fg="yellow")
|
click.secho("Not installed", fg="yellow")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
rmtree(join(self._package_dir, name))
|
rmtree(join(self._package_dir, name))
|
||||||
self._unregister(name)
|
self._unregister(name)
|
||||||
echo("[%s]" % style("OK", fg="green"))
|
click.echo("[%s]" % click.style("OK", fg="green"))
|
||||||
|
|
||||||
# report usage
|
# report usage
|
||||||
telemetry.on_event(
|
telemetry.on_event(
|
||||||
category="PackageManager", action="Uninstall", label=name)
|
category="PackageManager", action="Uninstall", label=name)
|
||||||
|
|
||||||
def update(self, name):
|
def update(self, name):
|
||||||
echo("Updating %s package:" % style(name, fg="yellow"))
|
click.echo("Updating %s package:" % click.style(name, fg="yellow"))
|
||||||
|
|
||||||
installed = self.get_installed()
|
installed = self.get_installed()
|
||||||
current_version = installed[name]['version']
|
current_version = installed[name]['version']
|
||||||
latest_version = self.get_info(name)['version']
|
latest_version = self.get_info(name)['version']
|
||||||
|
|
||||||
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:
|
||||||
echo("[%s]" % (style("Up-to-date", fg="green")))
|
click.echo("[%s]" % (click.style("Up-to-date", fg="green")))
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
echo("[%s]" % (style("Out-of-date", fg="red")))
|
click.echo("[%s]" % (click.style("Out-of-date", fg="red")))
|
||||||
|
|
||||||
self.uninstall(name)
|
self.uninstall(name)
|
||||||
self.install(name)
|
self.install(name)
|
||||||
|
@ -156,7 +156,7 @@ class BasePlatform(object):
|
|||||||
for item in installed_platforms:
|
for item in installed_platforms:
|
||||||
if item == platform:
|
if item == platform:
|
||||||
continue
|
continue
|
||||||
p = PlatformFactory().newPlatform(item)
|
p = PlatformFactory.newPlatform(item)
|
||||||
deppkgs = deppkgs.union(set(p.get_packages().keys()))
|
deppkgs = deppkgs.union(set(p.get_packages().keys()))
|
||||||
|
|
||||||
pm = PackageManager()
|
pm = PackageManager()
|
||||||
|
Reference in New Issue
Block a user