From 20c7ba5bd5b02b7ba913fc1fb6599589e0a42350 Mon Sep 17 00:00:00 2001 From: jonathan molinatto Date: Mon, 15 Sep 2025 06:25:40 -0700 Subject: [PATCH] update the example to work with the new apis --- examples/extensions/commands/clean/cmd_clean.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/examples/extensions/commands/clean/cmd_clean.py b/examples/extensions/commands/clean/cmd_clean.py index fb22e14a..8fcab3fd 100644 --- a/examples/extensions/commands/clean/cmd_clean.py +++ b/examples/extensions/commands/clean/cmd_clean.py @@ -1,3 +1,5 @@ +from conan.api.model.list import ListPattern +from conan.api.model.refs import RecipeReference from conan.api.conan_api import ConanAPI from conan.api.input import UserInput from conan.api.output import ConanOutput, Color @@ -28,13 +30,17 @@ def confirmation(message): output_remote = remote or "Local cache" # Getting all the recipes - recipes = conan_api.search.recipes("*/*", remote=remote) + recipes = conan_api.list.select(ListPattern("*/*"), remote=remote) if recipes and not confirmation("Do you want to remove all the recipes revisions and their packages ones, " "except the latest package revision from the latest recipe one?"): return - for recipe in recipes: - out.writeln(f"{str(recipe)}", fg=recipe_color) - all_rrevs = conan_api.list.recipe_revisions(recipe, remote=remote) + for k,v in recipes.recipes.items(): + # sort by timestamp + all_rrevs = sorted([(id,ts["timestamp"]) for (id,ts) in v["revisions"].items()], + key=lambda x: x[1], + reverse=True,) + all_rrevs = [x for x in map(lambda x: RecipeReference.loads(f"{k}#{x[0]}"), all_rrevs)] + out.writeln(f"{all_rrevs}", fg=recipe_color) latest_rrev = all_rrevs[0] if all_rrevs else None for rrev in all_rrevs: if rrev != latest_rrev: @@ -42,7 +48,7 @@ def confirmation(message): out.writeln(f"Removed recipe revision: {rrev.repr_notime()} " f"and all its package revisions [{output_remote}]", fg=removed_color) else: - packages = conan_api.list.packages_configurations(rrev, remote=remote) + packages = conan_api.list._packages_configurations(rrev, remote=remote) for package_ref in packages: all_prevs = conan_api.list.package_revisions(package_ref, remote=remote) latest_prev = all_prevs[0] if all_prevs else None @@ -50,3 +56,4 @@ def confirmation(message): if prev != latest_prev: conan_api.remove.package(prev, remote=remote) out.writeln(f"Removed package revision: {prev.repr_notime()} [{output_remote}]", fg=removed_color) +