def pioplus_call(args, **kwargs): if "windows" in util.get_systype() and sys.version_info < (2, 7, 6): raise exception.PlatformioException( "PlatformIO Core Plus v%s does not run under Python version %s.\n" "Minimum supported version is 2.7.6, please upgrade Python.\n" "Python 3 is not yet supported.\n" % (__version__, sys.version.split()[0])) pioplus_path = join(get_core_package_dir("tool-pioplus"), "pioplus") os.environ['PYTHONEXEPATH'] = util.get_pythonexe_path() os.environ['PYTHONPYSITEDIR'] = get_core_package_dir("pysite-pioplus") util.copy_pythonpath_to_osenv() code = subprocess.call([pioplus_path] + args, **kwargs) # handle remote update request if code == 13: count_attr = "_update_count" try: count_value = getattr(pioplus_call, count_attr) except AttributeError: count_value = 0 setattr(pioplus_call, count_attr, 1) count_value += 1 setattr(pioplus_call, count_attr, count_value) if count_value < PIOPLUS_AUTO_UPDATES_MAX: update_core_packages() return pioplus_call(args, **kwargs) # handle reload request elif code == 14: return pioplus_call(args, **kwargs) if code != 0: raise exception.ReturnErrorCode(1)
def pioplus_call(args, **kwargs): pioplus_install() pm = PioPlusPackageManager() pioplus_path = join( pm.get_package_dir(PACKAGE_DEPS['tool']['name'], PACKAGE_DEPS['tool']['requirements']), "pioplus") os.environ['PYTHONEXEPATH'] = util.get_pythonexe_path() os.environ['PYTHONPYSITEDIR'] = pm.get_package_dir( PACKAGE_DEPS['pysite']['name'], PACKAGE_DEPS['pysite']['requirements']) util.copy_pythonpath_to_osenv() code = subprocess.call([pioplus_path] + args, **kwargs) # handle remote update request if code == 13: count_attr = "_update_count" try: count_value = getattr(pioplus_call, count_attr) except AttributeError: count_value = 0 setattr(pioplus_call, count_attr, 1) count_value += 1 setattr(pioplus_call, count_attr, count_value) if count_value < AUTO_UPDATES_MAX: pioplus_update() return pioplus_call(args, **kwargs) # handle reload request elif code == 14: return pioplus_call(args, **kwargs) if code != 0: raise exception.ReturnErrorCode(1)
def pioplus_call(args, **kwargs): pioplus_path = get_pioplusexe_path() if system() == "Linux": os.environ['LD_LIBRARY_PATH'] = dirname(pioplus_path) os.environ['PYTHONEXEPATH'] = util.get_pythonexe_path() util.copy_pythonpath_to_osenv() subprocess.call([pioplus_path] + args, **kwargs)
def pioplus_call(args, **kwargs): pioplus_path = join(get_core_package_dir("tool-pioplus"), "pioplus") os.environ['PYTHONEXEPATH'] = util.get_pythonexe_path() os.environ['PYTHONPYSITEDIR'] = get_core_package_dir("pysite-pioplus") util.copy_pythonpath_to_osenv() code = subprocess.call([pioplus_path] + args, **kwargs) # handle remote update request if code == 13: count_attr = "_update_count" try: count_value = getattr(pioplus_call, count_attr) except AttributeError: count_value = 0 setattr(pioplus_call, count_attr, 1) count_value += 1 setattr(pioplus_call, count_attr, count_value) if count_value < PIOPLUS_AUTO_UPDATES_MAX: update_core_packages() return pioplus_call(args, **kwargs) # handle reload request elif code == 14: return pioplus_call(args, **kwargs) if code != 0: raise exception.ReturnErrorCode(1)
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 _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_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 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']])) output = result['out'] start_index = output.index('{"') stop_index = output.rindex('}') data = json.loads(output[start_index:stop_index + 1]) return data
def cli(): latest = get_latest_version() if __version__ == latest: 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 = not all([c.isdigit() for c in latest if c != "."]) cmds = ([ "pip", "install", "--upgrade", "https://github.com/platformio/platformio-core/archive/develop.zip" if to_develop else "platformio" ], ["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("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(1) else: raise exception.UpgradeError("\n".join( [str(cmd), r['out'], r['err']]))
PROGNAME="program", PIOHOME_DIR=util.get_home_dir(), PROJECT_DIR=util.get_project_dir(), PROJECTSRC_DIR=util.get_projectsrc_dir(), PROJECTTEST_DIR=util.get_projecttest_dir(), PROJECTDATA_DIR=util.get_projectdata_dir(), PROJECTPIOENVS_DIR=util.get_projectpioenvs_dir(), BUILD_DIR=join("$PROJECTPIOENVS_DIR", "$PIOENV"), BUILDSRC_DIR=join("$BUILD_DIR", "src"), BUILDTEST_DIR=join("$BUILD_DIR", "test"), LIBSOURCE_DIRS=[ util.get_projectlib_dir(), util.get_projectlibdeps_dir(), join("$PIOHOME_DIR", "lib") ], PYTHONEXE=util.get_pythonexe_path()) if not int(ARGUMENTS.get("PIOVERBOSE", 0)): DEFAULT_ENV_OPTIONS['ARCOMSTR'] = "Archiving $TARGET" DEFAULT_ENV_OPTIONS['LINKCOMSTR'] = "Linking $TARGET" DEFAULT_ENV_OPTIONS['RANLIBCOMSTR'] = "Indexing $TARGET" for k in ("ASCOMSTR", "ASPPCOMSTR", "CCCOMSTR", "CXXCOMSTR"): DEFAULT_ENV_OPTIONS[k] = "Compiling $TARGET" env = DefaultEnvironment(**DEFAULT_ENV_OPTIONS) # decode common variables for k in commonvars.keys(): if k in env: env[k] = base64.b64decode(env[k])
def cli(): # Update PlatformIO's Core packages update_core_packages(silent=True) latest = get_latest_version() if __version__ == latest: 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 = not all([c.isdigit() for c in latest if c != "."]) cmds = ([ "pip", "install", "--upgrade", "https://github.com/platformio/platformio-core/archive/develop.zip" if to_develop else "platformio" ], ["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( "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(1) else: raise exception.UpgradeError( "\n".join([str(cmd), r['out'], r['err']]))
PROJECTINCLUDE_DIR=util.get_projectinclude_dir(), PROJECTSRC_DIR=util.get_projectsrc_dir(), PROJECTTEST_DIR=util.get_projecttest_dir(), PROJECTDATA_DIR=util.get_projectdata_dir(), PROJECTBUILD_DIR=util.get_projectbuild_dir(), BUILD_DIR=join("$PROJECTBUILD_DIR", "$PIOENV"), BUILDSRC_DIR=join("$BUILD_DIR", "src"), BUILDTEST_DIR=join("$BUILD_DIR", "test"), LIBSOURCE_DIRS=[ util.get_projectlib_dir(), util.get_projectlibdeps_dir(), join("$PIOHOME_DIR", "lib") ], PROGNAME="program", PROG_PATH=join("$BUILD_DIR", "$PROGNAME$PROGSUFFIX"), PYTHONEXE=util.get_pythonexe_path()) if not int(ARGUMENTS.get("PIOVERBOSE", 0)): DEFAULT_ENV_OPTIONS['ARCOMSTR'] = "Archiving $TARGET" DEFAULT_ENV_OPTIONS['LINKCOMSTR'] = "Linking $TARGET" DEFAULT_ENV_OPTIONS['RANLIBCOMSTR'] = "Indexing $TARGET" for k in ("ASCOMSTR", "ASPPCOMSTR", "CCCOMSTR", "CXXCOMSTR"): DEFAULT_ENV_OPTIONS[k] = "Compiling $TARGET" env = DefaultEnvironment(**DEFAULT_ENV_OPTIONS) # decode common variables for k in commonvars.keys(): if k in env: env[k] = base64.b64decode(env[k]) if k in MULTILINE_VARS:
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