Merge pull request #43 from SRHTNIN/SarahTest

Sarah test
This commit is contained in:
sarah authored and GitHub committed 2026-04-20 20:00:19 +02:00
commit dd00cf0780
3 files changed
+58 -18

No files matched your search

+2
View File
@@ -103,6 +103,8 @@ LogFileName = "[y].[m].[d]._*" # Name for log files.
DirConfName = ".@Config" # Name for config files for directories. DirConfName = ".@Config" # Name for config files for directories.
FileHistoryName = ".@History" # Name for file history files. This keeps track of sorted files if an input and output are the same directory.
[Log] [Log]
All = "[h]:[n]:[s] | " # What to put at the start of all lines in Log file. All = "[h]:[n]:[s] | " # What to put at the start of all lines in Log file.
+4 -3
View File
@@ -1,7 +1,7 @@
Title = "SaraSortd Config" Title = "SaraSortd Config"
SafeMode = 1 SafeMode = 1
SilentMode = 0 SilentMode = 0
CheckInput = 10 CheckInput = 5
DotFiles = 0 DotFiles = 0
Logging = 1 Logging = 1
OverwriteDirConf = 0 OverwriteDirConf = 0
@@ -21,7 +21,7 @@ Second = "[s]"
VarCall = "%%" VarCall = "%%"
[DirectoryPaths] [DirectoryPaths]
RootDir = "Unset" RootDir = "/home/sarah/TestDir"
InputDir = [ "%RootDir%/Input" ] InputDir = [ "%RootDir%/Input" ]
OutputDir = [ "%RootDir%/Output" ] OutputDir = [ "%RootDir%/Output" ]
LogDir = "%RootDir%/.Logs" LogDir = "%RootDir%/.Logs"
@@ -30,12 +30,13 @@ FailedDir = "%RootDir%/.Failed"
[Names] [Names]
LogFileName = "[y].[m].[d]" LogFileName = "[y].[m].[d]"
DirConfName = ".@Config" DirConfName = ".@Config"
FileHistoryName = ".@History"
[Log] [Log]
All = "[h]:[n]:[s] | " All = "[h]:[n]:[s] | "
Start = "Started SaraSortd." Start = "Started SaraSortd."
NotStart = "Error: Failed to start SaraSortd." NotStart = "Error: Failed to start SaraSortd."
Stop = "\nStopped SaraSortd." Stop = "Stopped SaraSortd.\n"
MatchPattern = "Checking %%." MatchPattern = "Checking %%."
Sorted = "Sorted %%." Sorted = "Sorted %%."
NotSorted = "Error: Failed to sort %%. No valid output directory." NotSorted = "Error: Failed to sort %%. No valid output directory."
+52 -15
View File
@@ -166,11 +166,11 @@ def Parse(
ConfVars["OrgFileName"]: str(OrgFileName), ConfVars["OrgFileName"]: str(OrgFileName),
ConfVars["OrgFileType"]: str(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).rjust(2, "0"),
ConfVars["Day"]: str(Now.day), ConfVars["Day"]: str(Now.day).rjust(2, "0"),
ConfVars["Hour"]: str(Now.hour), ConfVars["Hour"]: str(Now.hour).rjust(2, "0"),
ConfVars["Minute"]: str(Now.minute), ConfVars["Minute"]: str(Now.minute).rjust(2, "0"),
ConfVars["Second"]: str(Now.second), ConfVars["Second"]: str(Now.second).rjust(2, "0"),
ConfVars["VarCall"]: str(VarCall), ConfVars["VarCall"]: str(VarCall),
} }
@@ -188,6 +188,23 @@ def Parse(
def Clone(Source, Destination, NewName, Delete = False): def Clone(Source, Destination, NewName, Delete = False):
if (os.path.dirname(Source) == Destination):
FileHistoryPath = f"{Destination}/{Parse(ConfNames["FileHistoryName"], Parent = os.path.basename(Destination))}.toml"
print("FileHistoryPath:",FileHistoryPath)
if not os.path.exists(FileHistoryPath):
with open(FileHistoryPath, "w", encoding = "utf-8") as HistoryFile:
toml.dump({"Title": f"{os.path.basename(Destination)} History", "History": []}, HistoryFile)
HistoryFileData = toml.load(FileHistoryPath)
if (NewName not in HistoryFileData["History"]):
HistoryFileData["History"].append(NewName)
with open(FileHistoryPath, "w", encoding = "utf-8") as HistoryFile:
toml.dump(HistoryFileData, HistoryFile)
os.rename(Source, os.path.join(Destination, NewName))
return
Dir(Destination, Output = False, CopyConf = False) Dir(Destination, Output = False, CopyConf = False)
shutil.copy2(Source, Destination) shutil.copy2(Source, Destination)
@@ -364,6 +381,16 @@ def DecideNewPath(FilePath):
def Sort(FilePath): def Sort(FilePath):
NewPath = DecideNewPath(FilePath) NewPath = DecideNewPath(FilePath)
if NewPath is None:
Dir(Parse(String = ConfDirs["FailedDir"]), Output = False, CopyConf = False)
NewName = os.path.basename(FilePath)
Clone(FilePath, Parse(String = ConfDirs["FailedDir"]), NewName, True)
TextOutput = Parse(String = ConfLog["NotSorted"], VarCall = FilePath)
LogWrite(TextOutput)
Speak(TextOutput)
return
NewDirPath = os.path.dirname(NewPath) NewDirPath = os.path.dirname(NewPath)
NewName = os.path.basename(NewPath) NewName = os.path.basename(NewPath)
@@ -373,16 +400,6 @@ def Sort(FilePath):
else: else:
Delete = False Delete = False
if NewPath is None:
Dir(Parse(String = ConfDirs["FailedDir"]), Output = False, CopyConf = False)
NewName = os.path.basename(FilePath)
Clone(FilePath, Parse(String = ConfDirs["FailedDir"]), NewName, Delete)
TextOutput = Parse(String = ConfLog["NotSorted"], VarCall = FilePath)
LogWrite(TextOutput)
Speak(TextOutput)
return
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['DirConfName'], Parent = os.path.basename(NewDirPath))}.toml", "LastFile", NewName)
@@ -450,11 +467,24 @@ def Main():
try: try:
while True: while True:
for Input in ConfDirs["InputDir"]: for Input in ConfDirs["InputDir"]:
RecurseDir = False
InputPath = Parse(Input) InputPath = Parse(Input)
if not os.path.exists(InputPath): if not os.path.exists(InputPath):
continue continue
for Output in ConfDirs["OutputDir"]:
OutputPath = Parse(Output)
if (OutputPath == InputPath):
RecurseDir = True
FileHistoryPath = f"{InputPath}/{Parse(ConfNames["FileHistoryName"], Parent = os.path.basename(InputPath))}.toml"
if not os.path.exists(FileHistoryPath):
with open(FileHistoryPath, "w", encoding = "utf-8") as HistoryFile:
toml.dump({"Title": f"{os.path.basename(InputPath)} History", "History": [] }, HistoryFile)
for FileName in os.listdir(InputPath): for FileName in os.listdir(InputPath):
FilePath = f"{InputPath}/{FileName}" FilePath = f"{InputPath}/{FileName}"
@@ -462,6 +492,13 @@ def Main():
FileName = os.path.basename(FilePath) FileName = os.path.basename(FilePath)
if FileName.startswith(".") and Conf["DotFiles"] == 0: if FileName.startswith(".") and Conf["DotFiles"] == 0:
continue continue
if RecurseDir:
HistoryFile = toml.load(FileHistoryPath)
if (Parse(FileName, Parent = os.path.basename(InputPath)) in HistoryFile["History"]):
continue
Sort(FilePath) Sort(FilePath)
time.sleep(Conf.get("CheckInput", 10)) time.sleep(Conf.get("CheckInput", 10))