mirror of
https://git.srhtnin.garden/sarah/SaraSortd.git
synced 2026-10-13 18:38:11 +02:00
Fixed NextNum and NextChar to increment and properly work.
This commit is contained in:
1 parent
fda62dd53c
commit
4a5221494f
2 files changed
+52
-34
No files matched your search
+1
-1
@@ -26,7 +26,7 @@ LogDir = "%RootDir%/.Logs"
|
|||||||
FailedDir = "%RootDir%/.Failed"
|
FailedDir = "%RootDir%/.Failed"
|
||||||
|
|
||||||
[Names]
|
[Names]
|
||||||
LogFileName = "[y].[m].[d]._!"
|
LogFileName = "[y].[m].[d]"
|
||||||
DirConfName = ".@Config"
|
DirConfName = ".@Config"
|
||||||
|
|
||||||
[Log]
|
[Log]
|
||||||
|
|||||||
+51
-33
@@ -56,6 +56,10 @@ def GetConf(Parameter, *Paths):
|
|||||||
if (isinstance(Value, dict)):
|
if (isinstance(Value, dict)):
|
||||||
if (Parameter in Value):
|
if (Parameter in Value):
|
||||||
return Value[Parameter]
|
return Value[Parameter]
|
||||||
|
elif (isinstance(Value, list)):
|
||||||
|
for Item in Value:
|
||||||
|
if (isinstance(Item, dict) and Parameter in Item):
|
||||||
|
return Item[Parameter]
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@@ -63,33 +67,41 @@ def GetConf(Parameter, *Paths):
|
|||||||
def UpdateConf(Path, Parameter, Value, Append = False):
|
def UpdateConf(Path, Parameter, Value, Append = False):
|
||||||
ConfData = toml.load(Path)
|
ConfData = toml.load(Path)
|
||||||
|
|
||||||
Section = None
|
def UpdateInData(Data):
|
||||||
for Table, Data in ConfData.items():
|
if isinstance(Data, dict):
|
||||||
if (isinstance(Data, dict) and Parameter in Data):
|
if Parameter in Data:
|
||||||
Section = Table
|
|
||||||
break
|
|
||||||
|
|
||||||
if (Section == None):
|
|
||||||
TargetData = ConfData
|
|
||||||
|
|
||||||
else:
|
|
||||||
TargetData = ConfData[Section]
|
|
||||||
|
|
||||||
if (not Append):
|
if (not Append):
|
||||||
TargetData[Parameter] = Value
|
Data[Parameter] = Value
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if (Parameter not in TargetData):
|
Data.setdefault(Parameter, [])
|
||||||
TargetData[Parameter] = []
|
|
||||||
|
|
||||||
if (Value not in TargetData[Parameter]):
|
if (Value not in Data[Parameter]):
|
||||||
TargetData[Parameter].append(Value)
|
Data[Parameter].append(Value)
|
||||||
|
|
||||||
if (Section == None):
|
return True
|
||||||
ConfData = TargetData
|
else:
|
||||||
|
for Key, DataValue in Data.items():
|
||||||
|
if (UpdateInData(DataValue)):
|
||||||
|
return True
|
||||||
|
|
||||||
|
elif (isinstance(Data, list)):
|
||||||
|
for Item in Data:
|
||||||
|
if (UpdateInData(Item)):
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
Updated = UpdateInData(ConfData)
|
||||||
|
|
||||||
|
if (not Updated):
|
||||||
|
if not Append:
|
||||||
|
ConfData[Parameter] = Value
|
||||||
|
|
||||||
else:
|
else:
|
||||||
ConfData[Section] = TargetData
|
ConfData.setdefault(Parameter, [])
|
||||||
|
if (Value not in ConfData[Parameter]):
|
||||||
|
ConfData[Parameter].append(Value)
|
||||||
|
|
||||||
with open(Path, 'w', encoding='utf-8') as File:
|
with open(Path, 'w', encoding='utf-8') as File:
|
||||||
toml.dump(ConfData, File)
|
toml.dump(ConfData, File)
|
||||||
@@ -139,18 +151,18 @@ def Parse(String = None, Path = ConfPath,
|
|||||||
OrgFileType = None
|
OrgFileType = None
|
||||||
|
|
||||||
VarValues = {
|
VarValues = {
|
||||||
ConfVars["NextNum"]: NextNum,
|
ConfVars["NextNum"]: str(NextNum),
|
||||||
ConfVars["NextChar"]: NextChar,
|
ConfVars["NextChar"]: str(NextChar),
|
||||||
ConfVars["Parent"]: Parent,
|
ConfVars["Parent"]: str(Parent),
|
||||||
ConfVars["OrgFileName"]: OrgFileName,
|
ConfVars["OrgFileName"]: str(OrgFileName),
|
||||||
ConfVars["OrgFileType"]: OrgFileType,
|
ConfVars["OrgFileType"]: str(OrgFileType),
|
||||||
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"]: VarCall
|
ConfVars["VarCall"]: str(VarCall)
|
||||||
}
|
}
|
||||||
|
|
||||||
for Key, Value in VarValues.items():
|
for Key, Value in VarValues.items():
|
||||||
@@ -231,7 +243,17 @@ def DecideNewPath(FilePath):
|
|||||||
|
|
||||||
if fnmatch.fnmatch(UnsortedFile, Pattern):
|
if fnmatch.fnmatch(UnsortedFile, Pattern):
|
||||||
NewFileName = File["NewFileName"]
|
NewFileName = File["NewFileName"]
|
||||||
NewFileName = Parse(String = NewFileName, Path = DirConfPath, OrgFile = UnsortedFile)
|
|
||||||
|
if (ConfVars["NextNum"] in NewFileName):
|
||||||
|
UpdateConf(DirConfPath, "NextNum", (int(GetConf("NextNum", DirConfPath)) + 1))
|
||||||
|
|
||||||
|
if (ConfVars["NextChar"] in NewFileName):
|
||||||
|
CurrentChar = GetConf("NextChar", DirConfPath)
|
||||||
|
if (CurrentChar and len(CurrentChar) == 1 and CurrentChar.isalpha()):
|
||||||
|
NewChar = chr(((ord(CurrentChar.upper()) - 65 +1) % 26) +65)
|
||||||
|
UpdateConf(DirConfPath, "NextChar", NewChar)
|
||||||
|
|
||||||
|
NewFileName = Parse(String = NewFileName, Path = DirConfPath, OrgFile = UnsortedFile, NextNum = File["NextNum"], NextChar = File["NextChar"], Parent = ParentName)
|
||||||
return f"{Output}/{NewFileName}"
|
return f"{Output}/{NewFileName}"
|
||||||
|
|
||||||
|
|
||||||
@@ -249,11 +271,7 @@ def Sort(FilePath):
|
|||||||
return
|
return
|
||||||
|
|
||||||
NewDirPath = os.path.dirname(NewPath)
|
NewDirPath = os.path.dirname(NewPath)
|
||||||
|
NewName = os.path.basename(NewPath)
|
||||||
NextNum = GetConf("NextNum", f"{NewDirPath}/{Parse(String = ConfNames["DirConfName"], Parent = os.path.basename(NewDirPath))}.toml")
|
|
||||||
NextChar = GetConf("NextChar", f"{NewDirPath}/{Parse(String = ConfNames["DirConfName"], Parent = os.path.basename(NewDirPath))}.toml")
|
|
||||||
|
|
||||||
NewName = Parse(os.path.basename(FilePath), NextNum = NextNum, NextChar = NextChar)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
Clone(FilePath, NewDirPath, NewName, True)
|
Clone(FilePath, NewDirPath, NewName, True)
|
||||||
@@ -265,7 +283,7 @@ def Sort(FilePath):
|
|||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
Dir(Parse(String = ConfDirs["FailedDir"]), Output = False, CopyConf = False)
|
Dir(Parse(String = ConfDirs["FailedDir"]), Output = False, CopyConf = False)
|
||||||
NewName = os.path.basename(FilePath)
|
NewName = os.path.basename(NewPath)
|
||||||
Clone(FilePath, Parse(String = ConfDirs["FailedDir"]), NewName, True)
|
Clone(FilePath, Parse(String = ConfDirs["FailedDir"]), NewName, True)
|
||||||
|
|
||||||
TextOutput = Parse(String = ConfLog["NotSorted"], VarCall = FilePath)
|
TextOutput = Parse(String = ConfLog["NotSorted"], VarCall = FilePath)
|
||||||
|
|||||||
Reference in new issue
Block a user