|
|
@ -17,7 +17,8 @@ def check_env() -> bool:
|
|
|
|
bool: Whether or not everything was put in properly
|
|
|
|
bool: Whether or not everything was put in properly
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
if not os.path.exists(".env.template"):
|
|
|
|
if not os.path.exists(".env.template"):
|
|
|
|
console.print("[red]Couldn't find .env.template. Unable to check variables.")
|
|
|
|
console.print(
|
|
|
|
|
|
|
|
"[red]Couldn't find .env.template. Unable to check variables.")
|
|
|
|
return True
|
|
|
|
return True
|
|
|
|
if not os.path.exists(".env"):
|
|
|
|
if not os.path.exists(".env"):
|
|
|
|
console.print("[red]Couldn't find the .env file, creating one now.")
|
|
|
|
console.print("[red]Couldn't find the .env file, creating one now.")
|
|
|
@ -38,14 +39,17 @@ def check_env() -> bool:
|
|
|
|
if line.startswith("#") is not True and "=" in line and var_optional is not True:
|
|
|
|
if line.startswith("#") is not True and "=" in line and var_optional is not True:
|
|
|
|
req_envs.append(line.split("=")[0])
|
|
|
|
req_envs.append(line.split("=")[0])
|
|
|
|
if "#" in line:
|
|
|
|
if "#" in line:
|
|
|
|
examples[line.split("=")[0]] = "#".join(line.split("#")[1:]).strip()
|
|
|
|
examples[line.split("=")[0]] = "#".join(
|
|
|
|
|
|
|
|
line.split("#")[1:]).strip()
|
|
|
|
elif "#OPTIONAL" in line:
|
|
|
|
elif "#OPTIONAL" in line:
|
|
|
|
var_optional = True
|
|
|
|
var_optional = True
|
|
|
|
elif line.startswith("#MATCH_REGEX "):
|
|
|
|
elif line.startswith("#MATCH_REGEX "):
|
|
|
|
matching[req_envs[-1]] = line.removeprefix("#MATCH_REGEX ")[:-1]
|
|
|
|
matching[req_envs[-1]
|
|
|
|
|
|
|
|
] = line.removeprefix("#MATCH_REGEX ")[:-1]
|
|
|
|
var_optional = False
|
|
|
|
var_optional = False
|
|
|
|
elif line.startswith("#OOB_ERROR "):
|
|
|
|
elif line.startswith("#OOB_ERROR "):
|
|
|
|
oob_errors[req_envs[-1]] = line.removeprefix("#OOB_ERROR ")[:-1]
|
|
|
|
oob_errors[req_envs[-1]
|
|
|
|
|
|
|
|
] = line.removeprefix("#OOB_ERROR ")[:-1]
|
|
|
|
var_optional = False
|
|
|
|
var_optional = False
|
|
|
|
elif line.startswith("#RANGE "):
|
|
|
|
elif line.startswith("#RANGE "):
|
|
|
|
bounds[req_envs[-1]] = tuple(
|
|
|
|
bounds[req_envs[-1]] = tuple(
|
|
|
@ -56,10 +60,12 @@ def check_env() -> bool:
|
|
|
|
)
|
|
|
|
)
|
|
|
|
var_optional = False
|
|
|
|
var_optional = False
|
|
|
|
elif line.startswith("#MATCH_TYPE "):
|
|
|
|
elif line.startswith("#MATCH_TYPE "):
|
|
|
|
types[req_envs[-1]] = eval(line.removeprefix("#MATCH_TYPE ")[:-1].split()[0])
|
|
|
|
types[req_envs[-1]
|
|
|
|
|
|
|
|
] = eval(line.removeprefix("#MATCH_TYPE ")[:-1].split()[0])
|
|
|
|
var_optional = False
|
|
|
|
var_optional = False
|
|
|
|
elif line.startswith("#EXPLANATION "):
|
|
|
|
elif line.startswith("#EXPLANATION "):
|
|
|
|
explanations[req_envs[-1]] = line.removeprefix("#EXPLANATION ")[:-1]
|
|
|
|
explanations[req_envs[-1]
|
|
|
|
|
|
|
|
] = line.removeprefix("#EXPLANATION ")[:-1]
|
|
|
|
var_optional = False
|
|
|
|
var_optional = False
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
var_optional = False
|
|
|
|
var_optional = False
|
|
|
@ -99,17 +105,22 @@ def check_env() -> bool:
|
|
|
|
title_justify="left",
|
|
|
|
title_justify="left",
|
|
|
|
title_style="#C0CAF5 bold",
|
|
|
|
title_style="#C0CAF5 bold",
|
|
|
|
)
|
|
|
|
)
|
|
|
|
table.add_column("Variable", justify="left", style="#7AA2F7 bold", no_wrap=True)
|
|
|
|
table.add_column("Variable", justify="left",
|
|
|
|
table.add_column("Explanation", justify="left", style="#BB9AF7", no_wrap=False)
|
|
|
|
style="#7AA2F7 bold", no_wrap=True)
|
|
|
|
table.add_column("Example", justify="center", style="#F7768E", no_wrap=True)
|
|
|
|
table.add_column("Explanation", justify="left",
|
|
|
|
|
|
|
|
style="#BB9AF7", no_wrap=False)
|
|
|
|
|
|
|
|
table.add_column("Example", justify="center",
|
|
|
|
|
|
|
|
style="#F7768E", no_wrap=True)
|
|
|
|
table.add_column("Min", justify="right", style="#F7768E", no_wrap=True)
|
|
|
|
table.add_column("Min", justify="right", style="#F7768E", no_wrap=True)
|
|
|
|
table.add_column("Max", justify="left", style="#F7768E", no_wrap=True)
|
|
|
|
table.add_column("Max", justify="left", style="#F7768E", no_wrap=True)
|
|
|
|
for env in missing:
|
|
|
|
for env in missing:
|
|
|
|
table.add_row(
|
|
|
|
table.add_row(
|
|
|
|
env,
|
|
|
|
env,
|
|
|
|
explanations[env] if env in explanations.keys() else "No explanation given",
|
|
|
|
explanations[env] if env in explanations.keys(
|
|
|
|
|
|
|
|
) else "No explanation given",
|
|
|
|
examples[env] if env in examples.keys() else "",
|
|
|
|
examples[env] if env in examples.keys() else "",
|
|
|
|
str(bounds[env][0]) if env in bounds.keys() and bounds[env][1] is not None else "",
|
|
|
|
str(bounds[env][0]) if env in bounds.keys(
|
|
|
|
|
|
|
|
) and bounds[env][1] is not None else "",
|
|
|
|
str(bounds[env][1])
|
|
|
|
str(bounds[env][1])
|
|
|
|
if env in bounds.keys() and len(bounds[env]) > 1 and bounds[env][1] is not None
|
|
|
|
if env in bounds.keys() and len(bounds[env]) > 1 and bounds[env][1] is not None
|
|
|
|
else "",
|
|
|
|
else "",
|
|
|
@ -127,20 +138,26 @@ def check_env() -> bool:
|
|
|
|
title_justify="left",
|
|
|
|
title_justify="left",
|
|
|
|
title_style="#C0CAF5 bold",
|
|
|
|
title_style="#C0CAF5 bold",
|
|
|
|
)
|
|
|
|
)
|
|
|
|
table.add_column("Variable", justify="left", style="#7AA2F7 bold", no_wrap=True)
|
|
|
|
table.add_column("Variable", justify="left",
|
|
|
|
table.add_column("Current value", justify="left", style="#F7768E", no_wrap=False)
|
|
|
|
style="#7AA2F7 bold", no_wrap=True)
|
|
|
|
table.add_column("Explanation", justify="left", style="#BB9AF7", no_wrap=False)
|
|
|
|
table.add_column("Current value", justify="left",
|
|
|
|
table.add_column("Example", justify="center", style="#F7768E", no_wrap=True)
|
|
|
|
style="#F7768E", no_wrap=False)
|
|
|
|
|
|
|
|
table.add_column("Explanation", justify="left",
|
|
|
|
|
|
|
|
style="#BB9AF7", no_wrap=False)
|
|
|
|
|
|
|
|
table.add_column("Example", justify="center",
|
|
|
|
|
|
|
|
style="#F7768E", no_wrap=True)
|
|
|
|
table.add_column("Min", justify="right", style="#F7768E", no_wrap=True)
|
|
|
|
table.add_column("Min", justify="right", style="#F7768E", no_wrap=True)
|
|
|
|
table.add_column("Max", justify="left", style="#F7768E", no_wrap=True)
|
|
|
|
table.add_column("Max", justify="left", style="#F7768E", no_wrap=True)
|
|
|
|
for env in incorrect:
|
|
|
|
for env in incorrect:
|
|
|
|
table.add_row(
|
|
|
|
table.add_row(
|
|
|
|
env,
|
|
|
|
env,
|
|
|
|
os.getenv(env),
|
|
|
|
os.getenv(env),
|
|
|
|
explanations[env] if env in explanations.keys() else "No explanation given",
|
|
|
|
explanations[env] if env in explanations.keys(
|
|
|
|
|
|
|
|
) else "No explanation given",
|
|
|
|
str(types[env].__name__) if env in types.keys() else "str",
|
|
|
|
str(types[env].__name__) if env in types.keys() else "str",
|
|
|
|
str(bounds[env][0]) if env in bounds.keys() else "None",
|
|
|
|
str(bounds[env][0]) if env in bounds.keys() else "None",
|
|
|
|
str(bounds[env][1]) if env in bounds.keys() and len(bounds[env]) > 1 else "None",
|
|
|
|
str(bounds[env][1]) if env in bounds.keys() and len(
|
|
|
|
|
|
|
|
bounds[env]) > 1 else "None",
|
|
|
|
)
|
|
|
|
)
|
|
|
|
missing.add(env)
|
|
|
|
missing.add(env)
|
|
|
|
console.print(table)
|
|
|
|
console.print(table)
|
|
|
@ -157,11 +174,13 @@ def check_env() -> bool:
|
|
|
|
with open(".env", "r+") as env_file:
|
|
|
|
with open(".env", "r+") as env_file:
|
|
|
|
lines = []
|
|
|
|
lines = []
|
|
|
|
for line in env_file.readlines():
|
|
|
|
for line in env_file.readlines():
|
|
|
|
line.split("=")[0].strip() not in incorrect and lines.append(line)
|
|
|
|
line.split("=")[0].strip(
|
|
|
|
|
|
|
|
) not in incorrect and lines.append(line)
|
|
|
|
env_file.seek(0)
|
|
|
|
env_file.seek(0)
|
|
|
|
env_file.write("\n".join(lines))
|
|
|
|
env_file.write("\n".join(lines))
|
|
|
|
env_file.truncate()
|
|
|
|
env_file.truncate()
|
|
|
|
console.print("[green]Successfully removed incorrectly set variables from .env")
|
|
|
|
console.print(
|
|
|
|
|
|
|
|
"[green]Successfully removed incorrectly set variables from .env")
|
|
|
|
with open(".env", "a") as env_file:
|
|
|
|
with open(".env", "a") as env_file:
|
|
|
|
for env in missing:
|
|
|
|
for env in missing:
|
|
|
|
env_file.write(
|
|
|
|
env_file.write(
|
|
|
@ -177,11 +196,14 @@ def check_env() -> bool:
|
|
|
|
if env in explanations.keys()
|
|
|
|
if env in explanations.keys()
|
|
|
|
else "Incorrect input. Try again.",
|
|
|
|
else "Incorrect input. Try again.",
|
|
|
|
bounds[env][0] if env in bounds.keys() else None,
|
|
|
|
bounds[env][0] if env in bounds.keys() else None,
|
|
|
|
bounds[env][1] if env in bounds.keys() and len(bounds[env]) > 1 else None,
|
|
|
|
bounds[env][1] if env in bounds.keys() and len(
|
|
|
|
oob_errors[env] if env in oob_errors.keys() else "Input too long/short.",
|
|
|
|
bounds[env]) > 1 else None,
|
|
|
|
|
|
|
|
oob_errors[env] if env in oob_errors.keys(
|
|
|
|
|
|
|
|
) else "Input too long/short.",
|
|
|
|
extra_info="[#C0CAF5 bold]⮶ "
|
|
|
|
extra_info="[#C0CAF5 bold]⮶ "
|
|
|
|
+ (
|
|
|
|
+ (
|
|
|
|
explanations[env] if env in explanations.keys() else "No info available"
|
|
|
|
explanations[env] if env in explanations.keys(
|
|
|
|
|
|
|
|
) else "No info available"
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|