@ -1,7 +1,6 @@
import re
import re
from typing import Tuple , Dict
from pathlib import Path
import toml
import toml
from pathlib import Path
from rich . console import Console
from rich . console import Console
from utils . console import handle_input
from utils . console import handle_input
@ -106,37 +105,36 @@ def check_vars(path, checks):
crawl_and_check ( config , path , checks )
crawl_and_check ( config , path , checks )
def check_toml ( template_file , config_file ) - > Tuple [ bool , Dict ] :
def check_toml ( template_file , config_file ) - > dict :
global config
global config
config = None
config = None
try :
try :
template = toml . load ( template_file )
template = toml . load ( template_file )
except Exception as error :
except Exception as error :
console . print ( f " [red bold]Encountered error when trying to to load { template_file } : { error } " )
console . print ( f " [red bold]Encountered error when trying to to load { template_file } : { error } " )
r eturn Fal se
r ai se
try :
try :
config = toml . load ( config_file )
config = toml . load ( config_file )
except toml . TomlDecodeError :
except toml . TomlDecodeError :
console . print (
console . print (
f """ [blue]Couldn ' t read { config_file } .
f """ [blue]Couldn ' t read { config_file } . Overwrite it?(y/n) """
Overwrite it ? ( y / n ) """
)
)
if not input ( ) . startswith ( " y " ) :
if not input ( ) . startswith ( " y " ) :
print ( " Unable to read config, and not allowed to overwrite it. Giving up. " )
print ( " Unable to read config, and not allowed to overwrite it. Giving up. " )
r eturn Fal se
r ai se
else :
else :
try :
try :
with open ( config_file , " w " ) as f :
with open ( config_file , " w " ) as f :
f . write ( " " )
f . write ( " " )
except :
except :
console . print (
console . print (
f " [red bold]Failed to overwrite { config_file } . Giving up. \n Suggestion: check { config_file } permissions for the user. "
f " [red bold]Failed to overwrite { config_file } . Giving up. "
f " \n Suggestion: check { config_file } permissions for the user. "
)
)
r eturn Fal se
r ai se
except FileNotFoundError :
except FileNotFoundError :
console . print (
console . print (
f """ [blue]Couldn ' t find { config_file }
f """ [blue]Couldn ' t find { config_file } Creating it now. """
Creating it now . """
)
)
try :
try :
with open ( config_file , " x " ) as f :
with open ( config_file , " x " ) as f :
@ -144,9 +142,10 @@ Creating it now."""
config = { }
config = { }
except :
except :
console . print (
console . print (
f " [red bold]Failed to write to { config_file } . Giving up. \n Suggestion: check the folder ' s permissions for the user. "
f " [red bold]Failed to write to { config_file } . Giving up. "
f " \n Suggestion: check the folder ' s permissions for the user. "
)
)
r eturn Fal se
r ai se
console . print (
console . print (
""" \
""" \