2014-08-03 18:40:20 +03:00
|
|
|
# Copyright (C) Ivan Kravets <me@ikravets.com>
|
|
|
|
# See LICENSE for details.
|
|
|
|
|
2014-12-03 20:16:50 +02:00
|
|
|
import click
|
|
|
|
import requests
|
2014-08-03 18:40:20 +03:00
|
|
|
|
|
|
|
from platformio import __version__
|
|
|
|
from platformio.exception import GetLatestVersionError
|
|
|
|
from platformio.util import exec_command
|
|
|
|
|
|
|
|
|
2014-12-03 20:16:50 +02:00
|
|
|
@click.command("upgrade",
|
|
|
|
short_help="Upgrade PlatformIO to the latest version")
|
2014-08-03 18:40:20 +03:00
|
|
|
def cli():
|
|
|
|
try:
|
|
|
|
last = get_latest_version()
|
|
|
|
except:
|
|
|
|
raise GetLatestVersionError()
|
|
|
|
|
|
|
|
if __version__ == last:
|
2014-12-03 20:16:50 +02:00
|
|
|
return click.secho(
|
|
|
|
"You're up-to-date!\nPlatformIO %s is currently the "
|
|
|
|
"newest version available." % __version__, fg="green"
|
|
|
|
)
|
2014-08-03 18:40:20 +03:00
|
|
|
else:
|
2015-01-06 17:45:07 +02:00
|
|
|
click.secho("Please wait while upgrading PlatformIO ...",
|
|
|
|
fg="yellow")
|
|
|
|
|
|
|
|
pip_result = exec_command(["pip", "install", "--upgrade",
|
|
|
|
"platformio"])
|
|
|
|
pio_result = exec_command(["platformio", "--version"])
|
|
|
|
|
|
|
|
if last in pio_result['out'].strip():
|
|
|
|
click.secho("PlatformIO has been successfully upgraded to %s" %
|
|
|
|
last, fg="green")
|
|
|
|
else:
|
|
|
|
click.secho(pip_result['out'], fg="green")
|
|
|
|
click.secho(pip_result['err'], fg="red")
|
2014-08-03 18:40:20 +03:00
|
|
|
|
|
|
|
|
|
|
|
def get_latest_version():
|
2014-12-03 20:16:50 +02:00
|
|
|
pkgdata = requests.get(
|
|
|
|
"https://pypi.python.org/pypi/platformio/json").json()
|
2014-08-03 18:40:20 +03:00
|
|
|
return pkgdata['info']['version']
|