From de62e5082eaa30669bc69637085743a2e5975f43 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Fri, 26 Aug 2016 01:42:05 +0300 Subject: [PATCH] Handle WindowsError when can't create .pioenvs directory --- platformio/commands/run.py | 2 +- platformio/util.py | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/platformio/commands/run.py b/platformio/commands/run.py index 83a62cd3..825d09ac 100644 --- a/platformio/commands/run.py +++ b/platformio/commands/run.py @@ -63,7 +63,7 @@ def cli(ctx, # pylint: disable=R0913,R0914 click.secho( "Can not remove temporary directory `%s`. Please remove " "`.pioenvs` directory from the project manually to avoid " - "build issues" % util.get_projectpioenvs_dir(), + "build issues" % util.get_projectpioenvs_dir(force=True), fg="yellow") config = util.load_project_config() diff --git a/platformio/util.py b/platformio/util.py index 21b60c2c..b08db611 100644 --- a/platformio/util.py +++ b/platformio/util.py @@ -218,18 +218,22 @@ def get_projecttest_dir(): "test")) -def get_projectpioenvs_dir(): +def get_projectpioenvs_dir(force=False): path = _get_projconf_option_dir("envs_dir", join(get_project_dir(), ".pioenvs")) - if not isdir(path): - os.makedirs(path) - dontmod_path = join(path, "do-not-modify-files-here.url") - if not isfile(dontmod_path): - with open(dontmod_path, "w") as fp: - fp.write(""" + try: + if not isdir(path): + os.makedirs(path) + dontmod_path = join(path, "do-not-modify-files-here.url") + if not isfile(dontmod_path): + with open(dontmod_path, "w") as fp: + fp.write(""" [InternetShortcut] URL=http://docs.platformio.org/en/stable/projectconf.html#envs-dir """) + except Exception as e: + if not force: + raise Exception(e) return path