def _run_scons(self, variables, targets, jobs): args = [ get_pythonexe_path(), join(get_core_package_dir("tool-scons"), "script", "scons"), "-Q", "--warn=no-no-parallel-support", "--jobs", str(jobs), "--sconstruct", join(util.get_source_dir(), "builder", "main.py") ] # yapf: disable args.append("PIOVERBOSE=%d" % (1 if self.verbose else 0)) # pylint: disable=protected-access args.append("ISATTY=%d" % (1 if click._compat.isatty(sys.stdout) else 0)) args += targets # encode and append variables for key, value in variables.items(): args.append("%s=%s" % (key.upper(), self.encode_scons_arg(value))) def _write_and_flush(stream, data): try: stream.write(data) stream.flush() except IOError: pass copy_pythonpath_to_osenv() result = exec_command( args, stdout=BuildAsyncPipe( line_callback=self._on_stdout_line, data_callback=lambda data: _write_and_flush(sys.stdout, data)), stderr=BuildAsyncPipe( line_callback=self._on_stderr_line, data_callback=lambda data: _write_and_flush(sys.stderr, data))) return result
def get_platforms(cls, installed=False): platforms = {} for d in (util.get_home_dir(), util.get_source_dir()): pdir = join(d, "platforms") if not isdir(pdir): continue for p in listdir(pdir): if p in ("__init__.py", "base.py") or not p.endswith(".py"): continue type_ = p[:-3] path = join(pdir, p) try: isplatform = hasattr( cls.load_module(type_, path), cls.get_clsname(type_) ) if isplatform: platforms[type_] = path except exception.UnknownPlatform: pass if not installed: return platforms installed_platforms = {} for type_ in get_state_item("installed_platforms", []): if type_ in platforms: installed_platforms[type_] = platforms[type_] return installed_platforms
def update_create_platform_doc(): allpackages = get_packages() lines = [] lines.append(""".. _platform_creating_packages: Packages -------- *PlatformIO* has pre-built packages for the most popular operation systems: *Mac OS*, *Linux (+ARM)* and *Windows*. .. list-table:: :header-rows: 1 * - Name - Contents""") for type_, data in sorted(allpackages.iteritems()): contitems = [ "`%s <%s>`_" % (name, url) for name, url in allpackages[type_] ] lines.append(""" * - ``{type_}`` - {contents}""".format(type_=type_, contents=", ".join(contitems))) with open( join(util.get_source_dir(), "..", "docs", "platforms", "creating_platform.rst"), "r+") as fp: content = fp.read() fp.seek(0, 0) fp.write( content[:content.index(".. _platform_creating_packages:")] + "\n".join(lines) + "\n\n" + content[content.index(".. _platform_creating_manifest_file:"):])
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 get_platforms(cls, installed=False): platforms = {} for d in (util.get_home_dir(), util.get_source_dir()): pdir = join(d, "platforms") if not isdir(pdir): continue for p in listdir(pdir): if p in ("__init__.py", "base.py") or not p.endswith(".py"): continue type_ = p[:-3] path = join(pdir, p) try: isplatform = hasattr(cls.load_module(type_, path), cls.get_clsname(type_)) if isplatform: platforms[type_] = path except exception.UnknownPlatform: pass if not installed: return platforms installed_platforms = {} for type_ in get_state_item("installed_platforms", []): if type_ in platforms: installed_platforms[type_] = platforms[type_] return installed_platforms
def update_create_platform_doc(): lines = [] lines.append(""".. _platform_creating_packages: Packages -------- *PlatformIO* has pre-built packages for the most popular operation systems: *Mac OS*, *Linux (+ARM)* and *Windows*. .. list-table:: :header-rows: 1 * - Name - Contents""") for name, items in sorted(API_PACKAGES.iteritems()): contitems = ["`{name} <{url}>`_".format(**item) for item in items] lines.append(""" * - ``{name}`` - {contents}""".format( name=name, contents=", ".join(contitems))) with open( join(util.get_source_dir(), "..", "docs", "platforms", "creating_platform.rst"), "r+") as fp: content = fp.read() fp.seek(0, 0) fp.write(content[:content.index(".. _platform_creating_packages:")] + "\n".join(lines) + "\n\n" + content[content.index( ".. _platform_creating_manifest_file:"):])
def update_create_platform_doc(): lines = [] lines.append(""".. _platform_creating_packages: Packages -------- *PlatformIO* has pre-built packages for the most popular operation systems: *Mac OS*, *Linux (+ARM)* and *Windows*. .. list-table:: :header-rows: 1 * - Name - Description""") for name, items in sorted(API_PACKAGES.iteritems()): lines.append(""" * - `{name} <{url}>`__ - {description}""".format(name=name, url=API_PACKAGES[name]['url'], description=API_PACKAGES[name]['description'])) with open( join(util.get_source_dir(), "..", "docs", "platforms", "creating_platform.rst"), "r+") as fp: content = fp.read() fp.seek(0) fp.truncate() fp.write( content[:content.index(".. _platform_creating_packages:")] + "\n".join(lines) + "\n\n" + content[content.index(".. _platform_creating_manifest_file:"):])
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 update_create_platform_doc(): lines = [] lines.append(""".. _platform_creating_packages: Packages -------- *PlatformIO* has pre-built packages for the most popular operation systems: *Mac OS*, *Linux (+ARM)* and *Windows*. .. list-table:: :header-rows: 1 * - Name - Description""") for name, items in sorted(API_PACKAGES.iteritems()): lines.append(""" * - `{name} <{url}>`__ - {description}""".format( name=name, url=API_PACKAGES[name]['url'], description=API_PACKAGES[name]['description'])) with open( join(util.get_source_dir(), "..", "docs", "platforms", "creating_platform.rst"), "r+") as fp: content = fp.read() fp.seek(0) fp.truncate() fp.write(content[:content.index(".. _platform_creating_packages:")] + "\n".join(lines) + "\n\n" + content[content.index( ".. _platform_creating_manifest_file:"):])
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_tpls(self): tpls = [] tpls_dir = join(util.get_source_dir(), "ide", "tpls", self.ide) for root, _, files in walk(tpls_dir): for f in files: if f.endswith(".tpl"): tpls.append((root.replace(tpls_dir, ""), join(root, f))) return tpls
def get_tpls(self): tpls = [] tpls_dir = join(util.get_source_dir(), "ide", "tpls", self.ide) for root, _, files in walk(tpls_dir): for f in files: if f.endswith(".tpl"): tpls.append(( root.replace(tpls_dir, ""), join(root, f))) return tpls
def list_commands(self, ctx): cmds = [] for filename in listdir(join(get_source_dir(), "commands")): if filename.startswith("__init__"): continue if filename.endswith(".py"): cmds.append(filename[:-3]) cmds.sort() return cmds
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 self.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.SConsNotInstalled() assert "returncode" in result # if self._found_error: # result['returncode'] = 1 if self._last_echo_line == ".": click.echo("") return result
def get_tpls(self): tpls = [] tpls_dir = join(util.get_source_dir(), "ide", "tpls", self.ide) for root, _, files in os.walk(tpls_dir): for f in files: if not f.endswith(".tpl"): continue _relpath = root.replace(tpls_dir, "") if _relpath.startswith(os.sep): _relpath = _relpath[1:] tpls.append((_relpath, join(root, f))) return tpls
def update_examples_readme(): examples_dir = join(util.get_source_dir(), "..", "examples") # Platforms embedded = [] desktop = [] for manifest in PLATFORM_MANIFESTS: p = PlatformFactory.newPlatform(manifest['name']) url = campaign_url( "http://docs.platformio.org/en/latest/platforms/%s.html#examples" % p.name, source="github", medium="examples") line = "* [%s](%s)" % (p.title, url) if p.is_embedded(): embedded.append(line) else: desktop.append(line) # Frameworks frameworks = [] for framework in API_FRAMEWORKS: url = campaign_url( "http://docs.platformio.org/en/latest/frameworks/%s.html#examples" % framework['name'], source="github", medium="examples") frameworks.append("* [%s](%s)" % (framework['title'], url)) with open(join(examples_dir, "README.md"), "w") as fp: fp.write("""# PlatformIO Project Examples - [Development platforms](#development-platforms): - [Embedded](#embedded) - [Desktop](#desktop) - [Frameworks](#frameworks) ## Development platforms ### Embedded %s ### Desktop %s ## Frameworks %s """ % ("\n".join(embedded), "\n".join(desktop), "\n".join(frameworks)))
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 init_base_project(project_dir): if not util.is_platformio_project(project_dir): copyfile(join(util.get_source_dir(), "projectconftpl.ini"), join(project_dir, "platformio.ini")) with util.cd(project_dir): lib_dir = util.get_projectlib_dir() src_dir = util.get_projectsrc_dir() for d in (src_dir, lib_dir): if not isdir(d): makedirs(d) init_lib_readme(lib_dir) init_ci_conf(project_dir) init_cvs_ignore(project_dir)
def cli(): if isfile("platformio.ini") and isdir("src"): raise ProjectInitialized() for d in ("lib", "src"): if not isdir(d): makedirs(d) if not isfile("platformio.ini"): copyfile(join(get_source_dir(), "projectconftpl.ini"), "platformio.ini") secho("Project has been initialized!\n" "Please put your source code to `src` directory, " "external libraries to `lib` and " "setup environments in `platformio.ini` file.\n" "Then process project with `platformio run` command.", fg="green")
def cli(project_dir, board, disable_auto_uploading): project_file = join(project_dir, "platformio.ini") src_dir = join(project_dir, "src") lib_dir = join(project_dir, "lib") if all([isfile(project_file), isdir(src_dir), isdir(lib_dir)]): raise ProjectInitialized() builtin_boards = set(get_boards().keys()) if board and not set(board).issubset(builtin_boards): raise UnknownBoard(", ".join(set(board).difference(builtin_boards))) if project_dir == getcwd(): click.secho("The current working directory", fg="yellow", nl=False) click.secho(" %s " % project_dir, fg="cyan", nl=False) click.secho( "will be used for the new project.\n" "You can specify another project directory via\n" "`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.\n", fg="yellow") click.echo("The next files/directories will be created in %s" % click.style(project_dir, fg="cyan")) click.echo("%s - Project Configuration File" % click.style("platformio.ini", fg="cyan")) click.echo("%s - a source directory. Put your source code here" % click.style("src", fg="cyan")) click.echo("%s - a directory for the project specific libraries" % click.style("lib", fg="cyan")) if (not app.get_setting("enable_prompts") or click.confirm("Do you want to continue?")): for d in (src_dir, lib_dir): if not isdir(d): makedirs(d) if not isfile(project_file): copyfile(join(get_source_dir(), "projectconftpl.ini"), project_file) if board: fill_project_envs(project_file, board, disable_auto_uploading) click.secho( "Project has been successfully initialized!\n" "Now you can process it with `platformio run` command.", fg="green") else: click.secho("Aborted by user", fg="red")
def check_platformio_upgrade(): last_check = app.get_state_item("last_check", {}) interval = int(app.get_setting("check_platformio_interval")) * 3600 * 24 if (time() - interval) < last_check.get("platformio_upgrade", 0): return last_check['platformio_upgrade'] = int(time()) app.set_state_item("last_check", last_check) util.internet_on(raise_exception=True) # Update PlatformIO's Core packages update_core_packages(silent=True) latest_version = get_latest_version() if semantic_version.Version.coerce(util.pepver_to_semver( latest_version)) <= semantic_version.Version.coerce( util.pepver_to_semver(__version__)): return terminal_width, _ = click.get_terminal_size() click.echo("") click.echo("*" * terminal_width) click.secho("There is a new version %s of PlatformIO available.\n" "Please upgrade it via `" % latest_version, fg="yellow", nl=False) if getenv("PLATFORMIO_IDE"): click.secho("PlatformIO IDE Menu: Upgrade PlatformIO", fg="cyan", nl=False) click.secho("`.", fg="yellow") elif join("Cellar", "platformio") in util.get_source_dir(): click.secho("brew update && brew upgrade", fg="cyan", nl=False) click.secho("` command.", fg="yellow") else: click.secho("platformio upgrade", fg="cyan", nl=False) click.secho("` or `", fg="yellow", nl=False) click.secho("pip install -U platformio", fg="cyan", nl=False) click.secho("` command.", fg="yellow") click.secho("Changes: ", fg="yellow", nl=False) click.secho("https://docs.platformio.org/en/latest/history.html", fg="cyan") click.echo("*" * terminal_width) click.echo("")
def check_platformio_upgrade(): last_check = app.get_state_item("last_check", {}) interval = int(app.get_setting("check_platformio_interval")) * 3600 * 24 if (time() - interval) < last_check.get("platformio_upgrade", 0): return last_check['platformio_upgrade'] = int(time()) app.set_state_item("last_check", last_check) util.internet_on(raise_exception=True) # Update PlatformIO's Core packages update_core_packages(silent=True) latest_version = get_latest_version() if semantic_version.Version.coerce(util.pepver_to_semver( latest_version)) <= semantic_version.Version.coerce( util.pepver_to_semver(__version__)): return terminal_width, _ = click.get_terminal_size() click.echo("") click.echo("*" * terminal_width) click.secho( "There is a new version %s of PlatformIO available.\n" "Please upgrade it via `" % latest_version, fg="yellow", nl=False) if getenv("PLATFORMIO_IDE"): click.secho( "PlatformIO IDE Menu: Upgrade PlatformIO", fg="cyan", nl=False) click.secho("`.", fg="yellow") elif join("Cellar", "platformio") in util.get_source_dir(): click.secho("brew update && brew upgrade", fg="cyan", nl=False) click.secho("` command.", fg="yellow") else: click.secho("platformio upgrade", fg="cyan", nl=False) click.secho("` or `", fg="yellow", nl=False) click.secho("pip install -U platformio", fg="cyan", nl=False) click.secho("` command.", fg="yellow") click.secho("Changes: ", fg="yellow", nl=False) click.secho( "https://docs.platformio.org/en/latest/history.html", fg="cyan") click.echo("*" * terminal_width) click.echo("")
def init_base_project(project_dir): if not util.is_platformio_project(project_dir): copyfile(join(util.get_source_dir(), "projectconftpl.ini"), join(project_dir, "platformio.ini")) lib_dir = join(project_dir, "lib") src_dir = join(project_dir, "src") config = util.load_project_config(project_dir) if config.has_option("platformio", "src_dir"): src_dir = join(project_dir, config.get("platformio", "src_dir")) for d in (src_dir, lib_dir): if not isdir(d): makedirs(d) init_lib_readme(lib_dir) init_ci_conf(project_dir) init_cvs_ignore(project_dir)
def _lookup_platforms(cls): platforms = {} for d in (util.get_home_dir(), util.get_source_dir()): pdir = join(d, "platforms") if not isdir(pdir): continue for p in sorted(listdir(pdir)): if p in ("__init__.py", "base.py") or not p.endswith(".py"): continue type_ = p[:-3] path = join(pdir, p) try: isplatform = hasattr(cls.load_module(type_, path), cls.get_clsname(type_)) if isplatform: platforms[type_] = path except exception.UnknownPlatform: pass return platforms
def init_base_project(project_dir): if not util.is_platformio_project(project_dir): copyfile( join(util.get_source_dir(), "projectconftpl.ini"), join(project_dir, "platformio.ini")) lib_dir = join(project_dir, "lib") src_dir = join(project_dir, "src") config = util.load_project_config(project_dir) if config.has_option("platformio", "src_dir"): src_dir = join(project_dir, config.get("platformio", "src_dir")) for d in (src_dir, lib_dir): if not isdir(d): makedirs(d) init_lib_readme(lib_dir) init_ci_conf(project_dir) init_cvs_ignore(project_dir)
def _lookup_platforms(cls): platforms = {} for d in (util.get_home_dir(), util.get_source_dir()): pdir = join(d, "platforms") if not isdir(pdir): continue for p in sorted(os.listdir(pdir)): if (p in ("__init__.py", "base.py") or not p.endswith(".py")): continue type_ = p[:-3] path = join(pdir, p) try: isplatform = hasattr(cls.load_module(type_, path), cls.get_clsname(type_)) if isplatform: platforms[type_] = path except exception.UnknownPlatform: pass return platforms
def init_base_project(project_dir): if util.is_platformio_project(project_dir): return copyfile(join(util.get_source_dir(), "projectconftpl.ini"), join(project_dir, "platformio.ini")) with util.cd(project_dir): dir_to_readme = [ (util.get_projectsrc_dir(), None), (util.get_projectinclude_dir(), init_include_readme), (util.get_projectlib_dir(), init_lib_readme), (util.get_projecttest_dir(), init_test_readme), ] for (path, cb) in dir_to_readme: if isdir(path): continue makedirs(path) if cb: cb(path)
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 run(self, variables, targets): assert isinstance(variables, list) assert isinstance(targets, list) installed_platforms = PlatformFactory.get_platforms( installed=True).keys() installed_packages = PackageManager.get_installed() if self.get_name() not in installed_platforms: raise exception.PlatformNotInstalledYet(self.get_name()) 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 name not in installed_packages: continue variables.append("PIOPACKAGE_%s=%s" % (options['alias'].upper(), name)) try: result = exec_command([ "scons", "-Q", "-f", join(get_source_dir(), "builder", "main.py") ] + variables + targets) except OSError: raise exception.SConsNotInstalled() return self.after_run(result)
def init_base_project(project_dir): if util.is_platformio_project(project_dir): return copyfile( join(util.get_source_dir(), "projectconftpl.ini"), join(project_dir, "platformio.ini")) with util.cd(project_dir): dir_to_readme = [ (util.get_projectsrc_dir(), None), (util.get_projectinclude_dir(), init_include_readme), (util.get_projectlib_dir(), init_lib_readme), (util.get_projecttest_dir(), init_test_readme), ] for (path, cb) in dir_to_readme: if isdir(path): continue makedirs(path) if cb: cb(path)
def pioplus_call(args, **kwargs): if WINDOWS 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)) pioplus_path = join(get_core_package_dir("tool-pioplus"), "pioplus") pythonexe_path = get_pythonexe_path() os.environ['PYTHONEXEPATH'] = pythonexe_path os.environ['PYTHONPYSITEDIR'] = get_core_package_dir("contrib-pysite") os.environ['PIOCOREPYSITEDIR'] = dirname(util.get_source_dir() or "") if dirname(pythonexe_path) not in os.environ['PATH'].split(os.pathsep): os.environ['PATH'] = (os.pathsep).join( [dirname(pythonexe_path), os.environ['PATH']]) 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) return True
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)) pioplus_path = join(get_core_package_dir("tool-pioplus"), "pioplus") pythonexe_path = util.get_pythonexe_path() os.environ['PYTHONEXEPATH'] = pythonexe_path os.environ['PYTHONPYSITEDIR'] = get_core_package_dir("contrib-pysite") os.environ['PIOCOREPYSITEDIR'] = dirname(util.get_source_dir() or "") os.environ['PATH'] = (os.pathsep).join( [dirname(pythonexe_path), os.environ['PATH']]) 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) return True
def update_create_platform_doc(): allpackages = get_packages() lines = [] lines.append(""".. _platform_creating_packages: Packages -------- *PlatformIO* has pre-built packages for the most popular operation systems: *Mac OS*, *Linux (+ARM)* and *Windows*. .. list-table:: :header-rows: 1 * - Name - Contents""") for type_, data in sorted(allpackages.iteritems()): contitems = [ "`%s <%s>`_" % (name, url) for name, url in allpackages[type_] ] lines.append(""" * - ``{type_}`` - {contents}""".format( type_=type_, contents=", ".join(contitems))) with open(join(util.get_source_dir(), "..", "docs", "platforms", "creating_platform.rst"), "r+") as fp: content = fp.read() fp.seek(0, 0) fp.write( content[:content.index(".. _platform_creating_packages:")] + "\n".join(lines) + "\n\n" + content[content.index(".. _platform_creating_manifest_file:"):] )
def get_supported_ides(): tpls_dir = join(util.get_source_dir(), "ide", "tpls") return sorted( [d for d in os.listdir(tpls_dir) if isdir(join(tpls_dir, d))])
("UPLOAD_PROTOCOL", ), ("UPLOAD_SPEED", )) DefaultEnvironment(tools=[ "gcc", "g++", "as", "ar", "gnulink", "platformio", "pioupload", "pioar", "piomisc" ], toolpath=[join("$PIOBUILDER_DIR", "tools")], variables=commonvars, UNIX_TIME=int(time()), PIOHOME_DIR=util.get_home_dir(), PROJECT_DIR=util.get_project_dir(), PROJECTLIB_DIR=util.get_projectlib_dir(), PROJECTSRC_DIR=util.get_projectsrc_dir(), PIOENVS_DIR=util.get_pioenvs_dir(), PIOBUILDER_DIR=join(util.get_source_dir(), "builder"), PIOPACKAGES_DIR=join("$PIOHOME_DIR", "packages"), BUILD_DIR=join("$PIOENVS_DIR", "$PIOENV"), BUILDSRC_DIR=join("$BUILD_DIR", "src"), LIBSOURCE_DIRS=[ "$PROJECTLIB_DIR", util.get_lib_dir(), join("$PLATFORMFW_DIR", "libraries") ]) env = DefaultEnvironment() if "BOARD" in env: try: env.Replace(BOARD_OPTIONS=util.get_boards(env.subst("$BOARD"))) except UnknownBoard as e:
def cli(ctx, project_dir, board, ide, # pylint: disable=R0913 enable_auto_uploading, env_prefix): if project_dir == getcwd(): click.secho("\nThe current working directory", fg="yellow", nl=False) click.secho(" %s " % project_dir, fg="cyan", nl=False) click.secho( "will be used for project.\n" "You can specify another project directory via\n" "`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.", fg="yellow" ) click.echo("") click.echo("The next files/directories will be created in %s" % click.style(project_dir, fg="cyan")) click.echo("%s - Project Configuration File. |-> PLEASE EDIT ME <-|" % click.style("platformio.ini", fg="cyan")) click.echo("%s - Put your source files here" % click.style("src", fg="cyan")) click.echo("%s - Put here project specific (private) libraries" % click.style("lib", fg="cyan")) if (app.get_setting("enable_prompts") and not click.confirm("Do you want to continue?")): raise exception.AbortedByUser() project_file = join(project_dir, "platformio.ini") src_dir = join(project_dir, "src") lib_dir = join(project_dir, "lib") for d in (src_dir, lib_dir): if not isdir(d): makedirs(d) init_lib_readme(lib_dir) init_ci_conf(project_dir) init_cvs_ignore(project_dir) if not isfile(project_file): copyfile(join(get_source_dir(), "projectconftpl.ini"), project_file) if board: fill_project_envs( ctx, project_file, board, enable_auto_uploading, env_prefix, ide is not None ) if ide: if not board: raise exception.BoardNotDefined() if len(board) > 1: click.secho( "Warning! You have initialised project with more than 1 board" " for the specified IDE.\n" "However, the IDE features (code autocompletion, syntax lint)" " have been configured for the first board '%s' from your list" " '%s'." % (board[0], ", ".join(board)), fg="yellow" ) pg = ProjectGenerator( project_dir, ide, board[0]) pg.generate() click.secho( "\nProject has been successfully initialized!\nUseful commands:\n" "`platformio run` - process/build project from the current " "directory\n" "`platformio run --target upload` or `platformio run -t upload` " "- upload firmware to embedded board\n" "`platformio run --target clean` - clean project (remove compiled " "files)\n" "`platformio run --help` - additional information", fg="green" )
def cli( ctx, project_dir, board, ide, # pylint: disable=R0913 disable_auto_uploading, env_prefix): # ask about auto-uploading if board and app.get_setting("enable_prompts"): disable_auto_uploading = not click.confirm( "Would you like to enable firmware auto-uploading when project " "is successfully built using `platformio run` command? \n" "Don't forget that you can upload firmware manually using " "`platformio run --target upload` command.") click.echo("") if project_dir == getcwd(): click.secho("\nThe current working directory", fg="yellow", nl=False) click.secho(" %s " % project_dir, fg="cyan", nl=False) click.secho( "will be used for project.\n" "You can specify another project directory via\n" "`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.", fg="yellow") click.echo("") click.echo("The next files/directories will be created in %s" % click.style(project_dir, fg="cyan")) click.echo("%s - Project Configuration File. |-> PLEASE EDIT ME <-|" % click.style("platformio.ini", fg="cyan")) click.echo("%s - Put your source files here" % click.style("src", fg="cyan")) click.echo("%s - Put here project specific (private) libraries" % click.style("lib", fg="cyan")) if (app.get_setting("enable_prompts") and not click.confirm("Do you want to continue?")): raise exception.AbortedByUser() project_file = join(project_dir, "platformio.ini") src_dir = join(project_dir, "src") lib_dir = join(project_dir, "lib") for d in (src_dir, lib_dir): if not isdir(d): makedirs(d) if not isfile(join(lib_dir, "readme.txt")): with open(join(lib_dir, "readme.txt"), "w") as f: f.write(""" This directory is intended for the project specific (private) libraries. PlatformIO will compile them to static libraries and link to executable file. The source code of each library should be placed in separate directory, like "lib/private_lib/[here are source files]". For example, see how can be organised `Foo` and `Bar` libraries: |--lib | |--Bar | | |--docs | | |--examples | | |--src | | |- Bar.c | | |- Bar.h | |--Foo | | |- Foo.c | | |- Foo.h | |- readme.txt --> THIS FILE |- platformio.ini |--src |- main.c Then in `src/main.c` you should use: #include <Foo.h> #include <Bar.h> // rest H/C/CPP code PlatformIO will find your libraries automatically, configure preprocessor's include paths and build them. See additional options for PlatformIO Library Dependency Finder `lib_*`: http://docs.platformio.org/en/latest/projectconf.html#lib-install """) if not isfile(project_file): copyfile(join(get_source_dir(), "projectconftpl.ini"), project_file) if board: fill_project_envs(ctx, project_file, board, disable_auto_uploading, env_prefix) if ide: pg = ProjectGenerator(project_dir, ide, board[0] if board else None) pg.generate() click.secho( "\nProject has been successfully initialized!\nUseful commands:\n" "`platformio run` - process/build project from the current " "directory\n" "`platformio run --target upload` or `platformio run -t upload` " "- upload firmware to embedded board\n" "`platformio run --target clean` - clean project (remove compiled " "files)", fg="green")
variables=commonvars, # Propagating External Environment ENV=environ, UNIX_TIME=int(time()), PROGNAME="program", PIOHOME_DIR=util.get_home_dir(), PROJECT_DIR=util.get_project_dir(), PROJECTLIB_DIR=util.get_projectlib_dir(), PROJECTSRC_DIR=util.get_projectsrc_dir(), PROJECTDATA_DIR=util.get_projectdata_dir(), PIOENVS_DIR=util.get_pioenvs_dir(), PIOBUILDER_DIR=join(util.get_source_dir(), "builder"), PIOPACKAGES_DIR=join("$PIOHOME_DIR", "packages"), BUILD_DIR=join("$PIOENVS_DIR", "$PIOENV"), BUILDSRC_DIR=join("$BUILD_DIR", "src"), LIBSOURCE_DIRS=[ "$PROJECTLIB_DIR", util.get_lib_dir(), join("$PLATFORMFW_DIR", "libraries") ], PYTHONEXE=normpath(sys.executable) ) env = DefaultEnvironment() env.Prepend(LIBPATH=[join("$PIOPACKAGES_DIR", "ldscripts")])
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 update_debugging(): vendors = {} platforms = [] frameworks = [] for data in BOARDS: if not data['debug']: continue platforms.append(data['platform']) frameworks.extend(data['frameworks']) vendor = data['vendor'] if vendor in vendors: vendors[vendor].append(data) else: vendors[vendor] = [data] lines = [] # Platforms lines.append(""".. _debugging_platforms: Platforms --------- .. list-table:: :header-rows: 1 * - Name - Description""") for manifest in PLATFORM_MANIFESTS: if manifest['name'] not in platforms: continue p = PlatformFactory.newPlatform(manifest['name']) lines.append(""" * - :ref:`platform_{type_}` - {description}""".format( type_=manifest['name'], description=p.description)) # Frameworks lines.append(""" Frameworks ---------- .. list-table:: :header-rows: 1 * - Name - Description""") for framework in API_FRAMEWORKS: if framework['name'] not in frameworks: continue lines.append(""" * - :ref:`framework_{name}` - {description}""".format(**framework)) # Boards lines.append(""" Boards ------ .. note:: For more detailed ``board`` information please scroll tables below by horizontal. """) for vendor, boards in sorted(vendors.iteritems()): lines.append(str(vendor)) lines.append("~" * len(vendor)) lines.extend(generate_boards(boards, extend_debug=True)) with open( join(util.get_source_dir(), "..", "docs", "plus", "debugging.rst"), "r+") as fp: content = fp.read() fp.seek(0) fp.truncate() fp.write(content[:content.index(".. _debugging_platforms:")] + "\n".join(lines))
def cli(project_dir, board, ide, disable_auto_uploading, env_prefix): # ask about auto-uploading if board and app.get_setting("enable_prompts"): disable_auto_uploading = not click.confirm( "Would you like to enable firmware auto-uploading when project " "is successfully built using `platformio run` command? \n" "Don't forget that you can upload firmware manually using " "`platformio run --target upload` command.") click.echo("") if project_dir == getcwd(): click.secho("\nThe current working directory", fg="yellow", nl=False) click.secho(" %s " % project_dir, fg="cyan", nl=False) click.secho( "will be used for project.\n" "You can specify another project directory via\n" "`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.", fg="yellow") click.echo("") click.echo("The next files/directories will be created in %s" % click.style(project_dir, fg="cyan")) click.echo("%s - Project Configuration File. |-> PLEASE EDIT ME <-|" % click.style("platformio.ini", fg="cyan")) click.echo("%s - Put your source code here" % click.style("src", fg="cyan")) click.echo("%s - Put here project specific or 3-rd party libraries" % click.style("lib", fg="cyan")) if (app.get_setting("enable_prompts") and not click.confirm("Do you want to continue?")): raise exception.AbortedByUser() project_file = join(project_dir, "platformio.ini") src_dir = join(project_dir, "src") lib_dir = join(project_dir, "lib") for d in (src_dir, lib_dir): if not isdir(d): makedirs(d) if not isfile(project_file): copyfile(join(get_source_dir(), "projectconftpl.ini"), project_file) if board: fill_project_envs(project_file, board, disable_auto_uploading, env_prefix) if ide: pg = ProjectGenerator(project_dir, ide) pg.generate() click.secho( "\nProject has been successfully initialized!\nUseful commands:\n" "`platformio run` - process/build project from the current " "directory\n" "`platformio run --target upload` or `platformio run -t upload` " "- upload firmware to embedded board\n" "`platformio run --target clean` - clean project (remove compiled " "files)", fg="green")
("DEBUG_TOOL",), ) # yapf: disable MULTILINE_VARS = [ "EXTRA_SCRIPTS", "PIOFRAMEWORK", "BUILD_FLAGS", "SRC_BUILD_FLAGS", "BUILD_UNFLAGS", "SRC_FILTER", "LIB_DEPS", "LIB_IGNORE", "LIB_EXTRA_DIRS" ] DEFAULT_ENV_OPTIONS = dict( tools=[ "ar", "gas", "gcc", "g++", "gnulink", "platformio", "pioplatform", "piowinhooks", "piolib", "pioupload", "piomisc", "pioide" ], # yapf: disable toolpath=[join(util.get_source_dir(), "builder", "tools")], variables=commonvars, # Propagating External Environment PIOVARIABLES=commonvars.keys(), ENV=environ, UNIX_TIME=int(time()), PIOHOME_DIR=util.get_home_dir(), PROJECT_DIR=util.get_project_dir(), 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"),
def cli(ctx, project_dir, board, ide, # pylint: disable=R0913 disable_auto_uploading, env_prefix): # ask about auto-uploading if board and app.get_setting("enable_prompts"): disable_auto_uploading = not click.confirm( "Would you like to enable firmware auto-uploading when project " "is successfully built using `platformio run` command? \n" "Don't forget that you can upload firmware manually using " "`platformio run --target upload` command." ) click.echo("") if project_dir == getcwd(): click.secho("\nThe current working directory", fg="yellow", nl=False) click.secho(" %s " % project_dir, fg="cyan", nl=False) click.secho( "will be used for project.\n" "You can specify another project directory via\n" "`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.", fg="yellow" ) click.echo("") click.echo("The next files/directories will be created in %s" % click.style(project_dir, fg="cyan")) click.echo("%s - Project Configuration File. |-> PLEASE EDIT ME <-|" % click.style("platformio.ini", fg="cyan")) click.echo("%s - Put your source files here" % click.style("src", fg="cyan")) click.echo("%s - Put here project specific (private) libraries" % click.style("lib", fg="cyan")) if (app.get_setting("enable_prompts") and not click.confirm("Do you want to continue?")): raise exception.AbortedByUser() project_file = join(project_dir, "platformio.ini") src_dir = join(project_dir, "src") lib_dir = join(project_dir, "lib") for d in (src_dir, lib_dir): if not isdir(d): makedirs(d) if not isfile(join(lib_dir, "readme.txt")): with open(join(lib_dir, "readme.txt"), "w") as f: f.write(""" This directory is intended for the project specific (private) libraries. PlatformIO will compile them to static libraries and link to executable file. The source code of each library should be placed in separate directory, like "lib/private_lib/[here are source files]". For example, see how can be organised `Foo` and `Bar` libraries: |--lib | |--Bar | | |--docs | | |--examples | | |--src | | |- Bar.c | | |- Bar.h | |--Foo | | |- Foo.c | | |- Foo.h | |- readme.txt --> THIS FILE |- platformio.ini |--src |- main.c Then in `src/main.c` you should use: #include <Foo.h> #include <Bar.h> // rest H/C/CPP code PlatformIO will find your libraries automatically, configure preprocessor's include paths and build them. See additional options for PlatformIO Library Dependency Finder `lib_*`: http://docs.platformio.org/en/latest/projectconf.html#lib-install """) if not isfile(project_file): copyfile(join(get_source_dir(), "projectconftpl.ini"), project_file) if board: fill_project_envs( ctx, project_file, board, disable_auto_uploading, env_prefix) if ide: pg = ProjectGenerator(project_dir, ide, board[0] if board else None) pg.generate() click.secho( "\nProject has been successfully initialized!\nUseful commands:\n" "`platformio run` - process/build project from the current " "directory\n" "`platformio run --target upload` or `platformio run -t upload` " "- upload firmware to embedded board\n" "`platformio run --target clean` - clean project (remove compiled " "files)", fg="green" )
("BOARD_FLASH_MODE",), # upload options ("UPLOAD_PORT",), ("UPLOAD_PROTOCOL",), ("UPLOAD_SPEED",), ("UPLOAD_FLAGS",), ("UPLOAD_RESETMETHOD",) ) # yapf: disable DEFAULT_ENV_OPTIONS = dict( tools=[ "ar", "as", "gcc", "g++", "gnulink", "platformio", "pioplatform", "piowinhooks", "piolib", "piotest", "pioupload", "piomisc" ], # yapf: disable toolpath=[join(util.get_source_dir(), "builder", "tools")], variables=commonvars, # Propagating External Environment PIOVARIABLES=commonvars.keys(), ENV=environ, UNIX_TIME=int(time()), 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"),
def cli(project_dir, board, disable_auto_uploading): project_file = join(project_dir, "platformio.ini") src_dir = join(project_dir, "src") lib_dir = join(project_dir, "lib") if all([isfile(project_file), isdir(src_dir), isdir(lib_dir)]): raise exception.ProjectInitialized() builtin_boards = set(get_boards().keys()) if board and not set(board).issubset(builtin_boards): raise exception.UnknownBoard( ", ".join(set(board).difference(builtin_boards))) # ask about auto-uploading if board and app.get_setting("enable_prompts"): disable_auto_uploading = not click.confirm( "\nWould you like to enable firmware auto-uploading when project " "is successfully built using `platformio run` command? \n" "Don't forget that you can upload firmware manually using " "`platformio run --target upload` command." ) if project_dir == getcwd(): click.secho("\nThe current working directory", fg="yellow", nl=False) click.secho(" %s " % project_dir, fg="cyan", nl=False) click.secho( "will be used for the new project.\n" "You can specify another project directory via\n" "`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.\n", fg="yellow" ) click.echo("The next files/directories will be created in %s" % click.style(project_dir, fg="cyan")) click.echo("%s - Project Configuration File. |-> PLEASE EDIT ME <-|" % click.style("platformio.ini", fg="cyan")) click.echo("%s - Put your source code here" % click.style("src", fg="cyan")) click.echo("%s - Put here project specific or 3-rd party libraries" % click.style("lib", fg="cyan")) if (not app.get_setting("enable_prompts") or click.confirm("Do you want to continue?")): for d in (src_dir, lib_dir): if not isdir(d): makedirs(d) if not isfile(project_file): copyfile(join(get_source_dir(), "projectconftpl.ini"), project_file) if board: fill_project_envs(project_file, board, disable_auto_uploading) click.secho( "Project has been successfully initialized!\nUseful commands:\n" "`platformio run` - process/build project from the current " "directory\n" "`platformio run --target upload` or `platformio run -t upload` " "- upload firmware to embedded board\n" "`platformio run --target clean` - clean project (remove compiled " "files)", fg="green" ) else: raise exception.AbortedByUser()
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 try: # test that SCons is installed correctly assert util.test_scons() result = util.exec_command( [ "scons", "-Q", "-j %d" % self.get_job_nums(), "--warn=no-no-parallel-support", "-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 update_project_examples(): platform_readme_tpl = """ # {title}: development platform for [PlatformIO](https://platformio.org) {description} * [Home](https://platformio.org/platforms/{name}) (home page in PlatformIO Registry) * [Documentation](https://docs.platformio.org/page/platforms/{name}.html) (advanced usage, packages, boards, frameworks, etc.) # Examples {examples} """ framework_readme_tpl = """ # {title}: framework for [PlatformIO](https://platformio.org) {description} * [Home](https://platformio.org/frameworks/{name}) (home page in PlatformIO Registry) * [Documentation](https://docs.platformio.org/page/frameworks/{name}.html) # Examples {examples} """ project_examples_dir = join(util.get_source_dir(), "..", "examples") framework_examples_md_lines = {} embedded = [] desktop = [] for manifest in PLATFORM_MANIFESTS: p = PlatformFactory.newPlatform(manifest['name']) github_url = p.repository_url[:-4] # Platform README platform_examples_dir = join(p.get_dir(), "examples") examples_md_lines = [] if isdir(platform_examples_dir): for item in os.listdir(platform_examples_dir): if not isdir(join(platform_examples_dir, item)): continue url = "%s/tree/master/examples/%s" % (github_url, item) examples_md_lines.append("* [%s](%s)" % (item, url)) readme_dir = join(project_examples_dir, "platforms", p.name) if not isdir(readme_dir): os.makedirs(readme_dir) with open(join(readme_dir, "README.md"), "w") as fp: fp.write( platform_readme_tpl.format( name=p.name, title=p.title, description=p.description, examples="\n".join(examples_md_lines))) # Framework README for framework in API_FRAMEWORKS: if not is_compat_platform_and_framework(p.name, framework['name']): continue if framework['name'] not in framework_examples_md_lines: framework_examples_md_lines[framework['name']] = [] lines = [] lines.append("- [%s](%s)" % (p.title, github_url)) lines.extend(" %s" % l for l in examples_md_lines) lines.append("") framework_examples_md_lines[framework['name']].extend(lines) # Root README line = "* [%s](%s)" % (p.title, "%s/tree/master/examples" % github_url) if p.is_embedded(): embedded.append(line) else: desktop.append(line) # Frameworks frameworks = [] for framework in API_FRAMEWORKS: readme_dir = join(project_examples_dir, "frameworks", framework['name']) if not isdir(readme_dir): os.makedirs(readme_dir) with open(join(readme_dir, "README.md"), "w") as fp: fp.write( framework_readme_tpl.format( name=framework['name'], title=framework['title'], description=framework['description'], examples="\n".join( framework_examples_md_lines[framework['name']]))) url = campaign_url( "https://docs.platformio.org/en/latest/frameworks/%s.html#examples" % framework['name'], source="github", medium="examples") frameworks.append("* [%s](%s)" % (framework['title'], url)) with open(join(project_examples_dir, "README.md"), "w") as fp: fp.write("""# PlatformIO Project Examples - [Development platforms](#development-platforms): - [Embedded](#embedded) - [Desktop](#desktop) - [Frameworks](#frameworks) ## Development platforms ### Embedded %s ### Desktop %s ## Frameworks %s """ % ("\n".join(embedded), "\n".join(desktop), "\n".join(frameworks)))
def update_framework_docs(): for name, data in util.get_frameworks().items(): rst_path = join(util.get_source_dir(), "..", "docs", "frameworks", "%s.rst" % name) with open(rst_path, "w") as f: f.write(generate_framework(name, data))
def get_build_script(self): builtin = join(util.get_source_dir(), "builder", "scripts", "%s.py" % self.get_type()) if isfile(builtin): return builtin raise NotImplementedError()