forked from moritz/alakazam
add comment function
This commit is contained in:
17
alakazam.py
17
alakazam.py
@ -216,6 +216,8 @@ def new_app(recipe, domain, server):
|
|||||||
def update_configs(path, config):
|
def update_configs(path, config):
|
||||||
if uncomment_keys := config.get("uncomment"):
|
if uncomment_keys := config.get("uncomment"):
|
||||||
uncomment(uncomment_keys, path, True)
|
uncomment(uncomment_keys, path, True)
|
||||||
|
if comment_keys := config.get("comment"):
|
||||||
|
comment(comment_keys, path, True)
|
||||||
if envs := config.get("env"):
|
if envs := config.get("env"):
|
||||||
uncomment(envs.keys(), path)
|
uncomment(envs.keys(), path)
|
||||||
for key, value in envs.items():
|
for key, value in envs.items():
|
||||||
@ -334,6 +336,21 @@ def uncomment(keys, path, match_all=False):
|
|||||||
file.write(line)
|
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):
|
def exchange_domains(instance, instance_config, path):
|
||||||
for app in instance_config:
|
for app in instance_config:
|
||||||
old_app_domain = f'{app}.example.com'
|
old_app_domain = f'{app}.example.com'
|
||||||
|
Reference in New Issue
Block a user