mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-29 17:47:14 +02:00
Added new check_prune_system_threshold
setting
This commit is contained in:
@ -24,6 +24,7 @@ PlatformIO Core 5
|
||||
+ ``--core-packages`` option to remove unnecessary core packages
|
||||
+ ``--platform-packages`` option to remove unnecessary development platform packages (`issue #923 <https://github.com/platformio/platformio-core/issues/923>`_)
|
||||
|
||||
- Added new `check_prune_system_threshold <https://docs.platformio.org/page/core/userguide/cmd_settings.html#check-prune-system-threshold>`__ setting
|
||||
- Disabled automatic removal of unnecessary development platform packages (`issue #3708 <https://github.com/platformio/platformio-core/issues/3708>`_, `issue #3770 <https://github.com/platformio/platformio-core/issues/3770>`_)
|
||||
- Fixed an issue when unnecessary packages were removed in ``update --dry-run`` mode (`issue #3809 <https://github.com/platformio/platformio-core/issues/3809>`_)
|
||||
|
||||
|
2
docs
2
docs
Submodule docs updated: 89ee78e13f...ee815b1b42
@ -55,6 +55,10 @@ DEFAULT_SETTINGS = {
|
||||
"description": "Check for the platform updates interval (days)",
|
||||
"value": 7,
|
||||
},
|
||||
"check_prune_system_threshold": {
|
||||
"description": "Check for pruning unnecessary data threshold (megabytes)",
|
||||
"value": 1024,
|
||||
},
|
||||
"enable_cache": {
|
||||
"description": "Enable caching for HTTP API requests",
|
||||
"value": True,
|
||||
|
@ -24,12 +24,13 @@ from platformio.package.manager.platform import remove_unnecessary_platform_pack
|
||||
from platformio.project.helpers import get_project_cache_dir
|
||||
|
||||
|
||||
def prune_cached_data(force, dry_run):
|
||||
def prune_cached_data(force=False, dry_run=False, silent=False):
|
||||
reclaimed_space = 0
|
||||
click.secho("Prune cached data:", bold=True)
|
||||
click.echo(" - cached API requests")
|
||||
click.echo(" - cached package downloads")
|
||||
click.echo(" - temporary data")
|
||||
if not silent:
|
||||
click.secho("Prune cached data:", bold=True)
|
||||
click.echo(" - cached API requests")
|
||||
click.echo(" - cached package downloads")
|
||||
click.echo(" - temporary data")
|
||||
cache_dir = get_project_cache_dir()
|
||||
if os.path.isdir(cache_dir):
|
||||
reclaimed_space += fs.calculate_folder_size(cache_dir)
|
||||
@ -37,22 +38,26 @@ def prune_cached_data(force, dry_run):
|
||||
if not force:
|
||||
click.confirm("Do you want to continue?", abort=True)
|
||||
fs.rmtree(cache_dir)
|
||||
click.secho("Space on disk: %s" % fs.humanize_file_size(reclaimed_space))
|
||||
if not silent:
|
||||
click.secho("Space on disk: %s" % fs.humanize_file_size(reclaimed_space))
|
||||
return reclaimed_space
|
||||
|
||||
|
||||
def prune_core_packages(force, dry_run):
|
||||
click.secho("Prune unnecessary core packages:", bold=True)
|
||||
return _prune_packages(force, dry_run, remove_unnecessary_core_packages)
|
||||
def prune_core_packages(force=False, dry_run=False, silent=False):
|
||||
if not silent:
|
||||
click.secho("Prune unnecessary core packages:", bold=True)
|
||||
return _prune_packages(force, dry_run, silent, remove_unnecessary_core_packages)
|
||||
|
||||
|
||||
def prune_platform_packages(force, dry_run):
|
||||
click.secho("Prune unnecessary development platform packages:", bold=True)
|
||||
return _prune_packages(force, dry_run, remove_unnecessary_platform_packages)
|
||||
def prune_platform_packages(force=False, dry_run=False, silent=False):
|
||||
if not silent:
|
||||
click.secho("Prune unnecessary development platform packages:", bold=True)
|
||||
return _prune_packages(force, dry_run, silent, remove_unnecessary_platform_packages)
|
||||
|
||||
|
||||
def _prune_packages(force, dry_run, handler):
|
||||
click.echo("Calculating...")
|
||||
def _prune_packages(force, dry_run, silent, handler):
|
||||
if not silent:
|
||||
click.echo("Calculating...")
|
||||
items = [
|
||||
(
|
||||
pkg,
|
||||
@ -62,7 +67,7 @@ def _prune_packages(force, dry_run, handler):
|
||||
]
|
||||
items = sorted(items, key=itemgetter(1), reverse=True)
|
||||
reclaimed_space = sum([item[1] for item in items])
|
||||
if items:
|
||||
if items and not silent:
|
||||
click.echo(
|
||||
tabulate(
|
||||
[
|
||||
@ -80,5 +85,14 @@ def _prune_packages(force, dry_run, handler):
|
||||
if not force:
|
||||
click.confirm("Do you want to continue?", abort=True)
|
||||
handler(dry_run=False)
|
||||
click.secho("Space on disk: %s" % fs.humanize_file_size(reclaimed_space))
|
||||
if not silent:
|
||||
click.secho("Space on disk: %s" % fs.humanize_file_size(reclaimed_space))
|
||||
return reclaimed_space
|
||||
|
||||
|
||||
def calculate_unnecessary_system_data():
|
||||
return (
|
||||
prune_cached_data(force=True, dry_run=True, silent=True)
|
||||
+ prune_core_packages(force=True, dry_run=True, silent=True)
|
||||
+ prune_platform_packages(force=True, dry_run=True, silent=True)
|
||||
)
|
||||
|
@ -26,6 +26,7 @@ from platformio.commands import PlatformioCLI
|
||||
from platformio.commands.lib.command import CTX_META_STORAGE_DIRS_KEY
|
||||
from platformio.commands.lib.command import lib_update as cmd_lib_update
|
||||
from platformio.commands.platform import platform_update as cmd_platform_update
|
||||
from platformio.commands.system.prune import calculate_unnecessary_system_data
|
||||
from platformio.commands.upgrade import get_latest_version
|
||||
from platformio.compat import ensure_python3
|
||||
from platformio.package.manager.core import update_core_packages
|
||||
@ -73,6 +74,7 @@ def on_platformio_end(ctx, result): # pylint: disable=unused-argument
|
||||
check_platformio_upgrade()
|
||||
check_internal_updates(ctx, "platforms")
|
||||
check_internal_updates(ctx, "libraries")
|
||||
check_prune_system()
|
||||
except (
|
||||
http.HTTPClientError,
|
||||
http.InternetIsOffline,
|
||||
@ -347,3 +349,31 @@ def check_internal_updates(ctx, what): # pylint: disable=too-many-branches
|
||||
|
||||
click.echo("*" * terminal_width)
|
||||
click.echo("")
|
||||
|
||||
|
||||
def check_prune_system():
|
||||
last_check = app.get_state_item("last_check", {})
|
||||
interval = 30 * 3600 * 24 # 1 time per month
|
||||
if (time() - interval) < last_check.get("prune_system", 0):
|
||||
return
|
||||
|
||||
last_check["prune_system"] = int(time())
|
||||
app.set_state_item("last_check", last_check)
|
||||
threshold_mb = int(app.get_setting("check_prune_system_threshold") or 0)
|
||||
if threshold_mb <= 0:
|
||||
return
|
||||
|
||||
unnecessary_mb = calculate_unnecessary_system_data() / 1024
|
||||
if unnecessary_mb < threshold_mb:
|
||||
return
|
||||
|
||||
terminal_width, _ = click.get_terminal_size()
|
||||
click.echo()
|
||||
click.echo("*" * terminal_width)
|
||||
click.secho(
|
||||
"We found %s of unnecessary PlatformIO system data (temporary files, "
|
||||
"unnecessary packages, etc.).\nUse `pio system prune --dry-run` to list "
|
||||
"them or `pio system prune` to save disk space."
|
||||
% fs.humanize_file_size(unnecessary_mb),
|
||||
fg="yellow",
|
||||
)
|
||||
|
Reference in New Issue
Block a user