diff --git a/HISTORY.rst b/HISTORY.rst index 3746622a..90d367a7 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -4,6 +4,18 @@ Release History 1.0.0 (?) --------- +0.5.0 (?) +--------- + +* Improved nested lookups for libraries +* Disabled default warning flag "-Wall" +* Added auto-conversation from \*.ino to valid \*.cpp for Arduino/Energia + frameworks (`issue #7 `_) +* Added `Arduino example `_ + with external library (Adafruit CC3000) +* Implemented ``platformio upgrade`` command and "auto-check" for the latest + version (`issue #8 `_) + 0.4.0 (2014-07-31) ------------------ diff --git a/README.rst b/README.rst index 4d8dd770..f1aef721 100644 --- a/README.rst +++ b/README.rst @@ -284,6 +284,7 @@ To print all available commands and options: show Show details about an installed platforms uninstall Uninstall platforms update Update installed platforms + upgrade Upgrade PlatformIO to the latest version ``platformio init`` @@ -564,7 +565,7 @@ To uninstall platform: ``platformio update`` -~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~ To check or update installed platforms: @@ -603,6 +604,19 @@ To check or update installed platforms: Versions: Current=1, Latest=1 [Up-to-date] +``platformio upgrade`` +~~~~~~~~~~~~~~~~~~~~~~ + +To check or upgrade PlatformIO to the latest version: + +.. code-block:: bash + + $ platformio upgrade + + # If you have problem with permissions try: + $ sudo platformio upgrade + + Questions & Bugs ---------------- diff --git a/platformio/__main__.py b/platformio/__main__.py index bf8f26d0..7b2525ef 100644 --- a/platformio/__main__.py +++ b/platformio/__main__.py @@ -2,15 +2,17 @@ # See LICENSE for details. from os import listdir -from os.path import join +from os.path import getmtime, isfile, join from sys import exit as sys_exit +from time import time from traceback import format_exc -from click import command, MultiCommand, version_option +from click import command, MultiCommand, secho, version_option from platformio import __version__ +from platformio.commands.upgrade import get_latest_version from platformio.exception import PlatformioException, UnknownCLICommand -from platformio.util import get_source_dir +from platformio.util import get_home_dir, get_source_dir class PlatformioCLI(MultiCommand): @@ -40,8 +42,23 @@ def cli(): pass +def autocheck_latest_version(): + check_interval = 3600 * 24 * 7 # 1 week + checkfile = join(get_home_dir(), ".pioupgrade") + if isfile(checkfile) and getmtime(checkfile) > (time() - check_interval): + return False + with open(checkfile, "w") as f: + f.write(str(time())) + return get_latest_version() != __version__ + + def main(): try: + if autocheck_latest_version(): + secho("\nThere is a new version of PlatformIO available.\n" + "Please upgrade it via `platformio upgrade` command.\n", + fg="yellow") + cli() except Exception as e: # pylint: disable=W0703 if isinstance(e, PlatformioException): diff --git a/platformio/commands/upgrade.py b/platformio/commands/upgrade.py new file mode 100644 index 00000000..2f211d36 --- /dev/null +++ b/platformio/commands/upgrade.py @@ -0,0 +1,30 @@ +# Copyright (C) Ivan Kravets +# 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'] diff --git a/platformio/exception.py b/platformio/exception.py index 7b7d08f1..046ad084 100644 --- a/platformio/exception.py +++ b/platformio/exception.py @@ -100,3 +100,8 @@ class UnknownEnvNames(PlatformioException): class GetSerialPortsError(PlatformioException): MESSAGE = "No implementation for your platform ('%s') available" + + +class GetLatestVersionError(PlatformioException): + + MESSAGE = "Can't retrieve latest PlatformIO version"