Skip to content

Commit

Permalink
Making paasta playground not override existing confs
Browse files Browse the repository at this point in the history
  • Loading branch information
cuza committed Oct 23, 2023
1 parent 3cd613b commit 05474e8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions paasta_tools/contrib/create_paasta_playground.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def main():
src="./k8s_itests/deployments/paasta/fake_soa_config",
dst="soa_config_playground",
values=values_path,
overwrite=False,
)


Expand Down
14 changes: 8 additions & 6 deletions paasta_tools/contrib/render_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,25 @@ def render_file(src, dst, values):
new.write(replace(old.read(), values))


def render(src, dst, values={}, exclude={}):
def render(src, dst, values={}, exclude={}, overwrite=True):
if os.path.isfile(src):
render_file(src, dst, values)
if overwrite:
render_file(src, dst, values)
return
for f in os.scandir(src):
if f.name.startswith(".") or f.path in exclude:
continue
if os.path.isfile(f.path):
render_file(f.path, dst, values)
if overwrite:
render_file(f.path, dst, values)
else:
new_dst = replace(f"{dst}/{f.name}", values)
try:
os.makedirs(new_dst, exist_ok=True)
except OSError as e:
if e.errno != os.errno.EEXIST:
raise
render(f.path, new_dst, values, exclude)
render(f.path, new_dst, values, exclude, overwrite)


def parse_args():
Expand Down Expand Up @@ -82,7 +84,7 @@ def parse_args():
return args


def render_values(src: str, dst: str, values: str) -> None:
def render_values(src: str, dst: str, values: str, overwrite=True) -> None:
if values is not None:
values = os.path.abspath(values)
# Validate src and values. Dst needs to be a directory. src can be either a valid folder of directory. values need to be valid file if provided.
Expand All @@ -108,7 +110,7 @@ def render_values(src: str, dst: str, values: str) -> None:
),
v,
)
render(src, dst, config_dict, {values})
render(src, dst, config_dict, {values}, overwrite)


def main():
Expand Down

0 comments on commit 05474e8

Please sign in to comment.