forked from moritz/alakazam
add comment function
This commit is contained in:
parent
2ef5a70c8b
commit
46f78a8896
17
alakazam.py
17
alakazam.py
|
@ -216,6 +216,8 @@ def new_app(recipe, domain, server):
|
|||
def update_configs(path, config):
|
||||
if uncomment_keys := config.get("uncomment"):
|
||||
uncomment(uncomment_keys, path, True)
|
||||
if comment_keys := config.get("comment"):
|
||||
comment(comment_keys, path, True)
|
||||
if envs := config.get("env"):
|
||||
uncomment(envs.keys(), path)
|
||||
for key, value in envs.items():
|
||||
|
@ -334,6 +336,21 @@ def uncomment(keys, path, match_all=False):
|
|||
file.write(line)
|
||||
|
||||
|
||||
def comment(keys, path, match_all=False):
|
||||
logging.debug(f'Comment {keys} in {path}')
|
||||
with open(path, "r") as file:
|
||||
lines = file.readlines()
|
||||
with open(path, "w") as file:
|
||||
for line in lines:
|
||||
line_match = line.split("=")[0] # Match only keys
|
||||
if match_all:
|
||||
line_match = line
|
||||
if any(key in line_match for key in keys):
|
||||
line = line.lstrip("#").lstrip()
|
||||
line = f"#{line}"
|
||||
file.write(line)
|
||||
|
||||
|
||||
def exchange_domains(instance, instance_config, path):
|
||||
for app in instance_config:
|
||||
old_app_domain = f'{app}.example.com'
|
||||
|
|
Loading…
Reference in New Issue