forked from platformio/platformio-core
Resolve #8: Implement "upgrade" command and "auto-check" for the latest version
This commit is contained in:
1 parent
a287d53520
commit
8b056efe64
5 files changed
+82
-4
No files matched your search
+20
-3
@@ -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):
|
||||
|
||||
Reference in new issue
Block a user