diff --git a/HISTORY.rst b/HISTORY.rst index 17a8786b..538649fa 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -30,8 +30,8 @@ PlatformIO Core 4 - Built-in fine-grained access control (role based, teams, organizations) - Command Line Interface: - * `platformio package publish `__ – publish a personal or organization package - * `platformio package unpublish `__ – remove a pushed package from the registry + * `pio package publish `__ – publish a personal or organization package + * `pio package unpublish `__ – remove a pushed package from the registry * Grant package access to the team members or maintainers * New **Package Management System** @@ -46,7 +46,7 @@ PlatformIO Core 4 - Command launcher with own arguments - Launch command with custom options declared in `"platformio.ini" `__ - Python callback as a target (use the power of Python interpreter and PlatformIO Build API) - - List available project targets (including dev-platform specific and custom targets) with a new `platformio run --list-targets `__ command (`issue #3544 `_) + - List available project targets (including dev-platform specific and custom targets) with a new `pio run --list-targets `__ command (`issue #3544 `_) * **PlatformIO Build System** @@ -58,12 +58,13 @@ PlatformIO Core 4 * **Miscellaneous** - - Display system-wide information using a new `platformio system info `__ command (`issue #3521 `_) - - Dump data intended for IDE extensions/plugins using a new `platformio project idedata `__ command - - Added a new ``-e, --environment`` option to `platformio project init `__ command that helps to update a PlatformIO project using existing environment - - 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. - - Do not generate ".travis.yml" for a new project, let the user have a choice + - Display system-wide information using a new `pio system info `__ command (`issue #3521 `_) + - Remove unused data using a new `pio system prune `__ command (`issue #3522 `_) + - Dump data intended for IDE extensions/plugins using a new `pio project idedata `__ command + - Added a new ``-e, --environment`` option to `pio project init `__ command that helps to update a PlatformIO project using existing environment + - Added support for "globstar/`**`" (recursive) pattern for the different commands and configuration options (`pio ci `__, `src_filter `__, `check_patterns `__, `library.json > srcFilter `__). Python 3.5+ is required. - Updated PIO Unit Testing support for Mbed framework. Added compatibility with Mbed OS 6 + - Do not generate ".travis.yml" for a new project, let the user have a choice - Do not escape compiler arguments in VSCode template on Windows - Fixed an issue with PIO Unit Testing when running multiple environments (`issue #3523 `_) diff --git a/docs b/docs index d01bbede..be04ee45 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit d01bbede6ca90420ed24736be4963a48228eff42 +Subproject commit be04ee45c8d037c8eecbbe9a178926593fd620a0 diff --git a/platformio/commands/system/command.py b/platformio/commands/system/command.py index 2fee5471..cb311205 100644 --- a/platformio/commands/system/command.py +++ b/platformio/commands/system/command.py @@ -13,6 +13,7 @@ # limitations under the License. import json +import os import platform import subprocess import sys @@ -20,7 +21,7 @@ import sys import click from tabulate import tabulate -from platformio import __version__, compat, proc, util +from platformio import __version__, compat, fs, proc, util from platformio.commands.system.completion import ( get_completion_install_path, install_completion_code, @@ -30,6 +31,7 @@ from platformio.package.manager.library import LibraryPackageManager from platformio.package.manager.platform import PlatformPackageManager from platformio.package.manager.tool import ToolPackageManager from platformio.project.config import ProjectConfig +from platformio.project.helpers import get_project_cache_dir @click.group("system", short_help="Miscellaneous system commands") @@ -95,6 +97,27 @@ def system_info(json_output): ) +@cli.command("prune", short_help="Remove unused data") +@click.option("--force", "-f", is_flag=True, help="Do not prompt for confirmation") +def system_prune(force): + click.secho("WARNING! This will remove:", fg="yellow") + click.echo(" - cached API requests") + click.echo(" - cached package downloads") + click.echo(" - temporary data") + if not force: + click.confirm("Do you want to continue?", abort=True) + + reclaimed_total = 0 + cache_dir = get_project_cache_dir() + if os.path.isdir(cache_dir): + reclaimed_total += fs.calculate_folder_size(cache_dir) + fs.rmtree(cache_dir) + + click.secho( + "Total reclaimed space: %s" % fs.humanize_file_size(reclaimed_total), fg="green" + ) + + @cli.group("completion", short_help="Shell completion support") def completion(): # pylint: disable=import-error,import-outside-toplevel diff --git a/platformio/fs.py b/platformio/fs.py index 75bf959c..da2101c5 100644 --- a/platformio/fs.py +++ b/platformio/fs.py @@ -85,6 +85,17 @@ def calculate_file_hashsum(algorithm, path): return h.hexdigest() +def calculate_folder_size(path): + assert os.path.isdir(path) + result = 0 + for root, __, files in os.walk(path): + for f in files: + file_path = os.path.join(root, f) + if not os.path.islink(file_path): + result += os.path.getsize(file_path) + return result + + def ensure_udev_rules(): from platformio.util import get_systype # pylint: disable=import-outside-toplevel