Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config clean command sketch #17514

Open
wants to merge 23 commits into
base: develop2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions conan/api/subapi/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,8 @@ def appending_recursive_dict_update(d, u):
appending_recursive_dict_update(settings, settings_user)

return Settings(settings)

def clean(self):
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
from conans.client.migrations import ClientMigrator
migrator = ClientMigrator(self.conan_api.cache_folder, conan_version)
migrator.clean()
14 changes: 14 additions & 0 deletions conan/cli/commands/config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from conan.api.input import UserInput
from conan.api.model import Remote
from conan.api.output import cli_out_write
from conan.cli.command import conan_command, conan_subcommand, OnceArgument
Expand Down Expand Up @@ -132,3 +133,16 @@ def config_show(conan_api, parser, subparser, *args):
args = parser.parse_args(*args)

return conan_api.config.show(args.pattern)


@conan_subcommand()
def config_clean(conan_api, parser, subparser, *args):
"""
Clean the configuration files in the Conan home folder. (Keeping installed packages)
"""
subparser.add_argument("-c", "--confirm", action='store_true',
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
help="Do not request confirmation")
args = parser.parse_args(*args)
ui = UserInput(conan_api.config.get("core:non_interactive"))
if args.confirm or ui.request_boolean("Clear all configuration files?"):
conan_api.config.clean()
12 changes: 11 additions & 1 deletion conans/client/migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from conan.internal.default_settings import migrate_settings_file
from conans.migrations import Migrator
from conans.util.dates import timestamp_now
from conans.util.files import load, save
from conans.util.files import load, save, rmdir

CONAN_GENERATED_COMMENT = "This file was generated by Conan"

Expand Down Expand Up @@ -61,6 +61,16 @@ def _apply_migrations(self, old_version):
if old_version is None or old_version < "2.4":
_migrate_default_compatibility(self.cache_folder)

def clean(self):
# TODO: Check what we're deleting
contents = os.listdir(self.cache_folder)
for contents in contents:
# keep packages
if contents not in ("p", "version.txt"):
rmdir(os.path.join(self.cache_folder, contents))
# CHECK: This also generates a remotes.json that is not there after a conan profile show?
self._apply_migrations(None)


def _migrate_default_compatibility(cache_folder):
# just the back migration
Expand Down
Loading