From f78b5bd5bdd449699f9e4571a8e5a05f809a900d Mon Sep 17 00:00:00 2001 From: Ole Herman Schumacher Elgesem Date: Tue, 28 May 2024 17:26:33 +0200 Subject: [PATCH 1/7] cfbs.json: added_by now documents when a masterfiles module was added by "cfbs init" Signed-off-by: Ole Herman Schumacher Elgesem --- cfbs/commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cfbs/commands.py b/cfbs/commands.py index 66d4813..b3ef1ae 100644 --- a/cfbs/commands.py +++ b/cfbs/commands.py @@ -278,7 +278,7 @@ def init_command(index=None, masterfiles=None, non_interactive=False) -> int: log.debug("Current commit for masterfiles branch %s is %s" % (branch, commit)) to_add = "%s@%s" % (remote, commit) if to_add: - ret = add_command([to_add]) + ret = add_command([to_add], added_by="cfbs init") if ret != 0: return ret From 4e43d95e5f790eb632b398c02364a2e87553a80b Mon Sep 17 00:00:00 2001 From: Ole Herman Schumacher Elgesem Date: Tue, 28 May 2024 17:38:15 +0200 Subject: [PATCH 2/7] cfbs init: Specifically add the masterfiles module from the masterfiles repo URL Previously we were telling the add command to add a module from masterfiles repo URL at a specific commit, but not specifying which module to add, resulting in an extra prompt. Signed-off-by: Ole Herman Schumacher Elgesem --- cfbs/commands.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/cfbs/commands.py b/cfbs/commands.py index b3ef1ae..c05ab09 100644 --- a/cfbs/commands.py +++ b/cfbs/commands.py @@ -240,7 +240,7 @@ def init_command(index=None, masterfiles=None, non_interactive=False) -> int: CFBSConfig.reload() branch = None - to_add = "" + to_add = [] if masterfiles is None: if prompt_user( non_interactive, @@ -248,16 +248,18 @@ def init_command(index=None, masterfiles=None, non_interactive=False) -> int: choices=YES_NO_CHOICES, default="yes", ) in ("yes", "y"): - to_add = "masterfiles" + to_add = ["masterfiles"] else: - to_add = prompt_user( - non_interactive, - "Specify policy set to use instead (empty to skip)", - default="", - ) + to_add = [ + prompt_user( + non_interactive, + "Specify policy set to use instead (empty to skip)", + default="", + ) + ] elif re.match(r"[0-9]+(\.[0-9]+){2}(\-[0-9]+)?", masterfiles): log.debug("--masterfiles=%s appears to be a version number" % masterfiles) - to_add = "masterfiles@%s" % masterfiles + to_add = ["masterfiles@%s" % masterfiles] elif masterfiles != "no": """This appears to be a branch. Thus we'll add masterfiles normally and try to do the necessary modifications needed afterwards. I.e. @@ -266,7 +268,7 @@ def init_command(index=None, masterfiles=None, non_interactive=False) -> int: log.debug("--masterfiles=%s appears to be a branch" % masterfiles) branch = masterfiles - to_add = "masterfiles" + to_add = ["masterfiles"] if branch is not None: remote = "https://github.com/cfengine/masterfiles" @@ -276,9 +278,9 @@ def init_command(index=None, masterfiles=None, non_interactive=False) -> int: "Failed to find branch or tag %s at remote %s" % (branch, remote) ) log.debug("Current commit for masterfiles branch %s is %s" % (branch, commit)) - to_add = "%s@%s" % (remote, commit) + to_add = ["%s@%s" % (remote, commit), "masterfiles"] if to_add: - ret = add_command([to_add], added_by="cfbs init") + ret = add_command(to_add, added_by="cfbs init") if ret != 0: return ret From 42266a12c3fb9b9303ce78403b0009693783dfb6 Mon Sep 17 00:00:00 2001 From: Ole Herman Schumacher Elgesem Date: Tue, 28 May 2024 17:43:31 +0200 Subject: [PATCH 3/7] cfbs add: Now adds all modules from URL if user presses enter or passes --non-interactive Signed-off-by: Ole Herman Schumacher Elgesem --- cfbs/cfbs_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cfbs/cfbs_config.py b/cfbs/cfbs_config.py index aa7b00b..7c28c51 100644 --- a/cfbs/cfbs_config.py +++ b/cfbs/cfbs_config.py @@ -144,7 +144,7 @@ def _add_using_url( non_interactive=self.non_interactive, prompt="Do you want to add all %d of them?" % (len(modules)), choices=YES_NO_CHOICES, - default="no", + default="yes", ) if answer.lower() not in ("y", "yes"): return From 082ca3e2e8c909339751007a715be38fbae63473 Mon Sep 17 00:00:00 2001 From: Ole Herman Schumacher Elgesem Date: Tue, 28 May 2024 17:45:43 +0200 Subject: [PATCH 4/7] cfbs add: Now skips the prompt if a repo added by URL only has 1 module Ticket: CFE-3863 Signed-off-by: Ole Herman Schumacher Elgesem --- cfbs/cfbs_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cfbs/cfbs_config.py b/cfbs/cfbs_config.py index 7c28c51..8a9cfac 100644 --- a/cfbs/cfbs_config.py +++ b/cfbs/cfbs_config.py @@ -139,7 +139,7 @@ def _add_using_url( print(" - " + m["name"]) if not any(modules): user_error("no modules available, nothing to do") - if not self.non_interactive: + if len(modules) > 1 and not self.non_interactive: answer = prompt_user( non_interactive=self.non_interactive, prompt="Do you want to add all %d of them?" % (len(modules)), From ed10f391f3a751675da82bdcfdcbfb8fffd6f779 Mon Sep 17 00:00:00 2001 From: Ole Herman Schumacher Elgesem Date: Tue, 28 May 2024 17:56:52 +0200 Subject: [PATCH 5/7] cfbs add: Added information about dependencies when adding modules by URL Signed-off-by: Ole Herman Schumacher Elgesem --- cfbs/cfbs_config.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cfbs/cfbs_config.py b/cfbs/cfbs_config.py index 8a9cfac..5c9714d 100644 --- a/cfbs/cfbs_config.py +++ b/cfbs/cfbs_config.py @@ -136,7 +136,9 @@ def _add_using_url( modules = list(provides.values()) print("Found %d modules in '%s':" % (len(modules), url)) for m in modules: - print(" - " + m["name"]) + deps = m.get("dependencies", []) + deps = "" if not deps else " (Depends on: " + ", ".join(deps) + ")" + print(" - " + m["name"] + deps) if not any(modules): user_error("no modules available, nothing to do") if len(modules) > 1 and not self.non_interactive: From 726a1b5c4840e906fc76f567bc49f3d9ec3f0bb5 Mon Sep 17 00:00:00 2001 From: Ole Herman Schumacher Elgesem Date: Tue, 28 May 2024 17:58:33 +0200 Subject: [PATCH 6/7] cfbs add: Fixed issue printing empty list of modules before erroring when adding by URL Signed-off-by: Ole Herman Schumacher Elgesem --- cfbs/cfbs_config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cfbs/cfbs_config.py b/cfbs/cfbs_config.py index 5c9714d..b315025 100644 --- a/cfbs/cfbs_config.py +++ b/cfbs/cfbs_config.py @@ -134,13 +134,13 @@ def _add_using_url( # URL specified in to_add, but no specific modules => let's add all (with a prompt) if len(to_add) == 0: modules = list(provides.values()) + if not any(modules): + user_error("no modules available, nothing to do") print("Found %d modules in '%s':" % (len(modules), url)) for m in modules: deps = m.get("dependencies", []) deps = "" if not deps else " (Depends on: " + ", ".join(deps) + ")" print(" - " + m["name"] + deps) - if not any(modules): - user_error("no modules available, nothing to do") if len(modules) > 1 and not self.non_interactive: answer = prompt_user( non_interactive=self.non_interactive, From 6f7c7b23e2737946c8d9256a4499f098a3f952cc Mon Sep 17 00:00:00 2001 From: Ole Herman Schumacher Elgesem Date: Tue, 28 May 2024 18:07:45 +0200 Subject: [PATCH 7/7] cfbs add: Now prompts to add individual modules after user says no to add all from URL Ticket: CFE-4015 Signed-off-by: Ole Herman Schumacher Elgesem --- cfbs/cfbs_config.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/cfbs/cfbs_config.py b/cfbs/cfbs_config.py index b315025..88e7187 100644 --- a/cfbs/cfbs_config.py +++ b/cfbs/cfbs_config.py @@ -131,6 +131,7 @@ def _add_using_url( remote_config = CFBSJson(path=config_path, url=url, url_commit=url_commit) provides = remote_config.get_provides() + add_all = True # URL specified in to_add, but no specific modules => let's add all (with a prompt) if len(to_add) == 0: modules = list(provides.values()) @@ -149,14 +150,24 @@ def _add_using_url( default="yes", ) if answer.lower() not in ("y", "yes"): - return + add_all = False else: missing = [k for k in to_add if k not in provides] if missing: user_error("Missing modules: " + ", ".join(missing)) modules = [provides[k] for k in to_add] - for module in modules: + for i, module in enumerate(modules, start=1): + if not add_all: + answer = prompt_user( + non_interactive=self.non_interactive, + prompt="(%d/%d) Do you want to add '%s'?" + % (i, len(modules), module["name"]), + choices=YES_NO_CHOICES, + default="yes", + ) + if answer.lower() not in ("y", "yes"): + continue self.add_with_dependencies(module, remote_config) @staticmethod