mirror of
https://git.srhtnin.garden/sarah/SaraSortd.git
synced 2026-10-15 10:53:17 +02:00
Added a replacer function in Parse() to check for %RootDir% and others.
This commit is contained in:
1 parent
eb4ca3264b
commit
8abe270d93
1 file changed
+49
-13
+49
-13
@@ -1,4 +1,4 @@
|
|||||||
import toml, os, datetime
|
import toml, os, datetime, re
|
||||||
|
|
||||||
Conf = None
|
Conf = None
|
||||||
ConfVars = None
|
ConfVars = None
|
||||||
@@ -37,28 +37,63 @@ def Speak(Text):
|
|||||||
print(Text)
|
print(Text)
|
||||||
|
|
||||||
|
|
||||||
|
def GetConf(Parameter):
|
||||||
|
if Parameter in Conf:
|
||||||
|
return str(Conf[Parameter])
|
||||||
|
|
||||||
|
elif Parameter in ConfVars:
|
||||||
|
return str(ConfVars[Parameter])
|
||||||
|
|
||||||
|
elif Parameter in ConfDirs:
|
||||||
|
return str(ConfDirs[Parameter])
|
||||||
|
|
||||||
|
elif Parameter in ConfNames:
|
||||||
|
return str(ConfNames[Parameter])
|
||||||
|
|
||||||
|
elif Parameter in ConfLog:
|
||||||
|
return str(ConfLog[Parameter])
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def Parse(String = None, Var = None, OrgFile = None, OutputDir = None):
|
def Parse(String = None, Var = None, OrgFile = None, OutputDir = None):
|
||||||
|
def Replacer(Match):
|
||||||
|
Content = Match.group(1)
|
||||||
|
|
||||||
|
if (Content == None or Content == ""):
|
||||||
|
if (Var != None):
|
||||||
|
return str(Var)
|
||||||
|
else:
|
||||||
|
return ""
|
||||||
|
|
||||||
|
Value = GetConf(Content)
|
||||||
|
if (Value != None):
|
||||||
|
return Value
|
||||||
|
|
||||||
|
|
||||||
Now = datetime.datetime.now()
|
Now = datetime.datetime.now()
|
||||||
|
|
||||||
ParseBook = {
|
VarValues = {
|
||||||
|
ConfVars["NextNum"]: "NOT ADDED",
|
||||||
|
ConfVars["NextChar"]: "NOT ADDED",
|
||||||
|
ConfVars["Parent"]: "NOT ADDED",
|
||||||
|
ConfVars["OrgFileName"]: "NOT ADDED",
|
||||||
|
ConfVars["OrgFileType"]: "NOT ADDED",
|
||||||
ConfVars["Year"]: str(Now.year),
|
ConfVars["Year"]: str(Now.year),
|
||||||
ConfVars["Month"]: str(Now.month),
|
ConfVars["Month"]: str(Now.month),
|
||||||
ConfVars["Day"]: str(Now.day),
|
ConfVars["Day"]: str(Now.day),
|
||||||
ConfVars["Hour"]: str(Now.hour),
|
ConfVars["Hour"]: str(Now.hour),
|
||||||
ConfVars["Minute"]: str(Now.minute),
|
ConfVars["Minute"]: str(Now.minute),
|
||||||
ConfVars["Second"]: str(Now.second),
|
ConfVars["Second"]: str(Now.second),
|
||||||
ConfVars["VarCall"]: Var,
|
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():
|
for Key, Value in VarValues.items():
|
||||||
if Key in String and Value is not None:
|
if Key in String and Value is not None:
|
||||||
String = String.replace(Key, Value)
|
String = String.replace(Key, Value)
|
||||||
|
|
||||||
|
String = re.sub(r"%([^%]*)%", Replacer, String)
|
||||||
|
|
||||||
return String
|
return String
|
||||||
|
|
||||||
|
|
||||||
@@ -105,12 +140,13 @@ def Init():
|
|||||||
if (Conf != None):
|
if (Conf != None):
|
||||||
ConfCheck()
|
ConfCheck()
|
||||||
|
|
||||||
TextOutput = Parse(ConfLog["Start"])
|
|
||||||
LogWrite(TextOutput)
|
|
||||||
Speak(TextOutput)
|
|
||||||
|
|
||||||
if (Start):
|
if (Start):
|
||||||
|
TextOutput = Parse(ConfLog["Start"])
|
||||||
|
LogWrite(TextOutput)
|
||||||
|
Speak(TextOutput)
|
||||||
|
|
||||||
Main()
|
Main()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
TextOutput = Parse(ConfLog["NotStart"])
|
TextOutput = Parse(ConfLog["NotStart"])
|
||||||
LogWrite(TextOutput)
|
LogWrite(TextOutput)
|
||||||
|
|||||||
Reference in new issue
Block a user