forked from platformio/platformio-core
Improve PlatformIO upgrading
This commit is contained in:
@ -4,8 +4,7 @@
|
|||||||
import click
|
import click
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from platformio import __version__, util
|
from platformio import __version__, exception, util
|
||||||
from platformio.exception import GetLatestVersionError
|
|
||||||
|
|
||||||
|
|
||||||
@click.command("upgrade",
|
@click.command("upgrade",
|
||||||
@ -21,16 +20,46 @@ def cli():
|
|||||||
click.secho("Please wait while upgrading PlatformIO ...",
|
click.secho("Please wait while upgrading PlatformIO ...",
|
||||||
fg="yellow")
|
fg="yellow")
|
||||||
|
|
||||||
pip_result = util.exec_command(["pip", "install", "--upgrade",
|
cmds = (
|
||||||
"platformio"])
|
["pip", "install", "--upgrade", "pip", "setuptools"],
|
||||||
pio_result = util.exec_command(["platformio", "--version"])
|
["pip", "install", "--upgrade", "platformio"],
|
||||||
|
["platformio", "--version"]
|
||||||
|
)
|
||||||
|
|
||||||
if last in pio_result['out'].strip():
|
cmd = None
|
||||||
click.secho("PlatformIO has been successfully upgraded to %s" %
|
r = None
|
||||||
last, fg="green")
|
try:
|
||||||
else:
|
for cmd in cmds:
|
||||||
click.secho(pip_result['out'], fg="green")
|
r = None
|
||||||
click.secho(pip_result['err'], fg="red")
|
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
|
||||||
|
|
||||||
|
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():
|
def get_latest_version():
|
||||||
@ -41,4 +70,4 @@ def get_latest_version():
|
|||||||
).json()
|
).json()
|
||||||
return pkgdata['info']['version']
|
return pkgdata['info']['version']
|
||||||
except:
|
except:
|
||||||
raise GetLatestVersionError()
|
raise exception.GetLatestVersionError()
|
||||||
|
Reference in New Issue
Block a user