mirror of
https://git.srhtnin.garden/sarah/SaraSortd.git
synced 2026-10-14 02:38:12 +02:00
Renamed files.
This commit is contained in:
1 parent
5933dd94d2
commit
0f2f6673aa
4 files changed
+33
-29
No files matched your search
@@ -1,5 +1,5 @@
|
|||||||
Title = "SaraSortd Config"
|
Title = "SaraSortd Config"
|
||||||
Version = "4.0"
|
Version = "5.0"
|
||||||
SafeMode = 1
|
SafeMode = 1
|
||||||
SilentMode = 0
|
SilentMode = 0
|
||||||
CheckInput = 5
|
CheckInput = 5
|
||||||
@@ -22,7 +22,7 @@ Second = "[s]"
|
|||||||
VarCall = "%%"
|
VarCall = "%%"
|
||||||
|
|
||||||
[DirectoryPaths]
|
[DirectoryPaths]
|
||||||
RootDir = "Unset"
|
RootDir = "C:/Users/sar2711/OneDrive - Telemark fylkeskommune/Desktop/Testdir"
|
||||||
InputDir = [ "%RootDir%/Input" ]
|
InputDir = [ "%RootDir%/Input" ]
|
||||||
OutputDir = [ "%RootDir%/Output" ]
|
OutputDir = [ "%RootDir%/Output" ]
|
||||||
LogDir = "%RootDir%/.Logs"
|
LogDir = "%RootDir%/.Logs"
|
||||||
@@ -30,7 +30,8 @@ FailedDir = "%RootDir%/.Failed"
|
|||||||
|
|
||||||
[Names]
|
[Names]
|
||||||
LogFileName = "[y].[m].[d]"
|
LogFileName = "[y].[m].[d]"
|
||||||
DirConfName = ".@Config"
|
InDirConfName = ".@Config"
|
||||||
|
OutDirConfName = ".@Config"
|
||||||
FileHistoryName = ".@History"
|
FileHistoryName = ".@History"
|
||||||
|
|
||||||
[Log]
|
[Log]
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
Title = "Unset"
|
||||||
|
Version = "5.0"
|
||||||
|
ParentDir = "Unset"
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
Title = "Unset"
|
Title = "Unset"
|
||||||
Version = "4.0"
|
Version = "5.0"
|
||||||
LastFile = "Unset"
|
LastFile = "Unset"
|
||||||
ParentDir = "Unset"
|
ParentDir = "Unset"
|
||||||
ValidInputDirs = ["*"]
|
ValidInputDirs = ["*"]
|
||||||
+25
-25
@@ -6,9 +6,9 @@ import shutil
|
|||||||
import time
|
import time
|
||||||
import toml
|
import toml
|
||||||
|
|
||||||
# Version 4.0
|
# Version 5.0
|
||||||
|
|
||||||
ConfPath = "./Config.toml"
|
ConfPath = "./GlobalConf.toml"
|
||||||
|
|
||||||
Conf = None
|
Conf = None
|
||||||
ConfVars = None
|
ConfVars = None
|
||||||
@@ -222,18 +222,18 @@ def Dir(Path, Output = True, CopyConf = True):
|
|||||||
os.makedirs(Path, exist_ok=True)
|
os.makedirs(Path, exist_ok=True)
|
||||||
|
|
||||||
if CopyConf:
|
if CopyConf:
|
||||||
NewDirConf = f"{Parse(String = ConfNames['DirConfName'], Path = ConfPath, Parent = ParentName)}.toml"
|
NewOutDirConf = f"{Parse(String = ConfNames['OutDirConfName'], Path = ConfPath, Parent = ParentName)}.toml"
|
||||||
if Conf["OverwriteDirConf"] == 1 or not os.path.exists(
|
if Conf["OverwriteDirConf"] == 1 or not os.path.exists(
|
||||||
os.path.join(f"{Path}/{NewDirConf}")
|
os.path.join(f"{Path}/{NewOutDirConf}")
|
||||||
):
|
):
|
||||||
Clone("DirConfig.toml", Path, NewDirConf)
|
Clone("OutputDirConf.toml", Path, NewOutDirConf)
|
||||||
UpdateConf(
|
UpdateConf(
|
||||||
f"{Path}/{Parse(String = ConfNames['DirConfName'], Path = ConfPath, Parent = ParentName)}.toml",
|
f"{Path}/{Parse(String = ConfNames['OutDirConfName'], Path = ConfPath, Parent = ParentName)}.toml",
|
||||||
"ParentDir",
|
"ParentDir",
|
||||||
ParentName,
|
ParentName,
|
||||||
)
|
)
|
||||||
UpdateConf(
|
UpdateConf(
|
||||||
f"{Path}/{Parse(String = ConfNames['DirConfName'], Path = ConfPath, Parent = ParentName)}.toml",
|
f"{Path}/{Parse(String = ConfNames['OutDirConfName'], Path = ConfPath, Parent = ParentName)}.toml",
|
||||||
"Title",
|
"Title",
|
||||||
f"{ParentName} Config",
|
f"{ParentName} Config",
|
||||||
)
|
)
|
||||||
@@ -266,13 +266,13 @@ def DecideNewPath(FilePath):
|
|||||||
|
|
||||||
ParentName = os.path.basename(Output)
|
ParentName = os.path.basename(Output)
|
||||||
|
|
||||||
DirConfName = Parse(String = ConfNames["DirConfName"], Path = ConfPath, Parent = ParentName)
|
OutDirConfName = Parse(String = ConfNames["OutDirConfName"], Path = ConfPath, Parent = ParentName)
|
||||||
DirConfPath = f"{Output}/{DirConfName}.toml"
|
OutDirConfPath = f"{Output}/{OutDirConfName}.toml"
|
||||||
|
|
||||||
ValidInputDirs = GetConf("ValidInputDirs", DirConfPath)
|
ValidInputDirs = GetConf("ValidInputDirs", OutDirConfPath)
|
||||||
|
|
||||||
for ValidInputDir in ValidInputDirs:
|
for ValidInputDir in ValidInputDirs:
|
||||||
ValidInputDir = Parse(String = ValidInputDir, Parent = GetConf("ParentDir", DirConfPath))
|
ValidInputDir = Parse(String = ValidInputDir, Parent = GetConf("ParentDir", OutDirConfPath))
|
||||||
|
|
||||||
TextOutput = Parse(String = ConfLog["MatchPattern"], VarCall = f"{os.path.dirname(FilePath)} against {ValidInputDir}")
|
TextOutput = Parse(String = ConfLog["MatchPattern"], VarCall = f"{os.path.dirname(FilePath)} against {ValidInputDir}")
|
||||||
LogWrite(TextOutput)
|
LogWrite(TextOutput)
|
||||||
@@ -282,12 +282,12 @@ def DecideNewPath(FilePath):
|
|||||||
if (InputDirValid):
|
if (InputDirValid):
|
||||||
break
|
break
|
||||||
|
|
||||||
if not os.path.exists(DirConfPath) or not InputDirValid:
|
if not os.path.exists(OutDirConfPath) or not InputDirValid:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
OutputFiles = 0
|
OutputFiles = 0
|
||||||
|
|
||||||
FileLimitConf = GetConf("FileLimit", DirConfPath)
|
FileLimitConf = GetConf("FileLimit", OutDirConfPath)
|
||||||
|
|
||||||
if FileLimitConf > 0:
|
if FileLimitConf > 0:
|
||||||
for OutputFile in os.listdir(Output):
|
for OutputFile in os.listdir(Output):
|
||||||
@@ -299,7 +299,7 @@ def DecideNewPath(FilePath):
|
|||||||
if OutputFiles >= FileLimitConf:
|
if OutputFiles >= FileLimitConf:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
FileConf = GetConf("Files", DirConfPath)
|
FileConf = GetConf("Files", OutDirConfPath)
|
||||||
|
|
||||||
if not FileConf:
|
if not FileConf:
|
||||||
continue
|
continue
|
||||||
@@ -320,13 +320,13 @@ def DecideNewPath(FilePath):
|
|||||||
if Match:
|
if Match:
|
||||||
NewFileName = File["NewFileName"]
|
NewFileName = File["NewFileName"]
|
||||||
|
|
||||||
NewFileName = Parse(String = NewFileName, Path = DirConfPath, OrgFile = UnsortedFile, NextNum = File["NextNum"], NextChar = File["NextChar"], Parent = ParentName)
|
NewFileName = Parse(String = NewFileName, Path = OutDirConfPath, 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 File["NewFileName"]:
|
if ConfVars["NextNum"] in File["NewFileName"]:
|
||||||
ConfData = toml.load(DirConfPath)
|
ConfData = toml.load(OutDirConfPath)
|
||||||
|
|
||||||
NewNum = (int(File["NextNum"]) + 1)
|
NewNum = (int(File["NextNum"]) + 1)
|
||||||
|
|
||||||
@@ -335,7 +335,7 @@ def DecideNewPath(FilePath):
|
|||||||
Item["NextNum"] = NewNum
|
Item["NextNum"] = NewNum
|
||||||
break
|
break
|
||||||
|
|
||||||
with open(DirConfPath, "w", encoding="utf-8") as ConfFile:
|
with open(OutDirConfPath, "w", encoding="utf-8") as ConfFile:
|
||||||
toml.dump(ConfData, ConfFile)
|
toml.dump(ConfData, ConfFile)
|
||||||
|
|
||||||
TextOutput = Parse(String = ConfLog["ValueSet"], VarCall = f"NextChar to {NewNum}")
|
TextOutput = Parse(String = ConfLog["ValueSet"], VarCall = f"NextChar to {NewNum}")
|
||||||
@@ -363,14 +363,14 @@ def DecideNewPath(FilePath):
|
|||||||
|
|
||||||
NewChar = "".join(Result)
|
NewChar = "".join(Result)
|
||||||
|
|
||||||
ConfData = toml.load(DirConfPath)
|
ConfData = toml.load(OutDirConfPath)
|
||||||
|
|
||||||
for Item in ConfData.get("Files", []):
|
for Item in ConfData.get("Files", []):
|
||||||
if Item.get("Pattern") == File["Pattern"]:
|
if Item.get("Pattern") == File["Pattern"]:
|
||||||
Item["NextChar"] = NewChar
|
Item["NextChar"] = NewChar
|
||||||
break
|
break
|
||||||
|
|
||||||
with open(DirConfPath, "w", encoding="utf-8") as ConfFile:
|
with open(OutDirConfPath, "w", encoding="utf-8") as ConfFile:
|
||||||
toml.dump(ConfData, ConfFile)
|
toml.dump(ConfData, ConfFile)
|
||||||
|
|
||||||
TextOutput = Parse(String = ConfLog["ValueSet"], VarCall = f"NextChar to {NewChar}")
|
TextOutput = Parse(String = ConfLog["ValueSet"], VarCall = f"NextChar to {NewChar}")
|
||||||
@@ -396,7 +396,7 @@ def Sort(FilePath):
|
|||||||
NewDirPath = os.path.dirname(NewPath)
|
NewDirPath = os.path.dirname(NewPath)
|
||||||
NewName = os.path.basename(NewPath)
|
NewName = os.path.basename(NewPath)
|
||||||
|
|
||||||
if (GetConf("DeleteOrg", f"{NewDirPath}/{Parse(String = ConfNames['DirConfName'], Parent = (os.path.basename(NewDirPath)))}.toml") == 1):
|
if (GetConf("DeleteOrg", f"{NewDirPath}/{Parse(String = ConfNames['OutDirConfName'], Parent = (os.path.basename(NewDirPath)))}.toml") == 1):
|
||||||
Delete = True
|
Delete = True
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@@ -404,7 +404,7 @@ def Sort(FilePath):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
Clone(FilePath, NewDirPath, NewName, Delete)
|
Clone(FilePath, NewDirPath, NewName, Delete)
|
||||||
UpdateConf(f"{NewDirPath}/{Parse(String = ConfNames['DirConfName'], Parent = os.path.basename(NewDirPath))}.toml", "LastFile", NewName)
|
UpdateConf(f"{NewDirPath}/{Parse(String = ConfNames['OutDirConfName'], Parent = os.path.basename(NewDirPath))}.toml", "LastFile", NewName)
|
||||||
|
|
||||||
TextOutput = Parse(String = ConfLog["Sorted"], VarCall = f"{FilePath} to {NewDirPath}/{NewName}")
|
TextOutput = Parse(String = ConfLog["Sorted"], VarCall = f"{FilePath} to {NewDirPath}/{NewName}")
|
||||||
LogWrite(TextOutput)
|
LogWrite(TextOutput)
|
||||||
@@ -437,8 +437,8 @@ def Init():
|
|||||||
Output = Parse(String = Output, Parent = os.path.basename(os.path.dirname(Output)))
|
Output = Parse(String = Output, Parent = os.path.basename(os.path.dirname(Output)))
|
||||||
Dir(Output)
|
Dir(Output)
|
||||||
|
|
||||||
DirConfPath = f"{Output}/{Parse(String = ConfNames["DirConfName"], Parent = os.path.basename(Output))}.toml"
|
OutDirConfPath = f"{Output}/{Parse(String = ConfNames["OutDirConfName"], Parent = os.path.basename(Output))}.toml"
|
||||||
ConfData = toml.load(DirConfPath)
|
ConfData = toml.load(OutDirConfPath)
|
||||||
|
|
||||||
for Item in ConfData.get("Files", []):
|
for Item in ConfData.get("Files", []):
|
||||||
Character = re.escape(ConfVars["NextChar"])
|
Character = re.escape(ConfVars["NextChar"])
|
||||||
@@ -448,7 +448,7 @@ def Init():
|
|||||||
if Width > 0:
|
if Width > 0:
|
||||||
Item["NextChar"] = Item["NextChar"].upper().rjust(Width, "A")
|
Item["NextChar"] = Item["NextChar"].upper().rjust(Width, "A")
|
||||||
|
|
||||||
with open(DirConfPath, "w", encoding = "utf-8") as ConfFile:
|
with open(OutDirConfPath, "w", encoding = "utf-8") as ConfFile:
|
||||||
toml.dump(ConfData, ConfFile)
|
toml.dump(ConfData, ConfFile)
|
||||||
|
|
||||||
TextOutput = Parse(String = ConfLog["Start"], Path = ConfPath)
|
TextOutput = Parse(String = ConfLog["Start"], Path = ConfPath)
|
||||||
@@ -462,7 +462,7 @@ def Init():
|
|||||||
Speak(TextOutput)
|
Speak(TextOutput)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print("NO CONFIG FOUND! Make sure the 'Config.toml' is in the same directory as 'SaraSortd.py'")
|
print("NO CONFIG FOUND! Make sure the 'GlobalConf.toml' is in the same directory as 'SaraSortd.py'")
|
||||||
|
|
||||||
|
|
||||||
def Main():
|
def Main():
|
||||||
|
|||||||
Reference in new issue
Block a user