| 
									
										
										
										
											2017-06-05 16:02:39 +03:00
										 |  |  | # Copyright (c) 2014-present PlatformIO <contact@platformio.org> | 
					
						
							| 
									
										
										
										
											2015-11-18 17:16:17 +02:00
										 |  |  | # | 
					
						
							|  |  |  | # Licensed under the Apache License, Version 2.0 (the "License"); | 
					
						
							|  |  |  | # you may not use this file except in compliance with the License. | 
					
						
							|  |  |  | # You may obtain a copy of the License at | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | #    http://www.apache.org/licenses/LICENSE-2.0 | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Unless required by applicable law or agreed to in writing, software | 
					
						
							|  |  |  | # distributed under the License is distributed on an "AS IS" BASIS, | 
					
						
							|  |  |  | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
					
						
							|  |  |  | # See the License for the specific language governing permissions and | 
					
						
							|  |  |  | # limitations under the License. | 
					
						
							| 
									
										
										
										
											2015-04-17 12:37:03 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-08 17:24:58 +02:00
										 |  |  | from os.path import dirname, isdir | 
					
						
							| 
									
										
										
										
											2015-04-17 12:37:03 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | import click | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-01 14:52:32 +02:00
										 |  |  | from platformio import app, exception, util | 
					
						
							| 
									
										
										
										
											2017-03-03 23:29:17 +02:00
										 |  |  | from platformio.commands.boards import print_boards | 
					
						
							| 
									
										
										
										
											2019-06-05 17:57:22 +03:00
										 |  |  | from platformio.compat import dump_json_to_unicode | 
					
						
							| 
									
										
										
										
											2016-05-26 19:43:36 +03:00
										 |  |  | from platformio.managers.platform import PlatformFactory, PlatformManager | 
					
						
							| 
									
										
										
										
											2015-04-17 12:37:03 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-26 19:43:36 +03:00
										 |  |  | @click.group(short_help="Platform Manager") | 
					
						
							| 
									
										
										
										
											2015-04-17 12:37:03 +01:00
										 |  |  | def cli(): | 
					
						
							|  |  |  |     pass | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-26 19:43:36 +03:00
										 |  |  | def _print_platforms(platforms): | 
					
						
							| 
									
										
										
										
											2015-04-17 12:37:03 +01:00
										 |  |  |     for platform in platforms: | 
					
						
							| 
									
										
										
										
											2019-09-23 23:13:48 +03:00
										 |  |  |         click.echo( | 
					
						
							|  |  |  |             "{name} ~ {title}".format( | 
					
						
							|  |  |  |                 name=click.style(platform["name"], fg="cyan"), title=platform["title"] | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         click.echo("=" * (3 + len(platform["name"] + platform["title"]))) | 
					
						
							|  |  |  |         click.echo(platform["description"]) | 
					
						
							| 
									
										
										
										
											2016-05-26 19:43:36 +03:00
										 |  |  |         click.echo() | 
					
						
							| 
									
										
										
										
											2017-02-26 17:53:41 +02:00
										 |  |  |         if "homepage" in platform: | 
					
						
							| 
									
										
										
										
											2019-09-23 23:13:48 +03:00
										 |  |  |             click.echo("Home: %s" % platform["homepage"]) | 
					
						
							|  |  |  |         if "frameworks" in platform and platform["frameworks"]: | 
					
						
							|  |  |  |             click.echo("Frameworks: %s" % ", ".join(platform["frameworks"])) | 
					
						
							| 
									
										
										
										
											2017-02-26 17:53:41 +02:00
										 |  |  |         if "packages" in platform: | 
					
						
							| 
									
										
										
										
											2019-09-23 23:13:48 +03:00
										 |  |  |             click.echo("Packages: %s" % ", ".join(platform["packages"])) | 
					
						
							| 
									
										
										
										
											2016-05-26 19:43:36 +03:00
										 |  |  |         if "version" in platform: | 
					
						
							| 
									
										
										
										
											2019-06-05 18:26:39 +03:00
										 |  |  |             if "__src_url" in platform: | 
					
						
							| 
									
										
										
										
											2019-09-23 23:13:48 +03:00
										 |  |  |                 click.echo( | 
					
						
							|  |  |  |                     "Version: #%s (%s)" % (platform["version"], platform["__src_url"]) | 
					
						
							|  |  |  |                 ) | 
					
						
							| 
									
										
										
										
											2019-06-05 18:26:39 +03:00
										 |  |  |             else: | 
					
						
							| 
									
										
										
										
											2019-09-23 23:13:48 +03:00
										 |  |  |                 click.echo("Version: " + platform["version"]) | 
					
						
							| 
									
										
										
										
											2016-05-26 19:43:36 +03:00
										 |  |  |         click.echo() | 
					
						
							| 
									
										
										
										
											2015-04-17 12:37:03 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-03 23:29:17 +02:00
										 |  |  | def _get_registry_platforms(): | 
					
						
							| 
									
										
										
										
											2017-09-09 20:57:25 +03:00
										 |  |  |     platforms = util.get_api_result("/platforms", cache_valid="7d") | 
					
						
							| 
									
										
										
										
											2017-03-03 23:29:17 +02:00
										 |  |  |     pm = PlatformManager() | 
					
						
							|  |  |  |     for platform in platforms or []: | 
					
						
							| 
									
										
										
										
											2019-09-23 23:13:48 +03:00
										 |  |  |         platform["versions"] = pm.get_all_repo_versions(platform["name"]) | 
					
						
							| 
									
										
										
										
											2017-03-03 23:29:17 +02:00
										 |  |  |     return platforms | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def _get_platform_data(*args, **kwargs): | 
					
						
							|  |  |  |     try: | 
					
						
							|  |  |  |         return _get_installed_platform_data(*args, **kwargs) | 
					
						
							|  |  |  |     except exception.UnknownPlatform: | 
					
						
							|  |  |  |         return _get_registry_platform_data(*args, **kwargs) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-23 23:13:48 +03:00
										 |  |  | def _get_installed_platform_data(platform, with_boards=True, expose_packages=True): | 
					
						
							| 
									
										
										
										
											2017-03-03 23:29:17 +02:00
										 |  |  |     p = PlatformFactory.newPlatform(platform) | 
					
						
							| 
									
										
										
										
											2019-09-23 23:13:48 +03:00
										 |  |  |     data = dict( | 
					
						
							|  |  |  |         name=p.name, | 
					
						
							|  |  |  |         title=p.title, | 
					
						
							|  |  |  |         description=p.description, | 
					
						
							|  |  |  |         version=p.version, | 
					
						
							|  |  |  |         homepage=p.homepage, | 
					
						
							|  |  |  |         repository=p.repository_url, | 
					
						
							|  |  |  |         url=p.vendor_url, | 
					
						
							|  |  |  |         docs=p.docs_url, | 
					
						
							|  |  |  |         license=p.license, | 
					
						
							|  |  |  |         forDesktop=not p.is_embedded(), | 
					
						
							|  |  |  |         frameworks=sorted(list(p.frameworks) if p.frameworks else []), | 
					
						
							|  |  |  |         packages=list(p.packages) if p.packages else [], | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-03-03 23:29:17 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # if dump to API | 
					
						
							|  |  |  |     # del data['version'] | 
					
						
							|  |  |  |     # return data | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-08 17:24:58 +02:00
										 |  |  |     # overwrite VCS version and add extra fields | 
					
						
							|  |  |  |     manifest = PlatformManager().load_manifest(dirname(p.manifest_path)) | 
					
						
							|  |  |  |     assert manifest | 
					
						
							|  |  |  |     for key in manifest: | 
					
						
							|  |  |  |         if key == "version" or key.startswith("__"): | 
					
						
							|  |  |  |             data[key] = manifest[key] | 
					
						
							| 
									
										
										
										
											2017-03-03 23:29:17 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if with_boards: | 
					
						
							| 
									
										
										
										
											2019-09-23 23:13:48 +03:00
										 |  |  |         data["boards"] = [c.get_brief_data() for c in p.get_boards().values()] | 
					
						
							| 
									
										
										
										
											2017-03-03 23:29:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-23 23:13:48 +03:00
										 |  |  |     if not data["packages"] or not expose_packages: | 
					
						
							| 
									
										
										
										
											2017-03-03 23:29:17 +02:00
										 |  |  |         return data | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-23 23:13:48 +03:00
										 |  |  |     data["packages"] = [] | 
					
						
							| 
									
										
										
										
											2017-03-03 23:29:17 +02:00
										 |  |  |     installed_pkgs = p.get_installed_packages() | 
					
						
							|  |  |  |     for name, opts in p.packages.items(): | 
					
						
							| 
									
										
										
										
											2019-09-23 23:13:48 +03:00
										 |  |  |         item = dict( | 
					
						
							|  |  |  |             name=name, | 
					
						
							|  |  |  |             type=p.get_package_type(name), | 
					
						
							|  |  |  |             requirements=opts.get("version"), | 
					
						
							|  |  |  |             optional=opts.get("optional") is True, | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2017-03-03 23:29:17 +02:00
										 |  |  |         if name in installed_pkgs: | 
					
						
							|  |  |  |             for key, value in installed_pkgs[name].items(): | 
					
						
							|  |  |  |                 if key not in ("url", "version", "description"): | 
					
						
							|  |  |  |                     continue | 
					
						
							|  |  |  |                 item[key] = value | 
					
						
							|  |  |  |                 if key == "version": | 
					
						
							| 
									
										
										
										
											2019-04-17 23:20:45 +03:00
										 |  |  |                     item["originalVersion"] = util.get_original_version(value) | 
					
						
							| 
									
										
										
										
											2019-09-23 23:13:48 +03:00
										 |  |  |         data["packages"].append(item) | 
					
						
							| 
									
										
										
										
											2017-03-03 23:29:17 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return data | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def _get_registry_platform_data(  # pylint: disable=unused-argument | 
					
						
							| 
									
										
										
										
											2019-09-23 23:13:48 +03:00
										 |  |  |     platform, with_boards=True, expose_packages=True | 
					
						
							|  |  |  | ): | 
					
						
							| 
									
										
										
										
											2017-03-03 23:29:17 +02:00
										 |  |  |     _data = None | 
					
						
							|  |  |  |     for p in _get_registry_platforms(): | 
					
						
							| 
									
										
										
										
											2019-09-23 23:13:48 +03:00
										 |  |  |         if p["name"] == platform: | 
					
						
							| 
									
										
										
										
											2017-03-03 23:29:17 +02:00
										 |  |  |             _data = p | 
					
						
							|  |  |  |             break | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if not _data: | 
					
						
							|  |  |  |         return None | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-23 23:13:48 +03:00
										 |  |  |     data = dict( | 
					
						
							|  |  |  |         name=_data["name"], | 
					
						
							|  |  |  |         title=_data["title"], | 
					
						
							|  |  |  |         description=_data["description"], | 
					
						
							|  |  |  |         homepage=_data["homepage"], | 
					
						
							|  |  |  |         repository=_data["repository"], | 
					
						
							|  |  |  |         url=_data["url"], | 
					
						
							|  |  |  |         license=_data["license"], | 
					
						
							|  |  |  |         forDesktop=_data["forDesktop"], | 
					
						
							|  |  |  |         frameworks=_data["frameworks"], | 
					
						
							|  |  |  |         packages=_data["packages"], | 
					
						
							|  |  |  |         versions=_data["versions"], | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-03-03 23:29:17 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if with_boards: | 
					
						
							| 
									
										
										
										
											2019-09-23 23:13:48 +03:00
										 |  |  |         data["boards"] = [ | 
					
						
							|  |  |  |             board | 
					
						
							|  |  |  |             for board in PlatformManager().get_registered_boards() | 
					
						
							|  |  |  |             if board["platform"] == _data["name"] | 
					
						
							| 
									
										
										
										
											2017-03-03 23:29:17 +02:00
										 |  |  |         ] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return data | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-23 14:37:14 +03:00
										 |  |  | @cli.command("search", short_help="Search for development platform") | 
					
						
							| 
									
										
										
										
											2016-05-26 19:43:36 +03:00
										 |  |  | @click.argument("query", required=False) | 
					
						
							| 
									
										
										
										
											2015-04-17 12:37:03 +01:00
										 |  |  | @click.option("--json-output", is_flag=True) | 
					
						
							| 
									
										
										
										
											2016-05-26 19:43:36 +03:00
										 |  |  | def platform_search(query, json_output): | 
					
						
							|  |  |  |     platforms = [] | 
					
						
							| 
									
										
										
										
											2017-03-03 23:29:17 +02:00
										 |  |  |     for platform in _get_registry_platforms(): | 
					
						
							| 
									
										
										
										
											2016-05-26 19:43:36 +03:00
										 |  |  |         if query == "all": | 
					
						
							|  |  |  |             query = "" | 
					
						
							| 
									
										
										
										
											2019-06-05 17:57:22 +03:00
										 |  |  |         search_data = dump_json_to_unicode(platform) | 
					
						
							| 
									
										
										
										
											2016-05-26 19:43:36 +03:00
										 |  |  |         if query and query.lower() not in search_data.lower(): | 
					
						
							|  |  |  |             continue | 
					
						
							| 
									
										
										
										
											2017-03-03 23:29:17 +02:00
										 |  |  |         platforms.append( | 
					
						
							| 
									
										
										
										
											2019-09-23 23:13:48 +03:00
										 |  |  |             _get_registry_platform_data( | 
					
						
							|  |  |  |                 platform["name"], with_boards=False, expose_packages=False | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2015-04-17 12:37:03 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if json_output: | 
					
						
							| 
									
										
										
										
											2019-06-05 17:57:22 +03:00
										 |  |  |         click.echo(dump_json_to_unicode(platforms)) | 
					
						
							| 
									
										
										
										
											2015-04-17 12:37:03 +01:00
										 |  |  |     else: | 
					
						
							| 
									
										
										
										
											2016-05-26 19:43:36 +03:00
										 |  |  |         _print_platforms(platforms) | 
					
						
							| 
									
										
										
										
											2015-04-17 12:37:03 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-26 17:53:41 +02:00
										 |  |  | @cli.command("frameworks", short_help="List supported frameworks, SDKs") | 
					
						
							|  |  |  | @click.argument("query", required=False) | 
					
						
							|  |  |  | @click.option("--json-output", is_flag=True) | 
					
						
							|  |  |  | def platform_frameworks(query, json_output): | 
					
						
							|  |  |  |     frameworks = [] | 
					
						
							| 
									
										
										
										
											2017-09-09 20:57:25 +03:00
										 |  |  |     for framework in util.get_api_result("/frameworks", cache_valid="7d"): | 
					
						
							| 
									
										
										
										
											2017-02-26 17:53:41 +02:00
										 |  |  |         if query == "all": | 
					
						
							|  |  |  |             query = "" | 
					
						
							| 
									
										
										
										
											2019-06-05 17:57:22 +03:00
										 |  |  |         search_data = dump_json_to_unicode(framework) | 
					
						
							| 
									
										
										
										
											2017-02-26 17:53:41 +02:00
										 |  |  |         if query and query.lower() not in search_data.lower(): | 
					
						
							|  |  |  |             continue | 
					
						
							| 
									
										
										
										
											2019-09-23 23:13:48 +03:00
										 |  |  |         framework["homepage"] = "https://platformio.org/frameworks/" + framework["name"] | 
					
						
							|  |  |  |         framework["platforms"] = [ | 
					
						
							|  |  |  |             platform["name"] | 
					
						
							|  |  |  |             for platform in _get_registry_platforms() | 
					
						
							|  |  |  |             if framework["name"] in platform["frameworks"] | 
					
						
							| 
									
										
										
										
											2017-03-03 23:29:17 +02:00
										 |  |  |         ] | 
					
						
							| 
									
										
										
										
											2017-02-26 17:53:41 +02:00
										 |  |  |         frameworks.append(framework) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-23 23:13:48 +03:00
										 |  |  |     frameworks = sorted(frameworks, key=lambda manifest: manifest["name"]) | 
					
						
							| 
									
										
										
										
											2017-02-26 17:53:41 +02:00
										 |  |  |     if json_output: | 
					
						
							| 
									
										
										
										
											2019-06-05 17:57:22 +03:00
										 |  |  |         click.echo(dump_json_to_unicode(frameworks)) | 
					
						
							| 
									
										
										
										
											2017-02-26 17:53:41 +02:00
										 |  |  |     else: | 
					
						
							|  |  |  |         _print_platforms(frameworks) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-03 23:29:17 +02:00
										 |  |  | @cli.command("list", short_help="List installed development platforms") | 
					
						
							|  |  |  | @click.option("--json-output", is_flag=True) | 
					
						
							|  |  |  | def platform_list(json_output): | 
					
						
							|  |  |  |     platforms = [] | 
					
						
							|  |  |  |     pm = PlatformManager() | 
					
						
							|  |  |  |     for manifest in pm.get_installed(): | 
					
						
							|  |  |  |         platforms.append( | 
					
						
							| 
									
										
										
										
											2019-09-23 23:13:48 +03:00
										 |  |  |             _get_installed_platform_data( | 
					
						
							|  |  |  |                 manifest["__pkg_dir"], with_boards=False, expose_packages=False | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2017-06-23 14:08:46 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-23 23:13:48 +03:00
										 |  |  |     platforms = sorted(platforms, key=lambda manifest: manifest["name"]) | 
					
						
							| 
									
										
										
										
											2017-03-03 23:29:17 +02:00
										 |  |  |     if json_output: | 
					
						
							| 
									
										
										
										
											2019-06-05 17:57:22 +03:00
										 |  |  |         click.echo(dump_json_to_unicode(platforms)) | 
					
						
							| 
									
										
										
										
											2017-03-03 23:29:17 +02:00
										 |  |  |     else: | 
					
						
							|  |  |  |         _print_platforms(platforms) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @cli.command("show", short_help="Show details about development platform") | 
					
						
							|  |  |  | @click.argument("platform") | 
					
						
							|  |  |  | @click.option("--json-output", is_flag=True) | 
					
						
							|  |  |  | def platform_show(platform, json_output):  # pylint: disable=too-many-branches | 
					
						
							|  |  |  |     data = _get_platform_data(platform) | 
					
						
							|  |  |  |     if not data: | 
					
						
							|  |  |  |         raise exception.UnknownPlatform(platform) | 
					
						
							|  |  |  |     if json_output: | 
					
						
							| 
									
										
										
										
											2019-06-05 17:57:22 +03:00
										 |  |  |         return click.echo(dump_json_to_unicode(data)) | 
					
						
							| 
									
										
										
										
											2017-03-03 23:29:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-23 23:13:48 +03:00
										 |  |  |     click.echo( | 
					
						
							|  |  |  |         "{name} ~ {title}".format( | 
					
						
							|  |  |  |             name=click.style(data["name"], fg="cyan"), title=data["title"] | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     click.echo("=" * (3 + len(data["name"] + data["title"]))) | 
					
						
							|  |  |  |     click.echo(data["description"]) | 
					
						
							| 
									
										
										
										
											2017-03-03 23:29:17 +02:00
										 |  |  |     click.echo() | 
					
						
							|  |  |  |     if "version" in data: | 
					
						
							| 
									
										
										
										
											2019-09-23 23:13:48 +03:00
										 |  |  |         click.echo("Version: %s" % data["version"]) | 
					
						
							|  |  |  |     if data["homepage"]: | 
					
						
							|  |  |  |         click.echo("Home: %s" % data["homepage"]) | 
					
						
							|  |  |  |     if data["repository"]: | 
					
						
							|  |  |  |         click.echo("Repository: %s" % data["repository"]) | 
					
						
							|  |  |  |     if data["url"]: | 
					
						
							|  |  |  |         click.echo("Vendor: %s" % data["url"]) | 
					
						
							|  |  |  |     if data["license"]: | 
					
						
							|  |  |  |         click.echo("License: %s" % data["license"]) | 
					
						
							|  |  |  |     if data["frameworks"]: | 
					
						
							|  |  |  |         click.echo("Frameworks: %s" % ", ".join(data["frameworks"])) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if not data["packages"]: | 
					
						
							| 
									
										
										
										
											2017-12-15 22:16:37 +02:00
										 |  |  |         return None | 
					
						
							| 
									
										
										
										
											2017-03-03 23:29:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-23 23:13:48 +03:00
										 |  |  |     if not isinstance(data["packages"][0], dict): | 
					
						
							|  |  |  |         click.echo("Packages: %s" % ", ".join(data["packages"])) | 
					
						
							| 
									
										
										
										
											2017-03-03 23:29:17 +02:00
										 |  |  |     else: | 
					
						
							|  |  |  |         click.echo() | 
					
						
							|  |  |  |         click.secho("Packages", bold=True) | 
					
						
							|  |  |  |         click.echo("--------") | 
					
						
							| 
									
										
										
										
											2019-09-23 23:13:48 +03:00
										 |  |  |         for item in data["packages"]: | 
					
						
							| 
									
										
										
										
											2017-03-03 23:29:17 +02:00
										 |  |  |             click.echo() | 
					
						
							| 
									
										
										
										
											2019-09-23 23:13:48 +03:00
										 |  |  |             click.echo("Package %s" % click.style(item["name"], fg="yellow")) | 
					
						
							|  |  |  |             click.echo("-" * (8 + len(item["name"]))) | 
					
						
							|  |  |  |             if item["type"]: | 
					
						
							|  |  |  |                 click.echo("Type: %s" % item["type"]) | 
					
						
							|  |  |  |             click.echo("Requirements: %s" % item["requirements"]) | 
					
						
							|  |  |  |             click.echo( | 
					
						
							|  |  |  |                 "Installed: %s" % ("Yes" if item.get("version") else "No (optional)") | 
					
						
							|  |  |  |             ) | 
					
						
							| 
									
										
										
										
											2017-03-03 23:29:17 +02:00
										 |  |  |             if "version" in item: | 
					
						
							| 
									
										
										
										
											2019-09-23 23:13:48 +03:00
										 |  |  |                 click.echo("Version: %s" % item["version"]) | 
					
						
							| 
									
										
										
										
											2017-03-03 23:29:17 +02:00
										 |  |  |             if "originalVersion" in item: | 
					
						
							| 
									
										
										
										
											2019-09-23 23:13:48 +03:00
										 |  |  |                 click.echo("Original version: %s" % item["originalVersion"]) | 
					
						
							| 
									
										
										
										
											2017-03-03 23:29:17 +02:00
										 |  |  |             if "description" in item: | 
					
						
							| 
									
										
										
										
											2019-09-23 23:13:48 +03:00
										 |  |  |                 click.echo("Description: %s" % item["description"]) | 
					
						
							| 
									
										
										
										
											2017-03-03 23:29:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-23 23:13:48 +03:00
										 |  |  |     if data["boards"]: | 
					
						
							| 
									
										
										
										
											2017-03-03 23:29:17 +02:00
										 |  |  |         click.echo() | 
					
						
							|  |  |  |         click.secho("Boards", bold=True) | 
					
						
							|  |  |  |         click.echo("------") | 
					
						
							| 
									
										
										
										
											2019-09-23 23:13:48 +03:00
										 |  |  |         print_boards(data["boards"]) | 
					
						
							| 
									
										
										
										
											2017-03-03 23:29:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-15 22:16:37 +02:00
										 |  |  |     return True | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-03 23:29:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-23 14:37:14 +03:00
										 |  |  | @cli.command("install", short_help="Install new development platform") | 
					
						
							| 
									
										
										
										
											2016-08-01 17:05:48 +03:00
										 |  |  | @click.argument("platforms", nargs=-1, required=True, metavar="[PLATFORM...]") | 
					
						
							| 
									
										
										
										
											2016-07-22 18:02:04 +03:00
										 |  |  | @click.option("--with-package", multiple=True) | 
					
						
							|  |  |  | @click.option("--without-package", multiple=True) | 
					
						
							| 
									
										
										
										
											2016-05-26 19:43:36 +03:00
										 |  |  | @click.option("--skip-default-package", is_flag=True) | 
					
						
							| 
									
										
										
										
											2017-12-19 00:51:35 +02:00
										 |  |  | @click.option( | 
					
						
							|  |  |  |     "-f", | 
					
						
							|  |  |  |     "--force", | 
					
						
							|  |  |  |     is_flag=True, | 
					
						
							| 
									
										
										
										
											2019-09-23 23:13:48 +03:00
										 |  |  |     help="Reinstall/redownload dev/platform and its packages if exist", | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | def platform_install( | 
					
						
							|  |  |  |     platforms, with_package, without_package, skip_default_package, force | 
					
						
							|  |  |  | ): | 
					
						
							| 
									
										
										
										
											2016-08-01 17:05:48 +03:00
										 |  |  |     pm = PlatformManager() | 
					
						
							| 
									
										
										
										
											2015-04-17 12:37:03 +01:00
										 |  |  |     for platform in platforms: | 
					
						
							| 
									
										
										
										
											2019-09-23 23:13:48 +03:00
										 |  |  |         if pm.install( | 
					
						
							|  |  |  |             name=platform, | 
					
						
							|  |  |  |             with_packages=with_package, | 
					
						
							|  |  |  |             without_packages=without_package, | 
					
						
							|  |  |  |             skip_default_package=skip_default_package, | 
					
						
							|  |  |  |             force=force, | 
					
						
							|  |  |  |         ): | 
					
						
							|  |  |  |             click.secho( | 
					
						
							|  |  |  |                 "The platform '%s' has been successfully installed!\n" | 
					
						
							|  |  |  |                 "The rest of packages will be installed automatically " | 
					
						
							|  |  |  |                 "depending on your build environment." % platform, | 
					
						
							|  |  |  |                 fg="green", | 
					
						
							|  |  |  |             ) | 
					
						
							| 
									
										
										
										
											2015-04-17 12:37:03 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-23 14:37:14 +03:00
										 |  |  | @cli.command("uninstall", short_help="Uninstall development platform") | 
					
						
							| 
									
										
										
										
											2016-08-01 17:05:48 +03:00
										 |  |  | @click.argument("platforms", nargs=-1, required=True, metavar="[PLATFORM...]") | 
					
						
							|  |  |  | def platform_uninstall(platforms): | 
					
						
							|  |  |  |     pm = PlatformManager() | 
					
						
							|  |  |  |     for platform in platforms: | 
					
						
							|  |  |  |         if pm.uninstall(platform): | 
					
						
							| 
									
										
										
										
											2019-09-23 23:13:48 +03:00
										 |  |  |             click.secho( | 
					
						
							| 
									
										
										
										
											2019-09-27 14:13:53 +03:00
										 |  |  |                 "The platform '%s' has been successfully uninstalled!" % platform, | 
					
						
							| 
									
										
										
										
											2019-09-23 23:13:48 +03:00
										 |  |  |                 fg="green", | 
					
						
							|  |  |  |             ) | 
					
						
							| 
									
										
										
										
											2016-08-01 17:05:48 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-23 14:37:14 +03:00
										 |  |  | @cli.command("update", short_help="Update installed development platforms") | 
					
						
							| 
									
										
										
										
											2016-08-01 17:05:48 +03:00
										 |  |  | @click.argument("platforms", nargs=-1, required=False, metavar="[PLATFORM...]") | 
					
						
							| 
									
										
										
										
											2019-09-23 23:13:48 +03:00
										 |  |  | @click.option( | 
					
						
							|  |  |  |     "-p", "--only-packages", is_flag=True, help="Update only the platform packages" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | @click.option( | 
					
						
							|  |  |  |     "-c", | 
					
						
							|  |  |  |     "--only-check", | 
					
						
							|  |  |  |     is_flag=True, | 
					
						
							|  |  |  |     help="DEPRECATED. Please use `--dry-run` instead", | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | @click.option( | 
					
						
							|  |  |  |     "--dry-run", is_flag=True, help="Do not update, only check for the new versions" | 
					
						
							|  |  |  | ) | 
					
						
							| 
									
										
										
										
											2017-01-30 01:04:06 +02:00
										 |  |  | @click.option("--json-output", is_flag=True) | 
					
						
							| 
									
										
										
										
											2019-05-16 21:03:15 +03:00
										 |  |  | def platform_update(  # pylint: disable=too-many-locals | 
					
						
							| 
									
										
										
										
											2019-09-23 23:13:48 +03:00
										 |  |  |     platforms, only_packages, only_check, dry_run, json_output | 
					
						
							|  |  |  | ): | 
					
						
							| 
									
										
										
										
											2016-08-01 17:05:48 +03:00
										 |  |  |     pm = PlatformManager() | 
					
						
							| 
									
										
										
										
											2017-03-08 19:52:11 +02:00
										 |  |  |     pkg_dir_to_name = {} | 
					
						
							| 
									
										
										
										
											2016-08-01 17:05:48 +03:00
										 |  |  |     if not platforms: | 
					
						
							| 
									
										
										
										
											2017-01-30 01:04:06 +02:00
										 |  |  |         platforms = [] | 
					
						
							| 
									
										
										
										
											2017-03-08 19:52:11 +02:00
										 |  |  |         for manifest in pm.get_installed(): | 
					
						
							| 
									
										
										
										
											2019-09-23 23:13:48 +03:00
										 |  |  |             platforms.append(manifest["__pkg_dir"]) | 
					
						
							|  |  |  |             pkg_dir_to_name[manifest["__pkg_dir"]] = manifest.get( | 
					
						
							|  |  |  |                 "title", manifest["name"] | 
					
						
							|  |  |  |             ) | 
					
						
							| 
									
										
										
										
											2017-01-30 01:04:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-16 20:02:45 +03:00
										 |  |  |     only_check = dry_run or only_check | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-30 01:04:06 +02:00
										 |  |  |     if only_check and json_output: | 
					
						
							|  |  |  |         result = [] | 
					
						
							|  |  |  |         for platform in platforms: | 
					
						
							| 
									
										
										
										
											2017-03-08 17:24:58 +02:00
										 |  |  |             pkg_dir = platform if isdir(platform) else None | 
					
						
							|  |  |  |             requirements = None | 
					
						
							|  |  |  |             url = None | 
					
						
							|  |  |  |             if not pkg_dir: | 
					
						
							| 
									
										
										
										
											2017-11-25 00:31:16 +02:00
										 |  |  |                 name, requirements, url = pm.parse_pkg_uri(platform) | 
					
						
							| 
									
										
										
										
											2017-03-08 17:24:58 +02:00
										 |  |  |                 pkg_dir = pm.get_package_dir(name, requirements, url) | 
					
						
							|  |  |  |             if not pkg_dir: | 
					
						
							|  |  |  |                 continue | 
					
						
							|  |  |  |             latest = pm.outdated(pkg_dir, requirements) | 
					
						
							| 
									
										
										
										
											2019-09-23 23:13:48 +03:00
										 |  |  |             if ( | 
					
						
							|  |  |  |                 not latest | 
					
						
							|  |  |  |                 and not PlatformFactory.newPlatform(pkg_dir).are_outdated_packages() | 
					
						
							|  |  |  |             ): | 
					
						
							| 
									
										
										
										
											2017-01-30 01:04:06 +02:00
										 |  |  |                 continue | 
					
						
							| 
									
										
										
										
											2019-09-23 23:13:48 +03:00
										 |  |  |             data = _get_installed_platform_data( | 
					
						
							|  |  |  |                 pkg_dir, with_boards=False, expose_packages=False | 
					
						
							|  |  |  |             ) | 
					
						
							| 
									
										
										
										
											2017-03-08 19:52:11 +02:00
										 |  |  |             if latest: | 
					
						
							| 
									
										
										
										
											2019-09-23 23:13:48 +03:00
										 |  |  |                 data["versionLatest"] = latest | 
					
						
							| 
									
										
										
										
											2017-03-03 23:29:17 +02:00
										 |  |  |             result.append(data) | 
					
						
							| 
									
										
										
										
											2019-06-05 17:57:22 +03:00
										 |  |  |         return click.echo(dump_json_to_unicode(result)) | 
					
						
							| 
									
										
										
										
											2018-12-26 20:54:29 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # cleanup cached board and platform lists | 
					
						
							|  |  |  |     app.clean_cache() | 
					
						
							|  |  |  |     for platform in platforms: | 
					
						
							| 
									
										
										
										
											2019-05-30 23:42:15 +03:00
										 |  |  |         click.echo( | 
					
						
							| 
									
										
										
										
											2019-09-23 23:13:48 +03:00
										 |  |  |             "Platform %s" | 
					
						
							|  |  |  |             % click.style(pkg_dir_to_name.get(platform, platform), fg="cyan") | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2018-12-26 20:54:29 +02:00
										 |  |  |         click.echo("--------") | 
					
						
							|  |  |  |         pm.update(platform, only_packages=only_packages, only_check=only_check) | 
					
						
							|  |  |  |         click.echo() | 
					
						
							| 
									
										
										
										
											2017-12-15 22:16:37 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return True |