diff --git a/HISTORY.rst b/HISTORY.rst index 2e9af05c..1e07cb28 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -23,6 +23,7 @@ PlatformIO Core 4 - Python callback as a target (use the power of Python interpreter and PlatformIO Build API) +* Display system-wide information using `platformio system info `__ command (`issue #3521 `_) * List available project targets (including dev-platform specific and custom targets) with a new `platformio run --list-targets `__ command (`issue #3544 `_) * Added support for "globstar/`**`" (recursive) pattern for the different commands and configuration options (`platformio ci `__, `src_filter `__, `check_patterns `__, `library.json > srcFilter `__). Python 3.5+ is required. * Added a new ``-e, --environment`` option to `platformio project init `__ command that helps to update a PlatformIO project using existing environment diff --git a/docs b/docs index 478d089d..f33f42cc 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 478d089d27feb4588d0aeb55a4edd33317fe9af4 +Subproject commit f33f42cc9c5ec30267dc8c0c845aeda63adda598 diff --git a/platformio/commands/system/command.py b/platformio/commands/system/command.py index 48336bfd..fed66c40 100644 --- a/platformio/commands/system/command.py +++ b/platformio/commands/system/command.py @@ -12,17 +12,24 @@ # See the License for the specific language governing permissions and # limitations under the License. - +import json +import platform import subprocess +import sys import click +from tabulate import tabulate -from platformio import proc +from platformio import __version__, proc, util from platformio.commands.system.completion import ( get_completion_install_path, install_completion_code, uninstall_completion_code, ) +from platformio.managers.lib import LibraryManager +from platformio.managers.package import PackageManager +from platformio.managers.platform import PlatformManager +from platformio.project.config import ProjectConfig @click.group("system", short_help="Miscellaneous system commands") @@ -30,6 +37,44 @@ def cli(): pass +@cli.command("info", short_help="Display system-wide information") +@click.option("--json-output", is_flag=True) +def system_info(json_output): + project_config = ProjectConfig() + data = {} + data["core_version"] = {"title": "PlatformIO Core", "value": __version__} + data["python_version"] = { + "title": "Python", + "value": "{0}.{1}.{2}-{3}.{4}".format(*list(sys.version_info)), + } + data["system"] = {"title": "System Type", "value": util.get_systype()} + data["platform"] = {"title": "Platform", "value": platform.platform(terse=True)} + data["core_dir"] = { + "title": "PlatformIO Core Directory", + "value": project_config.get_optional_dir("core"), + } + data["global_lib_nums"] = { + "title": "Global Libraries", + "value": len(LibraryManager().get_installed()), + } + data["dev_platform_nums"] = { + "title": "Development Platforms", + "value": len(PlatformManager().get_installed()), + } + data["package_tool_nums"] = { + "title": "Package Tools", + "value": len( + PackageManager(project_config.get_optional_dir("packages")).get_installed() + ), + } + + click.echo( + json.dumps(data) + if json_output + else tabulate([(item["title"], item["value"]) for item in data.values()]) + ) + + @cli.group("completion", short_help="Shell completion support") def completion(): # pylint: disable=import-error,import-outside-toplevel