Config failsafe
This commit is contained in:
@@ -1,3 +1,7 @@
|
|||||||
[DEFAULT]
|
[DEFAULT]
|
||||||
version = 1.12
|
version = 1.02
|
||||||
|
|
||||||
|
[ACCOUNT]
|
||||||
|
key = NK
|
||||||
|
id = NA
|
||||||
|
|
||||||
|
|||||||
20
CLI/Init.py
20
CLI/Init.py
@@ -1,5 +1,5 @@
|
|||||||
import configparser
|
import configparser
|
||||||
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
#declare default vars
|
#declare default vars
|
||||||
@@ -15,11 +15,21 @@ class Config():
|
|||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
configPath = Path("Config.ini")
|
configPath = Path("Config.ini")
|
||||||
|
|
||||||
|
def WarnMissingConfig(ConfigError):
|
||||||
|
print(f"[⚠️ WARNING ⚠️] - Your config file is corrupt , something that has to do with {ConfigError}")
|
||||||
|
print("Program will exit before it crashes :)")
|
||||||
|
reset = input("It is recommended that you reset the app data (you will be logged out) y (reset) / n (exit)")
|
||||||
|
if reset == "y":
|
||||||
|
os.remove(configPath)
|
||||||
|
print("[⚠️ WARNING ⚠️] - Reset Done, Re-Open TiropitCLI")
|
||||||
|
exit(0)
|
||||||
|
|
||||||
|
|
||||||
def makeConfig():
|
def makeConfig():
|
||||||
config['DEFAULT'] = {'Version': version}
|
config['DEFAULT'] = {'Version': Config.version}
|
||||||
config['ACCOUNT'] = {'KEY': "NK"}
|
config['ACCOUNT'] = {}
|
||||||
config['ACCOUNT'] = {'ID': "NK"}
|
config['ACCOUNT']['KEY'] = "NK"
|
||||||
|
config['ACCOUNT']["ID"] = "NA"
|
||||||
|
|
||||||
with open('Config.ini', 'w') as configfile:
|
with open('Config.ini', 'w') as configfile:
|
||||||
config.write(configfile)
|
config.write(configfile)
|
||||||
@@ -32,7 +42,7 @@ def loadConfig():
|
|||||||
Config.AccountID = config["ACCOUNT"]["ID"]
|
Config.AccountID = config["ACCOUNT"]["ID"]
|
||||||
Config.AccountID = config["ACCOUNT"]["KEY"]
|
Config.AccountID = config["ACCOUNT"]["KEY"]
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"An Error Occured , Check : {e}")
|
WarnMissingConfig(e)
|
||||||
|
|
||||||
def checkConfig():
|
def checkConfig():
|
||||||
if configPath.exists():
|
if configPath.exists():
|
||||||
|
|||||||
Reference in New Issue
Block a user