mirror of
https://git.srhtnin.garden/sarah/SaraSortd.git
synced 2026-10-14 18:48:11 +02:00
Added stacking of NextNum and NextChar. E.G: && into AA => "AB" instead
of && into AA => "BB". Also, !! into 01 => 02 instead of !! into 11 => 22. This was surprisingly difficult to achieve.
This commit is contained in:
1 parent
443d9231e2
commit
cbf1a4049c
1 file changed
+69
-24
+69
-24
@@ -302,30 +302,62 @@ def DecideNewPath(FilePath):
|
|||||||
if Match:
|
if Match:
|
||||||
NewFileName = File["NewFileName"]
|
NewFileName = File["NewFileName"]
|
||||||
|
|
||||||
NewFileName = Parse(
|
NewFileName = Parse(String = NewFileName, Path = DirConfPath, OrgFile = UnsortedFile, NextNum = File["NextNum"], NextChar = File["NextChar"], Parent = ParentName)
|
||||||
String = NewFileName,
|
|
||||||
Path = DirConfPath,
|
|
||||||
OrgFile = UnsortedFile,
|
|
||||||
NextNum = File["NextNum"],
|
|
||||||
NextChar = File["NextChar"],
|
|
||||||
Parent = ParentName,
|
|
||||||
)
|
|
||||||
|
|
||||||
if File["Overwrite"] == 0 and os.path.exists(os.path.join(Output, NewFileName)):
|
if File["Overwrite"] == 0 and os.path.exists(os.path.join(Output, NewFileName)):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if ConfVars["NextNum"] in NewFileName:
|
if ConfVars["NextNum"] in File["NewFileName"]:
|
||||||
UpdateConf(
|
ConfData = toml.load(DirConfPath)
|
||||||
DirConfPath,
|
|
||||||
"NextNum",
|
|
||||||
(int(GetConf("NextNum", DirConfPath)) + 1),
|
|
||||||
)
|
|
||||||
|
|
||||||
if ConfVars["NextChar"] in NewFileName:
|
NewNum = (int(File["NextNum"]) + 1)
|
||||||
CurrentChar = GetConf("NextChar", DirConfPath)
|
|
||||||
if CurrentChar and len(CurrentChar) == 1 and CurrentChar.isalpha():
|
for Item in ConfData.get("Files", []):
|
||||||
NewChar = chr(((ord(CurrentChar.upper()) - 65 + 1) % 26) + 65)
|
if Item.get("Pattern") == File["Pattern"]:
|
||||||
UpdateConf(DirConfPath, "NextChar", NewChar)
|
Item["NextNum"] = NewNum
|
||||||
|
break
|
||||||
|
|
||||||
|
with open(DirConfPath, "w", encoding="utf-8") as ConfFile:
|
||||||
|
toml.dump(ConfData, ConfFile)
|
||||||
|
|
||||||
|
TextOutput = Parse(String = ConfLog["ValueSet"], VarCall = f"NextChar to {NewNum}")
|
||||||
|
LogWrite(TextOutput)
|
||||||
|
Speak(TextOutput)
|
||||||
|
|
||||||
|
if ConfVars["NextChar"] in File["NewFileName"]:
|
||||||
|
CurrentChar = File["NextChar"]
|
||||||
|
CurrentChar = CurrentChar.upper()
|
||||||
|
Result = list(CurrentChar)
|
||||||
|
|
||||||
|
Count = len(Result) - 1
|
||||||
|
|
||||||
|
while Count >= 0:
|
||||||
|
if Result[Count] == "Z":
|
||||||
|
Result[Count] = "A"
|
||||||
|
Count -= 1
|
||||||
|
|
||||||
|
else:
|
||||||
|
Result[Count] = chr(ord(Result[Count]) + 1)
|
||||||
|
break
|
||||||
|
|
||||||
|
else:
|
||||||
|
Result.insert(0, "A")
|
||||||
|
|
||||||
|
NewChar = "".join(Result)
|
||||||
|
|
||||||
|
ConfData = toml.load(DirConfPath)
|
||||||
|
|
||||||
|
for Item in ConfData.get("Files", []):
|
||||||
|
if Item.get("Pattern") == File["Pattern"]:
|
||||||
|
Item["NextChar"] = NewChar
|
||||||
|
break
|
||||||
|
|
||||||
|
with open(DirConfPath, "w", encoding="utf-8") as ConfFile:
|
||||||
|
toml.dump(ConfData, ConfFile)
|
||||||
|
|
||||||
|
TextOutput = Parse(String = ConfLog["ValueSet"], VarCall = f"NextChar to {NewChar}")
|
||||||
|
LogWrite(TextOutput)
|
||||||
|
Speak(TextOutput)
|
||||||
|
|
||||||
return f"{Output}/{NewFileName}"
|
return f"{Output}/{NewFileName}"
|
||||||
|
|
||||||
@@ -383,10 +415,27 @@ def Init():
|
|||||||
InputDir = Parse(String = InputDir, Path = ConfPath, Parent = os.path.basename(os.path.dirname(InputDir)))
|
InputDir = Parse(String = InputDir, Path = ConfPath, Parent = os.path.basename(os.path.dirname(InputDir)))
|
||||||
Dir(InputDir, Output = False, CopyConf = False)
|
Dir(InputDir, Output = False, CopyConf = False)
|
||||||
|
|
||||||
|
for Output in ConfDirs["OutputDir"]:
|
||||||
|
Output = Parse(String = Output, Parent = os.path.basename(os.path.dirname(Output)))
|
||||||
|
Dir(Output)
|
||||||
|
|
||||||
|
DirConfPath = f"{os.path.join(Output, Parse(String = ConfNames["DirConfName"], Parent = os.path.basename(Output)))}.toml"
|
||||||
|
ConfData = toml.load(DirConfPath)
|
||||||
|
|
||||||
|
for Item in ConfData.get("Files", []):
|
||||||
|
Character = re.escape(ConfVars["NextChar"])
|
||||||
|
Matches = re.findall(f"{Character}+", Item["NewFileName"])
|
||||||
|
Width = max((len(Match) for Match in Matches), default=0)
|
||||||
|
|
||||||
|
if Width > 0:
|
||||||
|
Item["NextChar"] = Item["NextChar"].upper().rjust(Width, "A")
|
||||||
|
|
||||||
|
with open(DirConfPath, "w", encoding = "utf-8") as ConfFile:
|
||||||
|
toml.dump(ConfData, ConfFile)
|
||||||
|
|
||||||
TextOutput = Parse(String = ConfLog["Start"], Path = ConfPath)
|
TextOutput = Parse(String = ConfLog["Start"], Path = ConfPath)
|
||||||
LogWrite(TextOutput)
|
LogWrite(TextOutput)
|
||||||
Speak(TextOutput)
|
Speak(TextOutput)
|
||||||
|
|
||||||
Main()
|
Main()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@@ -401,10 +450,6 @@ def Init():
|
|||||||
|
|
||||||
|
|
||||||
def Main():
|
def Main():
|
||||||
for Output in ConfDirs["OutputDir"]:
|
|
||||||
Output = Parse(String = Output, Parent = os.path.basename(os.path.dirname(Output)))
|
|
||||||
Dir(Output)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
for Input in ConfDirs["InputDir"]:
|
for Input in ConfDirs["InputDir"]:
|
||||||
|
|||||||
Reference in new issue
Block a user