Resolve #8: Implement "upgrade" command and "auto-check" for the latest version

This commit is contained in:
Ivan Kravets
2014-08-03 18:40:20 +03:00
parent a287d53520
commit 8b056efe64
5 changed files with 82 additions and 4 deletions

View File

@ -4,6 +4,18 @@ Release History
1.0.0 (?) 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 <https://github.com/ivankravets/platformio/issues/7>`_)
* Added `Arduino example <https://github.com/ivankravets/platformio/tree/develop/examples/arduino-adafruit-library>`_
with external library (Adafruit CC3000)
* Implemented ``platformio upgrade`` command and "auto-check" for the latest
version (`issue #8 <https://github.com/ivankravets/platformio/issues/8>`_)
0.4.0 (2014-07-31) 0.4.0 (2014-07-31)
------------------ ------------------

View File

@ -284,6 +284,7 @@ To print all available commands and options:
show Show details about an installed platforms show Show details about an installed platforms
uninstall Uninstall platforms uninstall Uninstall platforms
update Update installed platforms update Update installed platforms
upgrade Upgrade PlatformIO to the latest version
``platformio init`` ``platformio init``
@ -564,7 +565,7 @@ To uninstall platform:
``platformio update`` ``platformio update``
~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~
To check or update installed platforms: To check or update installed platforms:
@ -603,6 +604,19 @@ To check or update installed platforms:
Versions: Current=1, Latest=1 [Up-to-date] 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 Questions & Bugs
---------------- ----------------

View File

@ -2,15 +2,17 @@
# See LICENSE for details. # See LICENSE for details.
from os import listdir from os import listdir
from os.path import join from os.path import getmtime, isfile, join
from sys import exit as sys_exit from sys import exit as sys_exit
from time import time
from traceback import format_exc 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 import __version__
from platformio.commands.upgrade import get_latest_version
from platformio.exception import PlatformioException, UnknownCLICommand 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): class PlatformioCLI(MultiCommand):
@ -40,8 +42,23 @@ def cli():
pass 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(): def main():
try: 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() cli()
except Exception as e: # pylint: disable=W0703 except Exception as e: # pylint: disable=W0703
if isinstance(e, PlatformioException): if isinstance(e, PlatformioException):

View File

@ -0,0 +1,30 @@
# Copyright (C) Ivan Kravets <me@ikravets.com>
# 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']

View File

@ -100,3 +100,8 @@ class UnknownEnvNames(PlatformioException):
class GetSerialPortsError(PlatformioException): class GetSerialPortsError(PlatformioException):
MESSAGE = "No implementation for your platform ('%s') available" MESSAGE = "No implementation for your platform ('%s') available"
class GetLatestVersionError(PlatformioException):
MESSAGE = "Can't retrieve latest PlatformIO version"