Files
platformio-core/platformio/commands/upgrade.py

74 lines
2.3 KiB
Python
Raw Normal View History

# Copyright (C) Ivan Kravets <me@ikravets.com>
# See LICENSE for details.
2014-12-03 20:16:50 +02:00
import click
import requests
2015-09-02 13:42:01 +03:00
from platformio import __version__, exception, util
2014-12-03 20:16:50 +02:00
@click.command("upgrade",
short_help="Upgrade PlatformIO to the latest version")
def cli():
last = get_latest_version()
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"
)
else:
click.secho("Please wait while upgrading PlatformIO ...",
fg="yellow")
2015-09-02 13:42:01 +03:00
cmds = (
2015-09-09 01:28:43 +03:00
["pip", "install", "--upgrade", "pip", "setuptools", "virtualenv"],
2015-09-02 13:42:01 +03:00
["pip", "install", "--upgrade", "platformio"],
["platformio", "--version"]
)
cmd = None
r = None
try:
for cmd in cmds:
r = None
r = util.exec_command(cmd)
assert r['returncode'] == 0
assert last in r['out'].strip()
click.secho(
"PlatformIO has been successfully upgraded to %s" % last,
fg="green")
click.echo("Release notes: ", nl=False)
click.secho("http://docs.platformio.org/en/latest/history.html",
fg="cyan")
except (OSError, AssertionError) as e:
if not r:
raise exception.PlatformioException(
"\n".join([str(cmd), str(e)]))
if ("Permission denied" in r['err'] and
"windows" not in util.get_systype()):
click.secho("""
-----------------
Permission denied
-----------------
You need the `sudo` permission to install Python packages. Try
> sudo platformio upgrade
2015-09-02 13:42:01 +03:00
WARNING! Don't use `sudo` for the rest PlatformIO commands.
""", fg="yellow", err=True)
raise exception.ReturnErrorCode()
else:
raise exception.PlatformioException(
"\n".join([str(cmd), r['out'], r['err']]))
def get_latest_version():
try:
pkgdata = requests.get(
2015-04-29 18:17:14 +01:00
"https://pypi.python.org/pypi/platformio/json",
headers=util.get_request_defheaders()
).json()
return pkgdata['info']['version']
except:
2015-09-02 13:42:01 +03:00
raise exception.GetLatestVersionError()