mirror of
https://git.srhtnin.garden/sarah/SaraSortd.git
synced 2026-10-14 18:48:11 +02:00
Removed and commented some Parameters in Config, and added much more to SaraSortd.py
This commit is contained in:
1 parent
ee8c83039c
commit
eb4ca3264b
2 files changed
+119
-17
No files matched your search
+102
-8
@@ -1,6 +1,12 @@
|
||||
import toml, os
|
||||
import toml, os, datetime
|
||||
|
||||
Conf = None
|
||||
ConfVars = None
|
||||
ConfDirs = None
|
||||
ConfNames = None
|
||||
ConfLog = None
|
||||
|
||||
Start = True
|
||||
|
||||
def Clear():
|
||||
if os.name == 'nt':
|
||||
@@ -10,25 +16,113 @@ def Clear():
|
||||
|
||||
|
||||
def LoadConf():
|
||||
global Conf
|
||||
global Conf, ConfVars, ConfDirs, ConfNames, ConfLog
|
||||
|
||||
LocalConf = toml.load("Config.toml")
|
||||
Conf = LocalConf
|
||||
ConfVars = Conf["Variables"]
|
||||
ConfDirs = Conf["DirectoryPaths"]
|
||||
ConfNames = Conf["Names"]
|
||||
ConfLog = Conf["Log"]
|
||||
|
||||
|
||||
def Error():
|
||||
global Start
|
||||
if (Conf["SafeMode"] == 1):
|
||||
Start = False
|
||||
|
||||
|
||||
def Speak(Text):
|
||||
if (Conf["SilentMode"] != 1):
|
||||
print(Text)
|
||||
|
||||
|
||||
def Parse(String = None, Var = None, OrgFile = None, OutputDir = None):
|
||||
Now = datetime.datetime.now()
|
||||
|
||||
ParseBook = {
|
||||
ConfVars["Year"]: str(Now.year),
|
||||
ConfVars["Month"]: str(Now.month),
|
||||
ConfVars["Day"]: str(Now.day),
|
||||
ConfVars["Hour"]: str(Now.hour),
|
||||
ConfVars["Minute"]: str(Now.minute),
|
||||
ConfVars["Second"]: str(Now.second),
|
||||
ConfVars["VarCall"]: Var,
|
||||
ConfVars["NextNum"]: "NOT ADDED",
|
||||
ConfVars["NextChar"]: "NOT ADDED",
|
||||
ConfVars["Parent"]: "NOT ADDED",
|
||||
ConfVars["OrgFileName"]: "NOT ADDED",
|
||||
ConfVars["OrgFileType"]: "NOT ADDED",
|
||||
}
|
||||
|
||||
for Key, Value in ParseBook.items():
|
||||
if Key in String and Value is not None:
|
||||
String = String.replace(Key, Value)
|
||||
|
||||
return String
|
||||
|
||||
|
||||
def Dir(Name):
|
||||
os.makedirs(Name, exist_ok=True)
|
||||
|
||||
|
||||
def LogWrite(Text):
|
||||
if (ConfDirs["LogDir"] != None and ConfNames != "Unset"):
|
||||
if (ConfNames["LogFileName"] != None and ConfNames["LogFileName"] != "Unset"):
|
||||
Dir(Parse(ConfDirs["LogDir"]))
|
||||
LogFile = f"{Parse(ConfDirs["LogDir"])}/{Parse(ConfNames["LogFileName"])}.log"
|
||||
with open(LogFile, "w", encoding="utf-8") as File:
|
||||
File.write(f"{Parse(ConfLog["All"])}{Text}\n")
|
||||
|
||||
|
||||
def ConfCheck():
|
||||
for Item in ConfVars:
|
||||
if (Item == None or Item == "Unset"):
|
||||
TextOutput = Parse(ConfLog["Unset"], Item)
|
||||
LogWrite(TextOutput)
|
||||
Speak(TextOutput)
|
||||
Error()
|
||||
|
||||
for Item in ConfDirs:
|
||||
if (Item == None or Item == "Unset"):
|
||||
TextOutput = Parse(ConfLog["Unset"], Item)
|
||||
LogWrite(TextOutput)
|
||||
Speak(TextOutput)
|
||||
Error()
|
||||
|
||||
for Item in ConfLog:
|
||||
if (Item == None or Item == "Unset"):
|
||||
TextOutput = Parse(ConfLog["Unset"], Item)
|
||||
LogWrite(TextOutput)
|
||||
Speak(TextOutput)
|
||||
Error()
|
||||
|
||||
|
||||
def Init():
|
||||
global Conf
|
||||
global Conf, ConfVars, ConfDirs, ConfNames, ConfLog
|
||||
|
||||
LoadConf()
|
||||
if (Conf != None):
|
||||
Main()
|
||||
ConfCheck()
|
||||
|
||||
TextOutput = Parse(ConfLog["Start"])
|
||||
LogWrite(TextOutput)
|
||||
Speak(TextOutput)
|
||||
|
||||
if (Start):
|
||||
Main()
|
||||
else:
|
||||
TextOutput = Parse(ConfLog["NotStart"])
|
||||
LogWrite(TextOutput)
|
||||
Speak(TextOutput)
|
||||
|
||||
else:
|
||||
print("NO CONFIG FOUND! Make sure the 'Config.toml' is in the same directory as 'SaraSortd.py'")
|
||||
|
||||
|
||||
def Main():
|
||||
global Conf
|
||||
|
||||
Clear()
|
||||
print(Conf)
|
||||
while True:
|
||||
pass
|
||||
|
||||
|
||||
Init()
|
||||
Reference in new issue
Block a user