diff --git a/platformio/commands/home.py b/platformio/commands/home.py index cd6b86f6..ae797781 100644 --- a/platformio/commands/home.py +++ b/platformio/commands/home.py @@ -15,6 +15,7 @@ import sys import click +import requests 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) def cli(*args, **kwargs): # pylint: disable=unused-argument 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 diff --git a/platformio/commands/upgrade.py b/platformio/commands/upgrade.py index 95241d7f..9cbb6611 100644 --- a/platformio/commands/upgrade.py +++ b/platformio/commands/upgrade.py @@ -18,6 +18,7 @@ import click import requests from platformio import VERSION, __version__, exception, util +from platformio.commands.home import shutdown_servers from platformio.managers.core import update_core_packages @@ -33,47 +34,49 @@ def cli(): "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") - to_develop = not all([c.isdigit() for c in latest if c != "."]) - cmds = ([ - "pip", "install", "--upgrade", - "https://github.com/platformio/platformio-core/archive/develop.zip" - if to_develop else "platformio" - ], ["platformio", "--version"]) + click.secho("Please wait while upgrading PlatformIO ...", fg="yellow") - cmd = None - r = None - try: - for cmd in cmds: - cmd = [util.get_pythonexe_path(), "-m"] + cmd - r = None + # kill all PIO Home servers, they block `pioplus` binary + shutdown_servers() + + to_develop = not all([c.isdigit() for c in latest if c != "."]) + cmds = ([ + "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) - # try pip with disabled cache - if r['returncode'] != 0 and cmd[2] == "pip": - cmd.insert(3, "--no-cache-dir") - r = util.exec_command(cmd) - - assert r['returncode'] == 0 - assert "version" in r['out'] - actual_version = r['out'].strip().split("version", 1)[1].strip() + assert r['returncode'] == 0 + assert "version" in r['out'] + actual_version = r['out'].strip().split("version", 1)[1].strip() + 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( - "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 ----------------- @@ -83,12 +86,12 @@ You need the `sudo` permission to install Python packages. Try WARNING! Don't use `sudo` for the rest PlatformIO commands. """, - fg="yellow", - err=True) - raise exception.ReturnErrorCode(1) - else: - raise exception.UpgradeError("\n".join( - [str(cmd), r['out'], r['err']])) + fg="yellow", + err=True) + raise exception.ReturnErrorCode(1) + else: + raise exception.UpgradeError("\n".join( + [str(cmd), r['out'], r['err']])) def get_latest_version():