forked from platformio/platformio-core
Resolve #8: Implement "upgrade" command and "auto-check" for the latest version
This commit is contained in:
30
platformio/commands/upgrade.py
Normal file
30
platformio/commands/upgrade.py
Normal file
@@ -0,0 +1,30 @@
|
||||
# Copyright (C) Ivan Kravets <me@ikravets.com>
|
||||
# See LICENSE for details.
|
||||
|
||||
from click import command, secho
|
||||
from requests import get
|
||||
|
||||
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")
|
||||
def cli():
|
||||
try:
|
||||
last = get_latest_version()
|
||||
except:
|
||||
raise GetLatestVersionError()
|
||||
|
||||
if __version__ == last:
|
||||
return 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")
|
||||
|
||||
|
||||
def get_latest_version():
|
||||
pkgdata = get("https://pypi.python.org/pypi/platformio/json").json()
|
||||
return pkgdata['info']['version']
|
||||
Reference in New Issue
Block a user