diff --git a/Config.toml b/GlobalConf.toml similarity index 84% rename from Config.toml rename to GlobalConf.toml index 38374af..276e300 100644 --- a/Config.toml +++ b/GlobalConf.toml @@ -1,5 +1,5 @@ Title = "SaraSortd Config" -Version = "4.0" +Version = "5.0" SafeMode = 1 SilentMode = 0 CheckInput = 5 @@ -22,7 +22,7 @@ Second = "[s]" VarCall = "%%" [DirectoryPaths] -RootDir = "Unset" +RootDir = "C:/Users/sar2711/OneDrive - Telemark fylkeskommune/Desktop/Testdir" InputDir = [ "%RootDir%/Input" ] OutputDir = [ "%RootDir%/Output" ] LogDir = "%RootDir%/.Logs" @@ -30,7 +30,8 @@ FailedDir = "%RootDir%/.Failed" [Names] LogFileName = "[y].[m].[d]" -DirConfName = ".@Config" +InDirConfName = ".@Config" +OutDirConfName = ".@Config" FileHistoryName = ".@History" [Log] diff --git a/InputDirConf.toml b/InputDirConf.toml new file mode 100644 index 0000000..58a9acc --- /dev/null +++ b/InputDirConf.toml @@ -0,0 +1,3 @@ +Title = "Unset" +Version = "5.0" +ParentDir = "Unset" diff --git a/DirConfig.toml b/OutputDirConf.toml similarity index 92% rename from DirConfig.toml rename to OutputDirConf.toml index 5ec450d..7a09f32 100644 --- a/DirConfig.toml +++ b/OutputDirConf.toml @@ -1,5 +1,5 @@ Title = "Unset" -Version = "4.0" +Version = "5.0" LastFile = "Unset" ParentDir = "Unset" ValidInputDirs = ["*"] diff --git a/SaraSortd.py b/SaraSortd.py index 435dda5..d4e1ebb 100644 --- a/SaraSortd.py +++ b/SaraSortd.py @@ -6,9 +6,9 @@ import shutil import time import toml -# Version 4.0 +# Version 5.0 -ConfPath = "./Config.toml" +ConfPath = "./GlobalConf.toml" Conf = None ConfVars = None @@ -222,18 +222,18 @@ def Dir(Path, Output = True, CopyConf = True): os.makedirs(Path, exist_ok=True) 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( - os.path.join(f"{Path}/{NewDirConf}") + os.path.join(f"{Path}/{NewOutDirConf}") ): - Clone("DirConfig.toml", Path, NewDirConf) + Clone("OutputDirConf.toml", Path, NewOutDirConf) UpdateConf( - f"{Path}/{Parse(String = ConfNames['DirConfName'], Path = ConfPath, Parent = ParentName)}.toml", + f"{Path}/{Parse(String = ConfNames['OutDirConfName'], Path = ConfPath, Parent = ParentName)}.toml", "ParentDir", ParentName, ) UpdateConf( - f"{Path}/{Parse(String = ConfNames['DirConfName'], Path = ConfPath, Parent = ParentName)}.toml", + f"{Path}/{Parse(String = ConfNames['OutDirConfName'], Path = ConfPath, Parent = ParentName)}.toml", "Title", f"{ParentName} Config", ) @@ -266,13 +266,13 @@ def DecideNewPath(FilePath): ParentName = os.path.basename(Output) - DirConfName = Parse(String = ConfNames["DirConfName"], Path = ConfPath, Parent = ParentName) - DirConfPath = f"{Output}/{DirConfName}.toml" + OutDirConfName = Parse(String = ConfNames["OutDirConfName"], Path = ConfPath, Parent = ParentName) + OutDirConfPath = f"{Output}/{OutDirConfName}.toml" - ValidInputDirs = GetConf("ValidInputDirs", DirConfPath) + ValidInputDirs = GetConf("ValidInputDirs", OutDirConfPath) 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}") LogWrite(TextOutput) @@ -282,12 +282,12 @@ def DecideNewPath(FilePath): if (InputDirValid): break - if not os.path.exists(DirConfPath) or not InputDirValid: + if not os.path.exists(OutDirConfPath) or not InputDirValid: continue OutputFiles = 0 - FileLimitConf = GetConf("FileLimit", DirConfPath) + FileLimitConf = GetConf("FileLimit", OutDirConfPath) if FileLimitConf > 0: for OutputFile in os.listdir(Output): @@ -299,7 +299,7 @@ def DecideNewPath(FilePath): if OutputFiles >= FileLimitConf: continue - FileConf = GetConf("Files", DirConfPath) + FileConf = GetConf("Files", OutDirConfPath) if not FileConf: continue @@ -320,13 +320,13 @@ def DecideNewPath(FilePath): if Match: 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)): continue if ConfVars["NextNum"] in File["NewFileName"]: - ConfData = toml.load(DirConfPath) + ConfData = toml.load(OutDirConfPath) NewNum = (int(File["NextNum"]) + 1) @@ -335,7 +335,7 @@ def DecideNewPath(FilePath): Item["NextNum"] = NewNum break - with open(DirConfPath, "w", encoding="utf-8") as ConfFile: + with open(OutDirConfPath, "w", encoding="utf-8") as ConfFile: toml.dump(ConfData, ConfFile) TextOutput = Parse(String = ConfLog["ValueSet"], VarCall = f"NextChar to {NewNum}") @@ -363,14 +363,14 @@ def DecideNewPath(FilePath): NewChar = "".join(Result) - ConfData = toml.load(DirConfPath) + ConfData = toml.load(OutDirConfPath) 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: + with open(OutDirConfPath, "w", encoding="utf-8") as ConfFile: toml.dump(ConfData, ConfFile) TextOutput = Parse(String = ConfLog["ValueSet"], VarCall = f"NextChar to {NewChar}") @@ -396,7 +396,7 @@ def Sort(FilePath): NewDirPath = os.path.dirname(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 else: @@ -404,7 +404,7 @@ def Sort(FilePath): try: 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}") LogWrite(TextOutput) @@ -437,8 +437,8 @@ def Init(): Output = Parse(String = Output, Parent = os.path.basename(os.path.dirname(Output))) Dir(Output) - DirConfPath = f"{Output}/{Parse(String = ConfNames["DirConfName"], Parent = os.path.basename(Output))}.toml" - ConfData = toml.load(DirConfPath) + OutDirConfPath = f"{Output}/{Parse(String = ConfNames["OutDirConfName"], Parent = os.path.basename(Output))}.toml" + ConfData = toml.load(OutDirConfPath) for Item in ConfData.get("Files", []): Character = re.escape(ConfVars["NextChar"]) @@ -448,7 +448,7 @@ def Init(): if Width > 0: 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) TextOutput = Parse(String = ConfLog["Start"], Path = ConfPath) @@ -462,7 +462,7 @@ def Init(): Speak(TextOutput) 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():