def test_scons(): try: r = util.exec_command(["scons", "--version"]) if "ImportError: No module named SCons.Script" in r['err']: _PYTHONPATH = [] for p in sys.path: if not p.endswith("-packages"): continue for item in glob(join(p, "scons*")): if isdir(join(item, "SCons")) and item not in sys.path: _PYTHONPATH.append(item) sys.path.insert(0, item) if _PYTHONPATH: _PYTHONPATH = str(os.pathsep).join(_PYTHONPATH) if os.getenv("PYTHONPATH"): os.environ['PYTHONPATH'] += os.pathsep + _PYTHONPATH else: os.environ['PYTHONPATH'] = _PYTHONPATH r = util.exec_command(["scons", "--version"]) assert r['returncode'] == 0 return True except (OSError, AssertionError): for p in sys.path: try: r = util.exec_command([join(p, "scons"), "--version"]) assert r['returncode'] == 0 os.environ['PATH'] += os.pathsep + p return True except (OSError, AssertionError): pass return False
def cli(): last = get_latest_version() if __version__ == last: return click.secho( "You're up-to-date!\nPlatformIO %s is currently the " "newest version available." % __version__, fg="green" ) else: click.secho("Please wait while upgrading PlatformIO ...", fg="yellow") cmds = ( ["pip", "install", "--upgrade", "platformio"], ["platformio", "--version"] ) cmd = None r = None try: for cmd in cmds: r = None r = util.exec_command(cmd) # try pip with disabled cache if r['returncode'] != 0 and cmd[0] == "pip": r = util.exec_command(["pip", "--no-cache-dir"] + cmd[1:]) assert r['returncode'] == 0 assert last in r['out'].strip() click.secho( "PlatformIO has been successfully upgraded to %s" % last, fg="green") click.echo("Release notes: ", nl=False) click.secho("http://docs.platformio.org/en/latest/history.html", fg="cyan") except Exception as e: # pylint: disable=W0703 if not r: raise exception.UpgradeError( "\n".join([str(cmd), str(e)])) permission_errors = ( "permission denied", "not permitted" ) if (any([m in r['err'].lower() for m in permission_errors]) and "windows" not in util.get_systype()): click.secho(""" ----------------- Permission denied ----------------- You need the `sudo` permission to install Python packages. Try > sudo pip install -U platformio WARNING! Don't use `sudo` for the rest PlatformIO commands. """, fg="yellow", err=True) raise exception.ReturnErrorCode() else: raise exception.UpgradeError( "\n".join([str(cmd), r['out'], r['err']]))
def generate_nvic_files(): for root, _, files in walk(join(FRAMEWORK_DIR, "include", "libopencm3")): if "irq.json" not in files or isfile(join(root, "nvic.h")): continue exec_command( ["python", join("scripts", "irq2nvic_h"), join("." + root.replace(FRAMEWORK_DIR, ""), "irq.json").replace("\\", "/")], cwd=FRAMEWORK_DIR )
def generate_nvic_files(): fw_dir = env.subst("$PLATFORMFW_DIR") for root, _, files in walk(join(fw_dir, "include", "libopencm3")): if "irq.json" not in files or isfile(join(root, "nvic.h")): continue exec_command( ["python", join("scripts", "irq2nvic_h"), join("." + root.replace(fw_dir, ""), "irq.json").replace("\\", "/")], cwd=fw_dir )
def test_local_env(): result = util.exec_command( ["platformio", "test", "-d", join("examples", "unit-testing", "calculator"), "-e", "native"] ) if result["returncode"] != 1: pytest.fail(result) assert all([s in result["out"] for s in ("PASSED", "IGNORED", "FAILED")])
def buildlib(mbed_dir, mcu, lib="mbed"): build_command = ["python", join(mbed_dir, "workspace_tools", "build.py"), "--mcu", mcu, "-t", "GCC_ARM"] if lib is not "mbed": build_command.append(lib) build_result = exec_command(build_command, cwd=getcwd()) if build_result["returncode"] != 0: print "* %s doesn't support %s library!" % (mcu, lib)
def get_project_build_data(self): data = { "defines": [], "includes": [], "cxx_path": None } envdata = self.get_project_env() if "env_name" not in envdata: return data result = util.exec_command( ["platformio", "-f", "run", "-t", "idedata", "-e", envdata['env_name'], "-d", self.project_dir] ) if result['returncode'] != 0 or '"includes":' not in result['out']: return data output = result['out'] try: start_index = output.index('\n{"') stop_index = output.rindex('}') data = json.loads(output[start_index + 1:stop_index + 1]) except ValueError: pass return data
def get_project_build_data(self): data = { "defines": [], "includes": [], "cxx_path": None } envdata = self.get_project_env() if "env_name" not in envdata: return data cmd = [ normpath(sys.executable), "-m", "platformio" + ( ".__main__" if sys.version_info < (2, 7, 0) else ""), "-f" ] if app.get_session_var("caller_id"): cmd.extend(["-c", app.get_session_var("caller_id")]) cmd.extend(["run", "-t", "idedata", "-e", envdata['env_name']]) cmd.extend(["-d", self.project_dir]) result = util.exec_command(cmd) if result['returncode'] != 0 or '"includes":' not in result['out']: raise exception.PlatformioException( "\n".join([result['out'], result['err']])) output = result['out'] start_index = output.index('{"') stop_index = output.rindex('}') data = json.loads(output[start_index:stop_index + 1]) return data
def _run_scons(self, variables, targets): # pass current PYTHONPATH to SCons if "PYTHONPATH" in os.environ: _PYTHONPATH = os.environ.get("PYTHONPATH").split(os.pathsep) else: _PYTHONPATH = [] for p in os.sys.path: if p not in _PYTHONPATH: _PYTHONPATH.append(p) os.environ['PYTHONPATH'] = os.pathsep.join(_PYTHONPATH) cmd = [ os.path.normpath(sys.executable), join(util.get_home_dir(), "packages", "tool-scons", "script", "scons"), "-Q", "-j %d" % self.get_job_nums(), "--warn=no-no-parallel-support", "-f", join(util.get_source_dir(), "builder", "main.py") ] + targets # encode and append variables for key, value in variables.items(): cmd.append("%s=%s" % (key.upper(), base64.b64encode(value))) result = util.exec_command( cmd, stdout=util.AsyncPipe(self.on_run_out), stderr=util.AsyncPipe(self.on_run_err) ) return result
def test_run(pioproject_dir): with util.cd(pioproject_dir): build_dir = util.get_projectbuild_dir() if isdir(build_dir): util.rmtree_(build_dir) env_names = [] for section in util.load_project_config().sections(): if section.startswith("env:"): env_names.append(section[4:]) result = util.exec_command( ["platformio", "run", "-e", random.choice(env_names)]) if result['returncode'] != 0: pytest.fail(result) assert isdir(build_dir) # check .elf file for item in listdir(build_dir): if not isdir(item): continue assert isfile(join(build_dir, item, "firmware.elf")) # check .hex or .bin files firmwares = [] for ext in ("bin", "hex"): firmwares += glob(join(build_dir, item, "firmware*.%s" % ext)) if not firmwares: pytest.fail("Missed firmware file") for firmware in firmwares: assert getsize(firmware) > 0
def CheckUploadSize(_, target, source, env): # pylint: disable=W0613,W0621 if "BOARD" not in env: return max_size = int(env.BoardConfig().get("upload.maximum_size", 0)) if max_size == 0 or "SIZETOOL" not in env: return sysenv = environ.copy() sysenv['PATH'] = str(env['ENV']['PATH']) cmd = [ env.subst("$SIZETOOL"), "-B", str(source[0] if isinstance(target[0], Alias) else target[0]) ] result = util.exec_command(cmd, env=sysenv) if result['returncode'] != 0: return print result['out'].strip() line = result['out'].strip().splitlines()[1] values = [v.strip() for v in line.split("\t")] used_size = int(values[0]) + int(values[1]) if used_size > max_size: sys.stderr.write("Error: The program size (%d bytes) is greater " "than maximum allowed (%s bytes)\n" % (used_size, max_size)) env.Exit(1)
def run(self, variables, targets, verbose): assert isinstance(variables, list) assert isinstance(targets, list) self._verbose_level = int(verbose) installed_platforms = PlatformFactory.get_platforms( installed=True).keys() installed_packages = PackageManager.get_installed() if self.get_type() not in installed_platforms: raise exception.PlatformNotInstalledYet(self.get_type()) if "clean" in targets: targets.remove("clean") targets.append("-c") if not any([v.startswith("BUILD_SCRIPT=") for v in variables]): variables.append("BUILD_SCRIPT=%s" % self.get_build_script()) for v in variables: if not v.startswith("BUILD_SCRIPT="): continue _, path = v.split("=", 2) if not isfile(path): raise exception.BuildScriptNotFound(path) # append aliases of the installed packages for name, options in self.get_packages().items(): if "alias" not in options or name not in installed_packages: continue variables.append( "PIOPACKAGE_%s=%s" % (options['alias'].upper(), name)) self._found_error = False try: # test that SCons is installed correctly assert util.test_scons() result = util.exec_command( [ "scons", "-Q", "-f", join(util.get_source_dir(), "builder", "main.py") ] + variables + targets, stdout=util.AsyncPipe(self.on_run_out), stderr=util.AsyncPipe(self.on_run_err) ) except (OSError, AssertionError): raise exception.SConsNotInstalledError() assert "returncode" in result # if self._found_error: # result['returncode'] = 1 if self._last_echo_line == ".": click.echo("") return result
def get_cmd_output(self, args, **kwargs): args = [self.command] + args if "cwd" not in kwargs: kwargs['cwd'] = self.src_dir result = util.exec_command(args, **kwargs) if result['returncode'] == 0: return result['out'].strip() raise PlatformioException( "VCS: Could not receive an output from `%s` command (%s)" % ( args, result))
def cli(): last = get_latest_version() if __version__ == last: return click.secho( "You're up-to-date!\nPlatformIO %s is currently the " "newest version available." % __version__, fg="green" ) else: click.secho("Please wait while upgrading PlatformIO ...", fg="yellow") pip_result = exec_command(["pip", "install", "--upgrade", "platformio"]) pio_result = exec_command(["platformio", "--version"]) if last in pio_result['out'].strip(): click.secho("PlatformIO has been successfully upgraded to %s" % last, fg="green") else: click.secho(pip_result['out'], fg="green") click.secho(pip_result['err'], fg="red")
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_size_output(): cmd = env.get("SIZECHECKCMD") if not cmd: return None if not isinstance(cmd, list): cmd = cmd.split() cmd = [arg.replace("$SOURCES", str(source[0])) for arg in cmd if arg] sysenv = environ.copy() sysenv['PATH'] = str(env['ENV']['PATH']) result = util.exec_command(env.subst(cmd), env=sysenv) if result['returncode'] != 0: return None return result['out'].strip()
def GetCompilerType(env): try: sysenv = environ.copy() sysenv['PATH'] = str(env['ENV']['PATH']) result = exec_command([env.subst("$CC"), "-v"], env=sysenv) except OSError: return None if result['returncode'] != 0: return None output = "".join([result['out'], result['err']]).lower() for type_ in ("clang", "gcc"): if type_ in output: return type_ return None
def verify(self, sha1=None): _dlsize = getsize(self._destination) if self.get_size() != -1 and _dlsize != self.get_size(): raise FDSizeMismatch(_dlsize, self._fname, self.get_size()) if not sha1: return dlsha1 = None try: result = util.exec_command(["sha1sum", self._destination]) dlsha1 = result["out"] except (OSError, ValueError): try: result = util.exec_command(["shasum", "-a", "1", self._destination]) dlsha1 = result["out"] except (OSError, ValueError): pass if dlsha1: dlsha1 = dlsha1[1:41] if dlsha1.startswith("\\") else dlsha1[:40] if sha1 != dlsha1: raise FDSHASumMismatch(dlsha1, self._fname, sha1)
def run(self, variables, targets): assert isinstance(variables, list) assert isinstance(targets, list) if "clean" in targets: targets.remove("clean") targets.append("-c") result = exec_command([ "scons", "-Q", "-f", join(get_source_dir(), "builder", "main.py") ] + variables + targets) return self.after_run(result)
def _prefill_appinfo(self): self['av'] = __version__ # gather dependent packages dpdata = [] dpdata.append("Click/%s" % click.__version__) # dpdata.append("Requests/%s" % requests.__version__) try: result = exec_command(["scons", "--version"]) match = re.search(r"engine: v([\d\.]+)", result['out']) if match: dpdata.append("SCons/%s" % match.group(1)) except: # pylint: disable=W0702 pass self['an'] = " ".join(dpdata)
def GetCompilerType(env): try: sysenv = environ.copy() sysenv['PATH'] = str(env['ENV']['PATH']) result = util.exec_command([env.subst("$CC"), "-v"], env=sysenv) except OSError: return None if result['returncode'] != 0: return None output = "".join([result['out'], result['err']]).lower() if "clang" in output and "LLVM" in output: return "clang" elif "gcc" in output: return "gcc" return None
def _prefill_appinfo(self): self['av'] = __version__ # gather dependent packages dpdata = [] dpdata.append("Click/%s" % click.__version__) if app.get_session_var("caller_id"): dpdata.append("Caller/%s" % app.get_session_var("caller_id")) try: result = util.exec_command(["scons", "--version"]) match = re.search(r"engine: v([\d\.]+)", result['out']) if match: dpdata.append("SCons/%s" % match.group(1)) except: # pylint: disable=W0702 pass self['an'] = " ".join(dpdata)
def cli(): last = get_latest_version() if __version__ == last: return click.secho( "You're up-to-date!\nPlatformIO %s is currently the " "newest version available." % __version__, fg="green" ) else: click.secho("Please wait while upgrading PlatformIO ...", fg="yellow") cmds = ( ["pip", "install", "--upgrade", "pip", "setuptools"], ["pip", "install", "--upgrade", "platformio"], ["platformio", "--version"], ) cmd = None r = None try: for cmd in cmds: r = None r = util.exec_command(cmd) assert r["returncode"] == 0 assert last in r["out"].strip() click.secho("PlatformIO has been successfully upgraded to %s" % last, fg="green") click.echo("Release notes: ", nl=False) click.secho("http://docs.platformio.org/en/latest/history.html", fg="cyan") except (OSError, AssertionError) as e: if not r: raise exception.PlatformioUpgradeError("\n".join([str(cmd), str(e)])) if "Permission denied" in r["err"] and "windows" not in util.get_systype(): click.secho( """ ----------------- Permission denied ----------------- You need the `sudo` permission to install Python packages. Try > sudo platformio upgrade WARNING! Don't use `sudo` for the rest PlatformIO commands. """, fg="yellow", err=True, ) raise exception.ReturnErrorCode() else: raise exception.PlatformioUpgradeError("\n".join([str(cmd), r["out"], r["err"]]))
def main(mbed_dir, output_dir): print "Starting..." path.append(mbed_dir) from workspace_tools.export import gccarm if isdir(output_dir): print "Deleting previous framework dir..." rmtree(output_dir) settings_file = join(mbed_dir, "workspace_tools", "private_settings.py") if not isfile(settings_file): with open(settings_file, "w") as f: f.write("GCC_ARM_PATH = '%s'" % join(get_home_dir(), "packages", "toolchain-gccarmnoneeabi", "bin")) makedirs(join(output_dir, "variant")) mbed_libs = ["--rtos", "--dsp", "--fat", "--eth", "--usb", "--usb_host"] for mcu in set(gccarm.GccArm.TARGETS): print "Processing board: %s" % mcu buildlib(mbed_dir, mcu) for lib in mbed_libs: buildlib(mbed_dir, mcu, lib) result = exec_command( [ "python", join(mbed_dir, "workspace_tools", "project.py"), "--mcu", mcu, "-i", "emblocks", "-p", "0", "-b", ], cwd=getcwd(), ) if result["returncode"] != 0: print "Unable to build the project for %s" % mcu continue _unzip_generated_file(mbed_dir, output_dir, mcu) copylibs(mbed_dir, output_dir) with open(join(output_dir, "boards.txt"), "w") as fp: fp.write("\n".join(sorted(listdir(join(output_dir, "variant"))))) print "Complete!"
def get_project_build_data(self): data = {"defines": [], "includes": [], "cxx_path": None} envdata = self.get_project_env() if "env_name" not in envdata: return data result = util.exec_command( ["platformio", "-f", "run", "-t", "idedata", "-e", envdata["env_name"], "-d", self.project_dir] ) if result["returncode"] != 0 or '"includes":' not in result["out"]: raise exception.PlatformioException("\n".join([result["out"], result["err"]])) output = result["out"] start_index = output.index('\n{"') stop_index = output.rindex("}") data = json.loads(output[start_index + 1 : stop_index + 1]) return data
def get_project_build_data(self): envdata = self.get_project_env() if "env_name" not in envdata: return None result = util.exec_command( ["platformio", "run", "-t", "idedata", "-e", envdata['env_name'], "--project-dir", self.project_dir] ) if result['returncode'] != 0 or '{"includes":' not in result['out']: return None output = result['out'] try: start_index = output.index('\n{"includes":') stop_index = output.rindex('}') return json.loads(output[start_index + 1:stop_index + 1]) except ValueError: pass return None
def _get_gcc_defines(env): items = [] try: sysenv = environ.copy() sysenv['PATH'] = str(env['ENV']['PATH']) result = util.exec_command( "echo | %s -dM -E -" % env.subst("$CC"), env=sysenv, shell=True) except OSError: return items if result['returncode'] != 0: return items for line in result['out'].split("\n"): tokens = line.strip().split(" ", 2) if not tokens or tokens[0] != "#define": continue if len(tokens) > 2: items.append("%s=%s" % (tokens[1], tokens[2])) else: items.append(tokens[1]) return items
def _run_scons(self, variables, targets): cmd = [ util.get_pythonexe_path(), join(self.get_package_dir("tool-scons"), "script", "scons"), "-Q", "-j %d" % self.get_job_nums(), "--warn=no-no-parallel-support", "-f", join(util.get_source_dir(), "builder", "main.py"), ] cmd.append("PIOVERBOSE=%d" % (1 if self.verbose else 0)) cmd += targets # encode and append variables for key, value in variables.items(): cmd.append("%s=%s" % (key.upper(), base64.b64encode(value))) util.copy_pythonpath_to_osenv() result = util.exec_command(cmd, stdout=util.AsyncPipe(self.on_run_out), stderr=util.AsyncPipe(self.on_run_err)) return result
def get_pip_package(to_develop): if not to_develop: return "platformio" dl_url = ("https://github.com/platformio/" "platformio-core/archive/develop.zip") 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", dl_url], 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 dl_url
def get_project_build_data(self): data = {"defines": [], "includes": [], "cxx_path": None} envdata = self.get_project_env() if "env_name" not in envdata: return data cmd = [util.get_pythonexe_path(), "-m", "platformio", "-f"] if app.get_session_var("caller_id"): cmd.extend(["-c", app.get_session_var("caller_id")]) cmd.extend(["run", "-t", "idedata", "-e", envdata['env_name']]) cmd.extend(["-d", self.project_dir]) result = util.exec_command(cmd) if result['returncode'] != 0 or '"includes":' not in result['out']: raise exception.PlatformioException("\n".join( [result['out'], result['err']])) for line in result['out'].split("\n"): line = line.strip() if line.startswith('{"') and line.endswith("}"): data = json.loads(line) return data
def run(self, variables, targets, verbose): assert isinstance(variables, list) assert isinstance(targets, list) envoptions = {} for v in variables: _name, _value = v.split("=", 1) envoptions[_name.lower()] = _value self.configure_default_packages(envoptions, targets) self._install_default_packages() self._verbose_level = int(verbose) if "clean" in targets: targets.remove("clean") targets.append("-c") if "build_script" not in envoptions: variables.append("BUILD_SCRIPT=%s" % self.get_build_script()) for v in variables: if not v.startswith("BUILD_SCRIPT="): continue _, path = v.split("=", 1) if not isfile(path): raise exception.BuildScriptNotFound(path) # append aliases of the installed packages installed_packages = PackageManager.get_installed() for name, options in self.get_packages().items(): if "alias" not in options or name not in installed_packages: continue variables.append( "PIOPACKAGE_%s=%s" % (options['alias'].upper(), name)) self._found_error = False args = [] try: args = [os.path.relpath(PathsManager.EXECUTABLE_FILE), # [JORGE_GARCIA] modified for scons compatibility "-Q", "-j %d" % self.get_job_nums(), "--warn=no-no-parallel-support", "-f", join(util.get_source_dir(), "builder", "main.py") ] + variables + targets + [os.getcwd()] if PathsManager.EXECUTABLE_FILE.endswith(".py"): args = ["python"] + args # test that SCons is installed correctly # assert util.test_scons() log.debug("Executing: {}".format("\n".join(args))) result = util.exec_command(args, stdout=util.AsyncPipe(self.on_run_out), stderr=util.AsyncPipe(self.on_run_err)) except (OSError, AssertionError) as e: log.exception("error running scons with \n{}".format(args)) raise exception.SConsNotInstalledError() assert "returncode" in result # if self._found_error: # result['returncode'] = 1 if self._last_echo_line == ".": click.echo("") return result
def test_platformio_cli(): result = util.exec_command(["pio", "--help"]) assert result["returncode"] == 0 assert "Usage: pio [OPTIONS] COMMAND [ARGS]..." in result["out"]
def cli(dev): if not dev and __version__ == get_latest_version(): return click.secho( "You're up-to-date!\nPlatformIO %s is currently the " "newest version available." % __version__, fg="green") click.secho("Please wait while upgrading PlatformIO ...", fg="yellow") # kill all PIO Home servers, they block `pioplus` binary shutdown_piohome_servers() to_develop = dev or not all(c.isdigit() for c in __version__ if c != ".") cmds = (["pip", "install", "--upgrade", get_pip_package(to_develop)], ["platformio", "--version"]) cmd = None r = None try: for cmd in cmds: cmd = [util.get_pythonexe_path(), "-m"] + cmd r = None r = util.exec_command(cmd) # try pip with disabled cache if r['returncode'] != 0 and cmd[2] == "pip": cmd.insert(3, "--no-cache-dir") r = util.exec_command(cmd) assert r['returncode'] == 0 assert "version" in r['out'] actual_version = r['out'].strip().split("version", 1)[1].strip() click.secho("PlatformIO has been successfully upgraded to %s" % actual_version, fg="green") click.echo("Release notes: ", nl=False) click.secho("https://docs.platformio.org/en/latest/history.html", fg="cyan") except Exception as e: # pylint: disable=broad-except if not r: raise exception.UpgradeError("\n".join([str(cmd), str(e)])) permission_errors = ("permission denied", "not permitted") if (any(m in r['err'].lower() for m in permission_errors) and "windows" not in util.get_systype()): click.secho(""" ----------------- Permission denied ----------------- You need the `sudo` permission to install Python packages. Try > sudo pip install -U platformio WARNING! Don't use `sudo` for the rest PlatformIO commands. """, fg="yellow", err=True) raise exception.ReturnErrorCode(1) else: raise exception.UpgradeError("\n".join( [str(cmd), r['out'], r['err']])) return True
def cli(): last = get_latest_version() if __version__ == last: return click.secho( "You're up-to-date!\nPlatformIO %s is currently the " "newest version available." % __version__, fg="green") else: click.secho("Please wait while upgrading PlatformIO ...", fg="yellow") to_develop = False try: from pkg_resources import parse_version to_develop = parse_version(last) < parse_version(__version__) except ImportError: pass cmds = ([ "pip", "install", "--upgrade", "https://github.com/platformio/platformio/archive/develop.zip" if to_develop else "platformio" ], ["platformio", "--version"]) cmd = None r = None try: for cmd in cmds: cmd = [os.path.normpath(sys.executable), "-m"] + cmd r = None r = util.exec_command(cmd) # try pip with disabled cache if r['returncode'] != 0 and cmd[2] == "pip": cmd.insert(3, "--no-cache-dir") r = util.exec_command(cmd) assert r['returncode'] == 0 assert "version" in r['out'] actual_version = r['out'].strip().split("version", 1)[1].strip() click.secho("PlatformIO has been successfully upgraded to %s" % actual_version, fg="green") click.echo("Release notes: ", nl=False) click.secho("http://docs.platformio.org/en/latest/history.html", fg="cyan") except Exception as e: # pylint: disable=W0703 if not r: raise exception.UpgradeError("\n".join([str(cmd), str(e)])) permission_errors = ("permission denied", "not permitted") if (any([m in r['err'].lower() for m in permission_errors]) and "windows" not in util.get_systype()): click.secho(""" ----------------- Permission denied ----------------- You need the `sudo` permission to install Python packages. Try > sudo pip install -U platformio WARNING! Don't use `sudo` for the rest PlatformIO commands. """, fg="yellow", err=True) raise exception.ReturnErrorCode() else: raise exception.UpgradeError("\n".join( [str(cmd), r['out'], r['err']]))