diff --git a/platformio/commands/upgrade.py b/platformio/commands/upgrade.py index 75172ccf..7e57579e 100644 --- a/platformio/commands/upgrade.py +++ b/platformio/commands/upgrade.py @@ -12,11 +12,7 @@ from platformio.util import exec_command @click.command("upgrade", short_help="Upgrade PlatformIO to the latest version") def cli(): - try: - last = get_latest_version() - except: - raise GetLatestVersionError() - + last = get_latest_version() if __version__ == last: return click.secho( "You're up-to-date!\nPlatformIO %s is currently the " @@ -39,6 +35,9 @@ def cli(): def get_latest_version(): - pkgdata = requests.get( - "https://pypi.python.org/pypi/platformio/json").json() - return pkgdata['info']['version'] + try: + pkgdata = requests.get( + "https://pypi.python.org/pypi/platformio/json").json() + return pkgdata['info']['version'] + except: + raise GetLatestVersionError() diff --git a/platformio/exception.py b/platformio/exception.py index c3ef53a0..c7e3ccc6 100644 --- a/platformio/exception.py +++ b/platformio/exception.py @@ -110,7 +110,7 @@ class GetSerialPortsError(PlatformioException): class GetLatestVersionError(PlatformioException): - MESSAGE = "Can't retrieve latest PlatformIO version" + MESSAGE = "Can't retrieve the latest PlatformIO version" class APIRequestError(PlatformioException): diff --git a/platformio/maintenance.py b/platformio/maintenance.py index 78b1d3ec..6aae8b8c 100644 --- a/platformio/maintenance.py +++ b/platformio/maintenance.py @@ -14,7 +14,7 @@ from platformio.commands.install import cli as cmd_install from platformio.commands.lib import lib_update as cmd_libraries_update from platformio.commands.update import cli as cli_platforms_update from platformio.commands.upgrade import get_latest_version -from platformio.exception import UpgraderFailed +from platformio.exception import GetLatestVersionError, UpgraderFailed from platformio.libmanager import LibraryManager from platformio.platforms.base import PlatformFactory from platformio.util import get_home_dir, get_lib_dir @@ -44,7 +44,10 @@ class Upgrader(object): @staticmethod def version_to_int(version): - return int(re.sub(r"[^\d]+", "", version)) + intver = int(re.sub(r"[^\d]+", "", version)) + if "dev" in version: + intver -= 1 + return intver def run(self, ctx): if self.from_version > self.to_version: @@ -106,13 +109,13 @@ def after_upgrade(ctx): )) click.secho("Thanks a lot!\n", fg="green") - if not isdir(get_home_dir()): + last_version = app.get_state_item("last_version", "0.0.0") + if last_version == "0.0.0": return click.secho("Please wait while upgrading PlatformIO ...", fg="yellow") - last_version = app.get_state_item("last_version", "0.0.0") u = Upgrader(last_version, __version__) if u.run(ctx): app.set_state_item("last_version", __version__) @@ -135,7 +138,12 @@ def check_platformio_upgrade(): last_check['platformio_upgrade'] = int(time()) app.set_state_item("last_check", last_check) - latest_version = get_latest_version() + try: + latest_version = get_latest_version() + except GetLatestVersionError: + click.secho("Failed to check for PlatformIO upgrades", fg="red") + return + if (latest_version == __version__ or Upgrader.version_to_int(latest_version) < Upgrader.version_to_int(__version__)):