forked from platformio/platformio-core
Terminate PIO Home servers when upgrade PIO Core // Issue #1132
This commit is contained in:
@ -15,6 +15,7 @@
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
import click
|
import click
|
||||||
|
import requests
|
||||||
|
|
||||||
from platformio.managers.core import pioplus_call
|
from platformio.managers.core import pioplus_call
|
||||||
|
|
||||||
@ -29,3 +30,13 @@ from platformio.managers.core import pioplus_call
|
|||||||
@click.option("--no-open", is_flag=True)
|
@click.option("--no-open", is_flag=True)
|
||||||
def cli(*args, **kwargs): # pylint: disable=unused-argument
|
def cli(*args, **kwargs): # pylint: disable=unused-argument
|
||||||
pioplus_call(sys.argv[1:])
|
pioplus_call(sys.argv[1:])
|
||||||
|
|
||||||
|
|
||||||
|
def shutdown_servers():
|
||||||
|
port = 8010
|
||||||
|
while port < 9000:
|
||||||
|
try:
|
||||||
|
requests.get("http://127.0.0.1:%d?__shutdown__=1" % port)
|
||||||
|
port += 1
|
||||||
|
except: # pylint: disable=bare-except
|
||||||
|
return
|
||||||
|
@ -18,6 +18,7 @@ import click
|
|||||||
import requests
|
import requests
|
||||||
|
|
||||||
from platformio import VERSION, __version__, exception, util
|
from platformio import VERSION, __version__, exception, util
|
||||||
|
from platformio.commands.home import shutdown_servers
|
||||||
from platformio.managers.core import update_core_packages
|
from platformio.managers.core import update_core_packages
|
||||||
|
|
||||||
|
|
||||||
@ -33,47 +34,49 @@ def cli():
|
|||||||
"You're up-to-date!\nPlatformIO %s is currently the "
|
"You're up-to-date!\nPlatformIO %s is currently the "
|
||||||
"newest version available." % __version__,
|
"newest version available." % __version__,
|
||||||
fg="green")
|
fg="green")
|
||||||
else:
|
|
||||||
click.secho("Please wait while upgrading PlatformIO ...", fg="yellow")
|
|
||||||
|
|
||||||
to_develop = not all([c.isdigit() for c in latest if c != "."])
|
click.secho("Please wait while upgrading PlatformIO ...", fg="yellow")
|
||||||
cmds = ([
|
|
||||||
"pip", "install", "--upgrade",
|
|
||||||
"https://github.com/platformio/platformio-core/archive/develop.zip"
|
|
||||||
if to_develop else "platformio"
|
|
||||||
], ["platformio", "--version"])
|
|
||||||
|
|
||||||
cmd = None
|
# kill all PIO Home servers, they block `pioplus` binary
|
||||||
r = None
|
shutdown_servers()
|
||||||
try:
|
|
||||||
for cmd in cmds:
|
to_develop = not all([c.isdigit() for c in latest if c != "."])
|
||||||
cmd = [util.get_pythonexe_path(), "-m"] + cmd
|
cmds = ([
|
||||||
r = None
|
"pip", "install", "--upgrade",
|
||||||
|
"https://github.com/platformio/platformio-core/archive/develop.zip"
|
||||||
|
if to_develop else "platformio"
|
||||||
|
], ["platformio", "--version"])
|
||||||
|
|
||||||
|
cmd = None
|
||||||
|
r = None
|
||||||
|
try:
|
||||||
|
for cmd in cmds:
|
||||||
|
cmd = [util.get_pythonexe_path(), "-m"] + cmd
|
||||||
|
r = None
|
||||||
|
r = util.exec_command(cmd)
|
||||||
|
|
||||||
|
# try pip with disabled cache
|
||||||
|
if r['returncode'] != 0 and cmd[2] == "pip":
|
||||||
|
cmd.insert(3, "--no-cache-dir")
|
||||||
r = util.exec_command(cmd)
|
r = util.exec_command(cmd)
|
||||||
|
|
||||||
# try pip with disabled cache
|
assert r['returncode'] == 0
|
||||||
if r['returncode'] != 0 and cmd[2] == "pip":
|
assert "version" in r['out']
|
||||||
cmd.insert(3, "--no-cache-dir")
|
actual_version = r['out'].strip().split("version", 1)[1].strip()
|
||||||
r = util.exec_command(cmd)
|
click.secho(
|
||||||
|
"PlatformIO has been successfully upgraded to %s" % actual_version,
|
||||||
assert r['returncode'] == 0
|
fg="green")
|
||||||
assert "version" in r['out']
|
click.echo("Release notes: ", nl=False)
|
||||||
actual_version = r['out'].strip().split("version", 1)[1].strip()
|
click.secho(
|
||||||
|
"http://docs.platformio.org/en/latest/history.html", fg="cyan")
|
||||||
|
except Exception as e: # pylint: disable=broad-except
|
||||||
|
if not r:
|
||||||
|
raise exception.UpgradeError("\n".join([str(cmd), str(e)]))
|
||||||
|
permission_errors = ("permission denied", "not permitted")
|
||||||
|
if (any([m in r['err'].lower() for m in permission_errors])
|
||||||
|
and "windows" not in util.get_systype()):
|
||||||
click.secho(
|
click.secho(
|
||||||
"PlatformIO has been successfully upgraded to %s" %
|
"""
|
||||||
actual_version,
|
|
||||||
fg="green")
|
|
||||||
click.echo("Release notes: ", nl=False)
|
|
||||||
click.secho(
|
|
||||||
"http://docs.platformio.org/en/latest/history.html", fg="cyan")
|
|
||||||
except Exception as e: # pylint: disable=broad-except
|
|
||||||
if not r:
|
|
||||||
raise exception.UpgradeError("\n".join([str(cmd), str(e)]))
|
|
||||||
permission_errors = ("permission denied", "not permitted")
|
|
||||||
if (any([m in r['err'].lower() for m in permission_errors])
|
|
||||||
and "windows" not in util.get_systype()):
|
|
||||||
click.secho(
|
|
||||||
"""
|
|
||||||
-----------------
|
-----------------
|
||||||
Permission denied
|
Permission denied
|
||||||
-----------------
|
-----------------
|
||||||
@ -83,12 +86,12 @@ You need the `sudo` permission to install Python packages. Try
|
|||||||
|
|
||||||
WARNING! Don't use `sudo` for the rest PlatformIO commands.
|
WARNING! Don't use `sudo` for the rest PlatformIO commands.
|
||||||
""",
|
""",
|
||||||
fg="yellow",
|
fg="yellow",
|
||||||
err=True)
|
err=True)
|
||||||
raise exception.ReturnErrorCode(1)
|
raise exception.ReturnErrorCode(1)
|
||||||
else:
|
else:
|
||||||
raise exception.UpgradeError("\n".join(
|
raise exception.UpgradeError("\n".join(
|
||||||
[str(cmd), r['out'], r['err']]))
|
[str(cmd), r['out'], r['err']]))
|
||||||
|
|
||||||
|
|
||||||
def get_latest_version():
|
def get_latest_version():
|
||||||
|
Reference in New Issue
Block a user