From 67841ccfc01831babef7457406e1bba5b1e57b8f Mon Sep 17 00:00:00 2001 From: Justin Ross Date: Sun, 25 Feb 2024 06:56:23 -0500 Subject: [PATCH] Warn people not to edit the generated README.md. Improve the placeholder handling. --- example/README.md | 10 ++-------- python/skewer/main.py | 46 +++++++++++++++++++++---------------------- 2 files changed, 24 insertions(+), 32 deletions(-) diff --git a/example/README.md b/example/README.md index 4fc95f2..5aba426 100644 --- a/example/README.md +++ b/example/README.md @@ -1,3 +1,5 @@ + + # Skupper Hello World [![main](https://github.com/skupperproject/skewer/actions/workflows/main.yaml/badge.svg)](https://github.com/skupperproject/skewer/actions/workflows/main.yaml) @@ -32,12 +34,10 @@ across cloud providers, data centers, and edge sites. An overview - ## Prerequisites Some prerequisites - ## Step 1: Install the Skupper command-line tool This example uses the Skupper command-line tool to deploy Skupper. @@ -249,7 +249,6 @@ _**West:**_ ~~~ shell if [ -n "${SKEWER_FAIL}" ]; then expr 1 / 0; fi - ~~~ ## Step 7: Expose the backend @@ -323,7 +322,6 @@ navigating to `http://:8080/` in your browser. To remove Skupper and the other resources from this exercise, use the following commands: - And more! _**West:**_ @@ -343,18 +341,14 @@ kubectl delete deployment/backend ## Summary - - More summary - ## Next steps Check out the other [examples][examples] on the Skupper website. More steps - ## About this example This example was produced using [Skewer][skewer], a library for diff --git a/python/skewer/main.py b/python/skewer/main.py index 4bb2390..df3e05e 100644 --- a/python/skewer/main.py +++ b/python/skewer/main.py @@ -312,6 +312,9 @@ def append_section(heading, text): out.append(text) out.append("") + out.append("") + out.append("") + out.append(f"# {model.title}") out.append("") @@ -427,23 +430,22 @@ def apply_standard_steps(model): del step.data["standard"] def apply_attribute(name, default=None): - value = standard_step_data.get(name, default) + standard_value = standard_step_data.get(name, default) + value = step.data.get(name, standard_value) + + if is_string(value): + if standard_value is not None: + value = value.replace("@default@", str(nvl(standard_value, "")).strip()) - if name in step.data: - if name in ("title", "preamble", "postamble"): - if value: - step.data[name] = step.data[name].replace("@default@", value) - else: - step.data[name] = step.data[name].replace("@default@", "") - else: - if value and name in ("title", "preamble", "postamble"): - for i, site in enumerate([x for _, x in model.sites]): - value = value.replace(f"@site{i}@", site.title) + for i, site in enumerate([x for _, x in model.sites]): + value = value.replace(f"@site{i}@", site.title) - if site.namespace: - value = value.replace(f"@namespace{i}@", site.namespace) + if site.namespace: + value = value.replace(f"@namespace{i}@", site.namespace) - step.data[name] = value + value = value.strip() + + step.data[name] = value apply_attribute("name") apply_attribute("title") @@ -521,13 +523,9 @@ def object_property(name, default=None): def get(obj): value = obj.data.get(name, default) - try: - if default is None: - value = value.replace("@default@", "") - else: - value = value.replace("@default@", default) - except AttributeError: - pass + if is_string(value): + value = value.replace("@default@", str(nvl(default, "")).strip()) + value = value.strip() return value @@ -550,10 +548,10 @@ class Model: subtitle = object_property("subtitle") workflow = object_property("workflow", "main.yaml") overview = object_property("overview") - prerequisites = object_property("prerequisites", standard_text["prerequisites"].strip()) + prerequisites = object_property("prerequisites", standard_text["prerequisites"]) summary = object_property("summary") - next_steps = object_property("next_steps", standard_text["next_steps"].strip()) - about_this_example = object_property("about_this_example", standard_text["about_this_example"].strip()) + next_steps = object_property("next_steps", standard_text["next_steps"]) + about_this_example = object_property("about_this_example", standard_text["about_this_example"]) def __init__(self, skewer_file, kubeconfigs=[]): self.skewer_file = skewer_file