def cli(ctx, **options): non_storage_cmds = ("search", "show", "register", "stats", "builtin") # skip commands that don't need storage folder if ctx.invoked_subcommand in non_storage_cmds or \ (len(ctx.args) == 2 and ctx.args[1] in ("-h", "--help")): return storage_dir = options['storage_dir'] if not storage_dir: if options['global']: storage_dir = join(util.get_home_dir(), "lib") elif util.is_platformio_project(): storage_dir = util.get_projectlibdeps_dir() elif util.is_ci(): storage_dir = join(util.get_home_dir(), "lib") click.secho( "Warning! Global library storage is used automatically. " "Please use `platformio lib --global %s` command to remove " "this warning." % ctx.invoked_subcommand, fg="yellow") elif util.is_platformio_project(storage_dir): with util.cd(storage_dir): storage_dir = util.get_projectlibdeps_dir() if not storage_dir and not util.is_platformio_project(): raise exception.NotGlobalLibDir(util.get_project_dir(), join(util.get_home_dir(), "lib"), ctx.invoked_subcommand) ctx.obj = LibraryManager(storage_dir) if "--json-output" not in ctx.args: click.echo("Library Storage: " + storage_dir)
def cli(ctx, **options): non_storage_cmds = ("search", "show", "register", "stats", "builtin") # skip commands that don't need storage folder if ctx.invoked_subcommand in non_storage_cmds or \ (len(ctx.args) == 2 and ctx.args[1] in ("-h", "--help")): return storage_dir = options['storage_dir'] if not storage_dir: if options['global']: storage_dir = join(util.get_home_dir(), "lib") elif util.is_platformio_project(): storage_dir = util.get_projectlibdeps_dir() elif util.is_ci(): storage_dir = join(util.get_home_dir(), "lib") click.secho( "Warning! Global library storage is used automatically. " "Please use `platformio lib --global %s` command to remove " "this warning." % ctx.invoked_subcommand, fg="yellow") if not storage_dir and not util.is_platformio_project(): raise exception.NotGlobalLibDir(util.get_project_dir(), join(util.get_home_dir(), "lib"), ctx.invoked_subcommand) ctx.obj = LibraryManager(storage_dir) if "--json-output" not in ctx.args: click.echo("Library Storage: " + storage_dir)
def autocheck_latest_version(): check_interval = 3600 * 24 * 7 # 1 week checkfile = join(get_home_dir(), ".pioupgrade") if isfile(checkfile) and getmtime(checkfile) > (time() - check_interval): return False if not isdir(get_home_dir()): makedirs(get_home_dir()) with open(checkfile, "w") as f: f.write(str(time())) return get_latest_version() != __version__
def test_pkg_name_parser(): items = [ ["PkgName", ("PkgName", None, None)], [("PkgName", "!=1.2.3,<2.0"), ("PkgName", "!=1.2.3,<2.0", None)], ["[email protected]", ("PkgName", "1.2.3", None)], [("[email protected]", "1.2.5"), ("[email protected]", "1.2.5", None)], ["id:13", ("id:13", None, None)], ["id:13@~1.2.3", ("id:13", "~1.2.3", None)], [util.get_home_dir(), (".platformio", None, "file://" + util.get_home_dir())], ["LocalName=" + util.get_home_dir(), ("LocalName", None, "file://" + util.get_home_dir())], ["https://github.com/user/package.git", ("package", None, "git+https://github.com/user/package.git")], ["https://gitlab.com/user/package.git", ("package", None, "git+https://gitlab.com/user/package.git")], ["https://github.com/user/package/archive/branch.zip", ("branch", None, "https://github.com/user/package/archive/branch.zip")], ["https://github.com/user/package/archive/branch.tar.gz", ("branch", None, "https://github.com/user/package/archive/branch.tar.gz")], ["https://developer.mbed.org/users/user/code/package/", ("package", None, "hg+https://developer.mbed.org/users/user/code/package/")], ["https://github.com/user/package#v1.2.3", ("package", None, "git+https://github.com/user/package#v1.2.3")], ["https://github.com/user/package.git#branch", ("package", None, "git+https://github.com/user/package.git#branch")], ["PkgName=https://github.com/user/package.git#a13d344fg56", ("PkgName", None, "git+https://github.com/user/package.git#a13d344fg56")], ["PkgName=user/package", ("PkgName", None, "git+https://github.com/user/package")], ["PkgName=user/package#master", ("PkgName", None, "git+https://github.com/user/package#master")], ["git+https://github.com/user/package", ("package", None, "git+https://github.com/user/package")], ["hg+https://example.com/user/package", ("package", None, "hg+https://example.com/user/package")], ["[email protected]:user/package.git", ("package", None, "[email protected]:user/package.git")], ["[email protected]:user/package.git#v1.2.0", ("package", None, "[email protected]:user/package.git#v1.2.0")] ] for params, result in items: if isinstance(params, tuple): assert BasePkgManager.parse_pkg_name(*params) == result else: assert BasePkgManager.parse_pkg_name(params) == result
def __init__(self): super(CorePackageManager, self).__init__( join(util.get_home_dir(), "packages"), [ "https://dl.bintray.com/platformio/dl-packages/manifest.json", "http%s://dl.platformio.org/packages/manifest.json" % ("" if sys.version_info < (2, 7, 9) else "s") ])
def test_get_package(isolated_pio_home): tests = [ [("unknown", ), None], [("1", ), None], [("id=1", "shasum"), dict(id=1, name="name_1", version="shasum")], [("id=1", "*"), dict(id=1, name="name_1", version="2.1.0")], [("id=1", "^1"), dict(id=1, name="name_1", version="1.2")], [("id=1", "^1"), dict(id=1, name="name_1", version="1.2")], [("name_1", "<2"), dict(id=1, name="name_1", version="1.2")], [("name_1", ">2"), None], [("name_1", "2-0-0"), None], [("name_2", ), dict(name="name_2", version="4.0.0")], [("url_has_higher_priority", None, "git+https://github.com"), dict(name="name_2", version="2.0.0", __src_url="git+https://github.com")], [("name_2", None, "git+https://github.com"), dict(name="name_2", version="2.0.0", __src_url="git+https://github.com")], ] pm = PackageManager(join(util.get_home_dir(), "packages")) for test in tests: manifest = pm.get_package(*test[0]) if test[1] is None: assert manifest is None, test continue for key, value in test[1].items(): assert manifest[key] == value, test
def get_boards(self, id_=None): def _append_board(board_id, manifest_path): config = PlatformBoardConfig(manifest_path) if "platform" in config and config.get("platform") != self.name: return elif ("platforms" in config and self.name not in config.get("platforms")): return config.manifest['platform'] = self.name self._BOARDS_CACHE[board_id] = config bdirs = (join(util.get_home_dir(), "boards"), join(self.get_dir(), "boards")) if id_ is None: for boards_dir in bdirs: if not isdir(boards_dir): continue for item in sorted(os.listdir(boards_dir)): _id = item[:-5] if not item.endswith(".json") or _id in self._BOARDS_CACHE: continue _append_board(_id, join(boards_dir, item)) else: if id_ not in self._BOARDS_CACHE: for boards_dir in bdirs: if not isdir(boards_dir): continue manifest_path = join(boards_dir, "%s.json" % id_) if not isfile(manifest_path): continue _append_board(id_, manifest_path) if id_ not in self._BOARDS_CACHE: raise exception.UnknownBoard(id_) return self._BOARDS_CACHE[id_] if id_ else self._BOARDS_CACHE
def __init__(self, path=None): self.path = path if not self.path: self.path = join(get_home_dir(), "appstate.json") self._state = {} self._prev_state = {} self._lock = None
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 test_install_packages(isolated_pio_home, tmpdir): packages = [ dict(id=1, name="name_1", version="shasum"), dict(id=1, name="name_1", version="2.0.0"), dict(id=1, name="name_1", version="2.1.0"), dict(id=1, name="name_1", version="1.2.0"), dict(id=1, name="name_1", version="1.0.0"), dict(name="name_2", version="1.0.0"), dict(name="name_2", version="2.0.0", __src_url="git+https://github.com"), dict(name="name_2", version="3.0.0", __src_url="git+https://github2.com"), dict(name="name_2", version="4.0.0", __src_url="git+https://github2.com") ] pm = PackageManager(join(util.get_home_dir(), "packages")) for package in packages: tmp_dir = tmpdir.mkdir("tmp-package") tmp_dir.join("package.json").write(json.dumps(package)) pm._install_from_url(package['name'], "file://%s" % str(tmp_dir)) tmp_dir.remove(rec=1) assert len(pm.get_installed()) == len(packages) - 1 pkg_dirnames = [ 'name_1_ID1', '[email protected]', '[email protected]', '[email protected]', 'name_1_ID1@shasum', 'name_2', 'name_2@src-177cbce1f0705580d17790fda1cc2ef5', 'name_2@src-f863b537ab00f4c7b5011fc44b120e1f' ] assert set([p.basename for p in isolated_pio_home.join( "packages").listdir()]) == set(pkg_dirnames)
def test_get_package(): tests = [ [("unknown", ), None], [("1", ), None], [("id=1", "shasum"), dict(id=1, name="name_1", version="shasum")], [("id=1", "*"), dict(id=1, name="name_1", version="2.1.0")], [("id=1", "^1"), dict(id=1, name="name_1", version="1.2")], [("id=1", "^1"), dict(id=1, name="name_1", version="1.2")], [("name_1", "<2"), dict(id=1, name="name_1", version="1.2")], [("name_1", ">2"), None], [("name_1", "2-0-0"), None], [("name_2", ), dict(name="name_2", version="4.0.0")], [("url_has_higher_priority", None, "git+https://github.com"), dict(name="name_2", version="2.0.0", __src_url="git+https://github.com")], [("name_2", None, "git+https://github.com"), dict(name="name_2", version="2.0.0", __src_url="git+https://github.com")], ] pm = PackageManager(join(util.get_home_dir(), "packages")) for test in tests: manifest = pm.get_package(*test[0]) if test[1] is None: assert manifest is None, test continue for key, value in test[1].items(): assert manifest[key] == value, test
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 __init__(self, cache_dir=None): self.cache_dir = None self._db_path = None self._lockfile = None self.cache_dir = cache_dir or join(util.get_home_dir(), ".cache") self._db_path = join(self.cache_dir, "db.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_install_packages(isolated_pio_home, tmpdir): packages = [ dict(id=1, name="name_1", version="shasum"), dict(id=1, name="name_1", version="2.0.0"), dict(id=1, name="name_1", version="2.1.0"), dict(id=1, name="name_1", version="1.2"), dict(id=1, name="name_1", version="1.0.0"), dict(name="name_2", version="1.0.0"), dict(name="name_2", version="2.0.0", __src_url="git+https://github.com"), dict(name="name_2", version="3.0.0", __src_url="git+https://github2.com"), dict(name="name_2", version="4.0.0", __src_url="git+https://github2.com") ] pm = PackageManager(join(util.get_home_dir(), "packages")) for package in packages: tmp_dir = tmpdir.mkdir("tmp-package") tmp_dir.join("package.json").write(json.dumps(package)) pm._install_from_url(package['name'], "file://%s" % str(tmp_dir)) tmp_dir.remove(rec=1) assert len(pm.get_installed()) == len(packages) - 1 pkg_dirnames = [ 'name_1_ID1', '[email protected]', '[email protected]', '[email protected]', 'name_1_ID1@shasum', 'name_2', 'name_2@src-177cbce1f0705580d17790fda1cc2ef5', 'name_2@src-f863b537ab00f4c7b5011fc44b120e1f' ] assert set([p.basename for p in isolated_pio_home.join( "packages").listdir()]) == set(pkg_dirnames)
def get_boards(self, id_=None): def _append_board(board_id, manifest_path): config = PlatformBoardConfig(manifest_path) if "platform" in config and config.get("platform") != self.name: return elif "platforms" in config and self.name not in config.get("platforms"): return config.manifest["platform"] = self.name self._BOARDS_CACHE[board_id] = config bdirs = [util.get_projectboards_dir(), join(util.get_home_dir(), "boards"), join(self.get_dir(), "boards")] if id_ is None: for boards_dir in bdirs: if not isdir(boards_dir): continue for item in sorted(os.listdir(boards_dir)): _id = item[:-5] if not item.endswith(".json") or _id in self._BOARDS_CACHE: continue _append_board(_id, join(boards_dir, item)) else: if id_ not in self._BOARDS_CACHE: for boards_dir in bdirs: if not isdir(boards_dir): continue manifest_path = join(boards_dir, "%s.json" % id_) if not isfile(manifest_path): continue _append_board(id_, manifest_path) if id_ not in self._BOARDS_CACHE: raise exception.UnknownBoard(id_) return self._BOARDS_CACHE[id_] if id_ else self._BOARDS_CACHE
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 __exit__(self, type_, value, traceback): if self._prev_state != self._state: try: with codecs.open(self.path, "w", encoding="utf8") as fp: json.dump(self._state, fp) except IOError: raise exception.HomeDirPermissionsError(util.get_home_dir()) self._unlock_state_file()
def __init__(self, path=None, lock=False): self.path = path self.lock = lock if not self.path: self.path = join(util.get_home_dir(), "appstate.json") self._state = {} self._prev_state = {} self._lockfile = None
def __init__(self, manifest_path): self._BOARDS_CACHE = {} self.manifest_path = manifest_path self._manifest = util.load_json(manifest_path) self.pm = PackageManager(join(util.get_home_dir(), "packages"), self._manifest.get("packageRepositories")) self.silent = False self.verbose = False
def test_complex(clirunner, validate_cliresult): items = [ "teensy", "https://github.com/platformio/platform-teensy/archive/develop.zip", "https://github.com/platformio/platform-teensy.git", "platformio/platform-teensy", ] for item in items: with clirunner.isolated_filesystem(): os.environ["PLATFORMIO_HOME_DIR"] = os.getcwd() try: result = clirunner.invoke(cli_platform.platform_install, [item]) validate_cliresult(result) assert all([ s in result.output for s in ("teensy", "Downloading", "Unpacking", "tool-scons") ]) # show platform information result = clirunner.invoke(cli_platform.platform_show, ["teensy"]) validate_cliresult(result) assert "teensy" in result.output # list platforms result = clirunner.invoke(cli_platform.platform_list, ["--json-output"]) validate_cliresult(result) list_result = json.loads(result.output) assert isinstance(list_result, list) assert len(list_result) == 1 assert list_result[0]["name"] == "teensy" assert list_result[0]["packages"] == ["tool-scons"] # try to install again result = clirunner.invoke(cli_platform.platform_install, ["teensy"]) validate_cliresult(result) assert "is already installed" in result.output # try to update result = clirunner.invoke(cli_platform.platform_update) validate_cliresult(result) assert "teensy" in result.output assert "Up-to-date" in result.output # try to uninstall result = clirunner.invoke(cli_platform.platform_uninstall, ["teensy"]) validate_cliresult(result) for folder in ("platforms", "packages"): assert len(os.listdir(join(util.get_home_dir(), folder))) == 0 finally: del os.environ["PLATFORMIO_HOME_DIR"]
def __init__(self, package_dir=None, repositories=None): if not repositories: repositories = [ "https://dl.bintray.com/platformio/dl-platforms/manifest.json", "{0}://dl.platformio.org/platforms/manifest.json".format( "https" if app.get_setting("enable_ssl") else "http" ), ] BasePkgManager.__init__(self, package_dir or join(util.get_home_dir(), "platforms"), repositories)
def test_board_ldscripts(platformio_setup, clirunner, validate_cliresult): result = clirunner.invoke( install_cli, ["ststm32", "--skip-default-package", "--with-package=ldscripts"]) validate_cliresult(result) ldscripts_path = join(util.get_home_dir(), "packages", "ldscripts") for _, opts in util.get_boards().iteritems(): if opts['build'].get("ldscript"): assert isfile(join(ldscripts_path, opts['build'].get("ldscript")))
def test_board_ldscripts(platformio_setup, clirunner, validate_cliresult): result = clirunner.invoke(cmd_platforms_install, ["ststm32", "--skip-default-package", "--with-package=ldscripts"]) validate_cliresult(result) ldscripts_path = join(util.get_home_dir(), "packages", "ldscripts") for _, opts in util.get_boards().iteritems(): if opts["build"].get("ldscript"): if "libopencm3" in opts["frameworks"]: continue assert isfile(join(ldscripts_path, opts["build"].get("ldscript")))
def __init__(self, package_dir=None, repositories=None): if not repositories: repositories = [ "{0}://dl.platformio.org/platforms/manifest.json".format( "http" if app.get_setting("disable_ssl") else "https") ] BasePkgManager.__init__(self, package_dir or join(util.get_home_dir(), "platforms"), repositories)
def __init__(self, cache_dir=None): self.cache_dir = None self._db_path = None self._lockfile = None if not get_setting("enable_cache"): return self.cache_dir = cache_dir or join(util.get_home_dir(), ".cache") self._db_path = join(self.cache_dir, "db.data")
def _upgrade_to_0_9_0(self, ctx): # pylint: disable=R0201 prev_platforms = [] # remove platform's folder (obsoleted package structure) for name in PlatformFactory.get_platforms().keys(): pdir = join(get_home_dir(), name) if not isdir(pdir): continue prev_platforms.append(name) rmtree(pdir) # remove unused files for fname in (".pioupgrade", "installed.json"): if isfile(join(get_home_dir(), fname)): remove(join(get_home_dir(), fname)) if prev_platforms: ctx.invoke(cmd_install, platforms=prev_platforms) return True
def __exit__(self, type_, value, traceback): if self._prev_state != self._state: try: with open(self.path, "w") as fp: if "dev" in __version__: json.dump(self._state, fp, indent=4) else: json.dump(self._state, fp) except IOError: raise exception.HomeDirPermissionsError(util.get_home_dir()) self._unlock_state_file()
def _get_platformio_packages(self): log.debug("Getting Scons Packages") ori_current_dir = os.getcwd() ori_click_confirm = click.confirm def click_confirm(message): print message return True click.confirm = click_confirm try: os.chdir(pm.PLATFORMIO_WORKSPACE_SKELETON) config = util.get_project_config() for section in config.sections(): env_options_dict = {x[0]: x[1] for x in config.items(section)} platform = PlatformFactory.newPlatform(env_options_dict["platform"]) log.info("getting packages for: {}".format(env_options_dict)) platform.configure_default_packages(env_options_dict, ["upload"]) platform._install_default_packages() os.chdir(ori_current_dir) log.info("all platformio packages are successfully installed") platformio_packages_path = os.path.abspath(util.get_home_dir()) def is_doc(file_path): is_doc_condition = os.sep + "doc" + os.sep not in file_path is_doc_condition = is_doc_condition and os.sep + "examples" + os.sep not in file_path is_doc_condition = is_doc_condition and os.sep + "tool-scons" + os.sep not in file_path is_doc_condition = is_doc_condition and os.sep + "README" not in file_path.upper() return not is_doc_condition # installerPlatformioPackagesPath = self._getPlatformIOPackagesPath() # if os.path.exists(installerPlatformioPackagesPath): # shutil.rmtree(installerPlatformioPackagesPath) # # os.makedirs(installerPlatformioPackagesPath) log.info("Cleaning platformio packages files") all_files = sorted(utils.find_files(platformio_packages_path, ["*", "**" + os.sep + "*"]), reverse=True) for i, f in enumerate(all_files): if is_doc(f): if os.path.isfile(f): os.remove(f) else: try: os.rmdir(f) except: shutil.rmtree(f) finally: os.chdir(ori_current_dir) click.confirm = ori_click_confirm
def test_board_ldscripts(platformio_setup, clirunner, validate_cliresult): result = clirunner.invoke( cmd_platforms_install, ["ststm32", "--skip-default-package", "--with-package=ldscripts"]) validate_cliresult(result) ldscripts_path = join(util.get_home_dir(), "packages", "ldscripts") for type_, opts in util.get_boards().iteritems(): if opts['build'].get("ldscript"): frameworks = opts['frameworks'] if (any(fw in frameworks for fw in ["libopencm3", "mbed"]) or type_ in ("rfduino", )): continue assert isfile(join(ldscripts_path, opts['build'].get("ldscript")))
def test_complex(clirunner, validate_cliresult): with clirunner.isolated_filesystem(): os.environ["PLATFORMIO_HOME_DIR"] = os.getcwd() try: result = clirunner.invoke( cli_platform.platform_install, ["teensy", "--with-package", "framework-arduinoteensy"]) validate_cliresult(result) assert all([ s in result.output for s in ("teensy", "Downloading", "Unpacking") ]) # show platform information result = clirunner.invoke(cli_platform.platform_show, ["teensy"]) validate_cliresult(result) assert "teensy" in result.output # list platforms result = clirunner.invoke(cli_platform.platform_list, ["--json-output"]) validate_cliresult(result) list_result = json.loads(result.output) assert isinstance(list_result, list) assert len(list_result) == 1 assert list_result[0]["name"] == "teensy" assert list_result[0]["packages"] == ["framework-arduinoteensy"] # try to install again result = clirunner.invoke(cli_platform.platform_install, ["teensy"]) validate_cliresult(result) assert "is already installed" in result.output # try to update for _ in range(2): result = clirunner.invoke(cli_platform.platform_update) validate_cliresult(result) assert "teensy" in result.output assert "Up-to-date" in result.output assert "Out-of-date" not in result.output # try to uninstall result = clirunner.invoke(cli_platform.platform_uninstall, ["teensy"]) validate_cliresult(result) for folder in ("platforms", "packages"): assert len(os.listdir(join(util.get_home_dir(), folder))) == 0 finally: del os.environ["PLATFORMIO_HOME_DIR"]
def __init__(self, manifest_path): self._BOARDS_CACHE = {} self.manifest_path = manifest_path self._manifest = util.load_json(manifest_path) self.pm = PackageManager( join(util.get_home_dir(), "packages"), self.package_repositories) self.silent = False self.verbose = False if self.engines and "platformio" in self.engines: if self.PIO_VERSION not in semantic_version.Spec( self.engines['platformio']): raise exception.IncompatiblePlatform(self.name, str(self.PIO_VERSION))
def test_board_ldscripts(platformio_setup, clirunner, validate_cliresult): result = clirunner.invoke( cmd_platforms_install, [ "ststm32", "--skip-default-package", "--with-package=ldscripts" ]) validate_cliresult(result) ldscripts_path = join(util.get_home_dir(), "packages", "ldscripts") for type_, opts in util.get_boards().iteritems(): if opts['build'].get("ldscript"): frameworks = opts['frameworks'] if (any(fw in frameworks for fw in ["libopencm3", "mbed"]) or type_ in ("rfduino", )): continue assert isfile(join(ldscripts_path, opts['build'].get("ldscript")))
def __init__(self, manifest_path): self._BOARDS_CACHE = {} self.manifest_path = manifest_path self._manifest = util.load_json(manifest_path) self.pm = PackageManager(join(util.get_home_dir(), "packages"), self._manifest.get("packageRepositories")) self.silent = False self.verbose = False if self.engines and "platformio" in self.engines: if self.PIO_VERSION not in semantic_version.Spec( self.engines['platformio']): raise exception.IncompatiblePlatform(self.name, str(self.PIO_VERSION))
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 _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 cleanup_packages(self, names): self.reset_cache() deppkgs = {} for manifest in PlatformManager().get_installed(): p = PlatformFactory.newPlatform(manifest["name"], manifest["version"]) for pkgname, pkgmanifest in p.get_installed_packages().items(): if pkgname not in deppkgs: deppkgs[pkgname] = set() deppkgs[pkgname].add(pkgmanifest["version"]) pm = PackageManager(join(util.get_home_dir(), "packages")) for manifest in pm.get_installed(): if manifest["name"] not in names: continue if manifest["name"] not in deppkgs or manifest["version"] not in deppkgs[manifest["name"]]: pm.uninstall(manifest["name"], manifest["version"], trigger_event=False) self.reset_cache() return True
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 cleanup_packages(self, names): self.cache_reset() deppkgs = {} for manifest in PlatformManager().get_installed(): p = PlatformFactory.newPlatform(manifest['__pkg_dir']) for pkgname, pkgmanifest in p.get_installed_packages().items(): if pkgname not in deppkgs: deppkgs[pkgname] = set() deppkgs[pkgname].add(pkgmanifest['version']) pm = PackageManager(join(util.get_home_dir(), "packages")) for manifest in pm.get_installed(): if manifest['name'] not in names: continue if (manifest['name'] not in deppkgs or manifest['version'] not in deppkgs[manifest['name']]): pm.uninstall(manifest['__pkg_dir'], trigger_event=False) self.cache_reset() return True
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 after_upgrade(ctx): if app.get_state_item("last_version", None) == __version__: return # promotion click.echo("\nIf you like %s, please:" % ( click.style("PlatformIO", fg="cyan") )) click.echo( "- %s us on Twitter to stay up-to-date " "on the latest project news > %s" % (click.style("follow", fg="cyan"), click.style("https://twitter.com/PlatformIO_Org", fg="cyan")) ) click.echo("- %s us a star on GitHub > %s" % ( click.style("give", fg="cyan"), click.style("https://github.com/ivankravets/platformio", fg="cyan") )) click.secho("Thanks a lot!\n", fg="green") if not isdir(get_home_dir()): return click.secho("Please wait while upgrading PlatformIO ...", fg="yellow") last_version = app.get_state_item("last_version", "0.0.0") u = Upgrader(last_version, __version__) if u.run(ctx): app.set_state_item("last_version", __version__) click.secho("PlatformIO has been successfully upgraded to %s!\n" % __version__, fg="green") telemetry.on_event(category="Auto", action="Upgrade", label="%s > %s" % (last_version, __version__)) else: raise UpgraderFailed() click.echo("")
def cleanup_packages(self, names): self.cache_reset() deppkgs = {} for manifest in PlatformManager().get_installed(): p = PlatformFactory.newPlatform(manifest['__pkg_dir']) for pkgname, pkgmanifest in p.get_installed_packages().items(): if pkgname not in deppkgs: deppkgs[pkgname] = set() deppkgs[pkgname].add(pkgmanifest['version']) pm = PackageManager(join(util.get_home_dir(), "packages")) for manifest in pm.get_installed(): if manifest['name'] not in names: continue if (manifest['name'] not in deppkgs or manifest['version'] not in deppkgs[manifest['name']]): try: pm.uninstall(manifest['__pkg_dir'], after_update=True) except exception.UnknownPackage: pass self.cache_reset() return True
def _upgrade_to_3_0_0(ctx): # convert custom board configuration boards_dir = join(util.get_home_dir(), "boards") if isdir(boards_dir): for item in os.listdir(boards_dir): if not item.endswith(".json"): continue data = util.load_json(join(boards_dir, item)) if set(["name", "url", "vendor"]) <= set(data.keys()): continue os.remove(join(boards_dir, item)) for key, value in data.items(): with open(join(boards_dir, "%s.json" % key), "w") as f: json.dump(value, f, sort_keys=True, indent=2) # re-install PlatformIO 2.0 development platforms installed_platforms = app.get_state_item("installed_platforms", []) if installed_platforms: if "espressif" in installed_platforms: installed_platforms[installed_platforms.index( "espressif")] = "espressif8266" ctx.invoke(cmd_platform_install, platforms=installed_platforms) return True
# upload options ("UPLOAD_PORT",), ("UPLOAD_PROTOCOL",), ("UPLOAD_SPEED",) ) DefaultEnvironment( tools=["default", "platformio"], toolpath=[join("$PIOBUILDER_DIR", "tools")], variables=commonvars, PIOBUILDER_DIR=join(get_source_dir(), "builder"), PROJECT_DIR=get_project_dir(), PIOENVS_DIR=get_pioenvs_dir(), PLATFORMIOHOME_DIR=get_home_dir(), PLATFORM_DIR=join("$PLATFORMIOHOME_DIR", "$PLATFORM"), PLATFORMFW_DIR=join("$PLATFORM_DIR", "frameworks", "$FRAMEWORK"), PLATFORMTOOLS_DIR=join("$PLATFORM_DIR", "tools"), BUILD_DIR=join("$PIOENVS_DIR", "$PIOENV"), LIBSOURCE_DIRS=[ join("$PROJECT_DIR", "lib"), get_lib_dir(), join("$PLATFORMFW_DIR", "libraries"), ] ) env = DefaultEnvironment() if not isdir(env['PLATFORMIOHOME_DIR']):
def __init__(self, package_dir=None): if not package_dir: package_dir = join(util.get_home_dir(), "lib") BasePkgManager.__init__(self, package_dir)
DefaultEnvironment( tools=[ "gcc", "g++", "as", "ar", "gnulink", "platformio", "pioupload", "pioar", "piomisc" ], toolpath=[join("$PIOBUILDER_DIR", "tools")], 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")
def test_pkg_name_parser(): items = [ ["PkgName", ("PkgName", None, None)], [("PkgName", "!=1.2.3,<2.0"), ("PkgName", "!=1.2.3,<2.0", None)], ["[email protected]", ("PkgName", "1.2.3", None)], [("[email protected]", "1.2.5"), ("[email protected]", "1.2.5", None)], ["id:13", ("id:13", None, None)], ["id:13@~1.2.3", ("id:13", "~1.2.3", None)], [ util.get_home_dir(), (".platformio", None, "file://" + util.get_home_dir()) ], [ "LocalName=" + util.get_home_dir(), ("LocalName", None, "file://" + util.get_home_dir()) ], [ "https://github.com/user/package.git", ("package", None, "git+https://github.com/user/package.git") ], [ "https://gitlab.com/user/package.git", ("package", None, "git+https://gitlab.com/user/package.git") ], [ "https://github.com/user/package/archive/branch.zip", ("branch", None, "https://github.com/user/package/archive/branch.zip") ], [ "https://github.com/user/package/archive/branch.tar.gz", ("branch", None, "https://github.com/user/package/archive/branch.tar.gz") ], [ "https://developer.mbed.org/users/user/code/package/", ("package", None, "hg+https://developer.mbed.org/users/user/code/package/") ], [ "https://github.com/user/package#v1.2.3", ("package", None, "git+https://github.com/user/package#v1.2.3") ], [ "https://github.com/user/package.git#branch", ("package", None, "git+https://github.com/user/package.git#branch") ], [ "PkgName=https://github.com/user/package.git#a13d344fg56", ("PkgName", None, "git+https://github.com/user/package.git#a13d344fg56") ], [ "PkgName=user/package", ("PkgName", None, "git+https://github.com/user/package") ], [ "PkgName=user/package#master", ("PkgName", None, "git+https://github.com/user/package#master") ], [ "git+https://github.com/user/package", ("package", None, "git+https://github.com/user/package") ], [ "hg+https://example.com/user/package", ("package", None, "hg+https://example.com/user/package") ], [ "[email protected]:user/package.git", ("package", None, "[email protected]:user/package.git") ], [ "[email protected]:user/package.git#v1.2.0", ("package", None, "[email protected]:user/package.git#v1.2.0") ], [ "git+ssh://[email protected]/user/package#1.2.0", ("package", None, "git+ssh://[email protected]/user/package#1.2.0") ] ] for params, result in items: if isinstance(params, tuple): assert BasePkgManager.parse_pkg_name(*params) == result else: assert BasePkgManager.parse_pkg_name(params) == result
def __init__(self): self._package_dir = join(util.get_home_dir(), "packages") if not isdir(self._package_dir): makedirs(self._package_dir) assert isdir(self._package_dir)
def __init__(self, package_dir=None): if not package_dir: package_dir = join(util.get_home_dir(), "lib") super(LibraryManager, self).__init__(package_dir)
def test_pkg_input_parser(): items = [ ["PkgName", ("PkgName", None, None)], [("PkgName", "!=1.2.3,<2.0"), ("PkgName", "!=1.2.3,<2.0", None)], ["[email protected]", ("PkgName", "1.2.3", None)], [("[email protected]", "1.2.5"), ("[email protected]", "1.2.5", None)], ["id=13", ("id=13", None, None)], ["id=13@~1.2.3", ("id=13", "~1.2.3", None)], [ util.get_home_dir(), (".platformio", None, "file://" + util.get_home_dir()) ], [ "LocalName=" + util.get_home_dir(), ("LocalName", None, "file://" + util.get_home_dir()) ], [ "LocalName=%s@>2.3.0" % util.get_home_dir(), ("LocalName", ">2.3.0", "file://" + util.get_home_dir()) ], [ "https://github.com/user/package.git", ("package", None, "git+https://github.com/user/package.git") ], [ "MyPackage=https://gitlab.com/user/package.git", ("MyPackage", None, "git+https://gitlab.com/user/package.git") ], [ "MyPackage=https://gitlab.com/user/[email protected],!=2", ("MyPackage", "3.2.1,!=2", "git+https://gitlab.com/user/package.git") ], [ "https://somedomain.com/path/LibraryName-1.2.3.zip", ("LibraryName-1.2.3", None, "https://somedomain.com/path/LibraryName-1.2.3.zip") ], [ "https://github.com/user/package/archive/branch.zip", ("branch", None, "https://github.com/user/package/archive/branch.zip") ], [ "https://github.com/user/package/archive/branch.zip@~1.2.3", ("branch", "~1.2.3", "https://github.com/user/package/archive/branch.zip") ], [ "https://github.com/user/package/archive/branch.tar.gz", ("branch.tar", None, "https://github.com/user/package/archive/branch.tar.gz") ], [ "https://github.com/user/package/archive/branch.tar.gz@!=5", ("branch.tar", "!=5", "https://github.com/user/package/archive/branch.tar.gz") ], [ "https://developer.mbed.org/users/user/code/package/", ("package", None, "hg+https://developer.mbed.org/users/user/code/package/") ], [ "https://os.mbed.com/users/user/code/package/", ("package", None, "hg+https://os.mbed.com/users/user/code/package/") ], [ "https://github.com/user/package#v1.2.3", ("package", None, "git+https://github.com/user/package#v1.2.3") ], [ "https://github.com/user/package.git#branch", ("package", None, "git+https://github.com/user/package.git#branch") ], [ "PkgName=https://github.com/user/package.git#a13d344fg56", ("PkgName", None, "git+https://github.com/user/package.git#a13d344fg56") ], [ "user/package", ("package", None, "git+https://github.com/user/package") ], [ "PkgName=user/package", ("PkgName", None, "git+https://github.com/user/package") ], [ "PkgName=user/package#master", ("PkgName", None, "git+https://github.com/user/package#master") ], [ "git+https://github.com/user/package", ("package", None, "git+https://github.com/user/package") ], [ "hg+https://example.com/user/package", ("package", None, "hg+https://example.com/user/package") ], [ "[email protected]:user/package.git", ("package", None, "[email protected]:user/package.git") ], [ "[email protected]:user/package.git#v1.2.0", ("package", None, "[email protected]:user/package.git#v1.2.0") ], [ "[email protected]:user/package.git#v1.2.0@~1.2.0", ("LocalName", "~1.2.0", "[email protected]:user/package.git#v1.2.0") ], [ "git+ssh://[email protected]/user/package#1.2.0", ("package", None, "git+ssh://[email protected]/user/package#1.2.0") ], [ "git+ssh://[email protected]:1234/package#1.2.0", ("package", None, "git+ssh://[email protected]:1234/package#1.2.0") ], [ "LocalName=git+ssh://[email protected]:1234" "/package#1.2.0@!=13", ("LocalName", "!=13", "git+ssh://[email protected]:1234/package#1.2.0") ] ] for params, result in items: if isinstance(params, tuple): assert PackageManager.parse_pkg_uri(*params) == result else: assert PackageManager.parse_pkg_uri(params) == result