diff --git a/platformio/app.py b/platformio/app.py index f6015d36..8ca1ba4c 100644 --- a/platformio/app.py +++ b/platformio/app.py @@ -141,7 +141,7 @@ class ContentCache(object): self._db_path = None self._lockfile = None - self.cache_dir = cache_dir or join(util.get_home_dir(), ".cache") + self.cache_dir = cache_dir or util.get_cache_dir() self._db_path = join(self.cache_dir, "db.data") def __enter__(self): diff --git a/platformio/commands/upgrade.py b/platformio/commands/upgrade.py index bcc202ab..a1efb8f2 100644 --- a/platformio/commands/upgrade.py +++ b/platformio/commands/upgrade.py @@ -12,7 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +import os import re +from zipfile import ZipFile import click import requests @@ -37,11 +39,8 @@ def cli(dev): shutdown_servers() to_develop = dev or not all(c.isdigit() for c in __version__ if c != ".") - cmds = ([ - "pip", "install", "--upgrade", - "https://github.com/platformio/platformio-core/archive/develop.zip" - if to_develop else "platformio" - ], ["platformio", "--version"]) + cmds = (["pip", "install", "--upgrade", + get_pip_package(to_develop)], ["platformio", "--version"]) cmd = None r = None @@ -92,6 +91,33 @@ WARNING! Don't use `sudo` for the rest PlatformIO commands. return True +def get_pip_package(to_develop): + pkg_name = "platformio" + if not to_develop: + return pkg_name + cache_dir = util.get_cache_dir() + if not os.path.isdir(cache_dir): + os.makedirs(cache_dir) + pkg_name = os.path.join(cache_dir, "piocoredevelop.zip") + try: + with open(pkg_name, "w") as fp: + r = util.exec_command( + [ + "curl", "-fsSL", "https://github.com/platformio/" + "platformio-core/archive/develop.zip" + ], + stdout=fp, + universal_newlines=True) + assert r['returncode'] == 0 + # check ZIP structure + with ZipFile(pkg_name) as zp: + assert zp.testzip() is None + return pkg_name + except: # pylint: disable=bare-except + pass + return "platformio" + + def get_latest_version(): try: if not str(VERSION[2]).isdigit(): diff --git a/platformio/util.py b/platformio/util.py index c569f04a..459b85e2 100644 --- a/platformio/util.py +++ b/platformio/util.py @@ -253,6 +253,11 @@ def get_home_dir(): return home_dir +def get_cache_dir(): + return get_project_optional_dir("cache_dir", join(get_home_dir(), + ".cache")) + + def get_source_dir(): curpath = abspath(__file__) if not isfile(curpath): diff --git a/tests/test_maintenance.py b/tests/test_maintenance.py index 667c1563..ec9d749a 100644 --- a/tests/test_maintenance.py +++ b/tests/test_maintenance.py @@ -44,9 +44,7 @@ def test_after_upgrade_2_to_3(clirunner, validate_cliresult, result = clirunner.invoke(cli_pio, ["settings", "get"]) validate_cliresult(result) - assert "upgraded to 3" - assert isolated_pio_home.join("platforms", "native", - "platform.json").check() + assert "upgraded to 3" in result.output # check PlatformIO 3.0 boards assert board_ids == set([p.basename[:-5] for p in boards.listdir()])