From 2cc72b1730e5786fabe8fd95c2fa586a0137bccd Mon Sep 17 00:00:00 2001 From: Sarahtonin Date: Sun, 10 May 2026 21:42:21 +0200 Subject: [PATCH 1/2] Added unzipping function, but haven't tested it yet. --- GlobalConf.toml | 2 +- InputDirConf.toml | 2 +- OutputDirConf.toml | 3 ++- README.md | 10 ++++++---- SaraSortd.py | 15 ++++++++++++++- 5 files changed, 24 insertions(+), 8 deletions(-) diff --git a/GlobalConf.toml b/GlobalConf.toml index f4dfd59..b8106fd 100644 --- a/GlobalConf.toml +++ b/GlobalConf.toml @@ -1,5 +1,5 @@ Title = "SaraSortd Config" -Version = "6.3" +Version = "6.4" SafeMode = 1 SilentMode = 0 CheckInput = 5 diff --git a/InputDirConf.toml b/InputDirConf.toml index 5567027..62dde71 100644 --- a/InputDirConf.toml +++ b/InputDirConf.toml @@ -1,5 +1,5 @@ Title = "Unset" -Version = "6.3" +Version = "6.4" ParentDir = "Unset" SortDirs = 0 diff --git a/OutputDirConf.toml b/OutputDirConf.toml index 9354b09..81e9965 100644 --- a/OutputDirConf.toml +++ b/OutputDirConf.toml @@ -1,10 +1,11 @@ Title = "Unset" -Version = "6.3" +Version = "6.4" LastFile = "Unset" ParentDir = "Unset" ValidInputDirs = ["*"] FileLimit = 0 DeleteOrg = 1 +Unzip = 1 [[Files]] Pattern = "*" diff --git a/README.md b/README.md index b395749..ff85bd7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ SaraSortd: a file and directory sorting daemon built with python. -(Version = "6.3") +(Version = "6.4") It's made by Sarah, hence the name. :3 @@ -58,7 +58,7 @@ Here's a step-by-step tutorial (in case you don't want to watch the video). ``` Title = "SaraSortd Config" # NOTE: Do not change the title. This is so that the program knows which config file is which. -Version = "6.3" # Just the version number for the config file. +Version = "6.4" # Just the version number for the config file. SafeMode = 1 # If SaraSortd should stop if an error with the config appears. 1 is stop, 0 is continue. @@ -158,7 +158,7 @@ The output directory config references the SaraSortd config (GlobalConf.toml). T ``` Title = "Unset" # NOTE: Do not change the title. This is so that the program knows which config file is which. -Version = "6.3" # The version number of the config. +Version = "6.4" # The version number of the config. LastFile = "Unset" # The last file that was sorted to this directory. It gets automatically updated whenever a file gets sorted to this directory. @@ -170,6 +170,8 @@ FileLimit = 0 # The max limit of files a directory can have. If this is 0, then DeleteOrg = 1 # If SaraSortd should delete the original file or not. If this is 1, then sorted files will be 'moved' to an output directory. If not, they will be 'copied' to an output directory. +Unzip = 1 # If this output directory should unzip zip files that get sent here. + [[Files]] # The double brackets means that you can add multiple types of files to be sorted here. Just copy [[Files]] and all the parameters under it, and paste it under or over this section, then you may change the values of the new parameters. E.G: # [[Files]] @@ -209,7 +211,7 @@ Overwrite = 1 # Whether this specific file type can be overwritten by others of ``` Title = "Unset" # NOTE: Do not change the title. This is so that the program knows which config file is which. -Version = "6.3" +Version = "6.4" ParentDir = "Unset" # The name of this directory. It gets automatically updated when this config gets copied to an output directory. diff --git a/SaraSortd.py b/SaraSortd.py index 8251f42..efadf5c 100644 --- a/SaraSortd.py +++ b/SaraSortd.py @@ -6,7 +6,7 @@ import shutil import time import toml -# Version = "6.3" +# Version = "6.4" ConfPath = "./GlobalConf.toml" @@ -307,6 +307,19 @@ def DecideNewPath(FilePath): FileLimitConf = GetConf("FileLimit", OutDirConfPath) + if GetConf("Unzip", OutDirConfPath) == 1: + ZipTypes = ["zip", "tar.gz", "bz2"] + for OutputFile in os.listdir(Output): + if OutputFile.startswith("."): + continue + + for ZipType in ZipTypes: + if OutputFile.lower().endswith(ZipType): + shutil.unpack_archive(f"{Output}/{OutputFile}", Output, ZipType) + TextOutput = Parse(String = ConfLog["Unzipping"], VarCall = f"{Output}/{OutputFile}") + LogWrite(TextOutput) + Speak(TextOutput) + if FileLimitConf > 0: for OutputFile in os.listdir(Output): if OutputFile.startswith("."): From 19ceec218f04eddd2feb6e16ff32f747148252c6 Mon Sep 17 00:00:00 2001 From: Sarahtonin Date: Sun, 10 May 2026 23:33:44 +0200 Subject: [PATCH 2/2] Renamed CheckInput tot SortTimer, added Unzip parameter with a list, and fixed sorting directories to not need admin (at least on linux). --- GlobalConf.toml | 4 ++-- InputDirConf.toml | 2 +- OutputDirConf.toml | 4 ++-- README.md | 15 ++++++++------- SaraSortd.py | 43 +++++++++++++++++++++++++++---------------- 5 files changed, 40 insertions(+), 28 deletions(-) diff --git a/GlobalConf.toml b/GlobalConf.toml index b8106fd..cf1a3bd 100644 --- a/GlobalConf.toml +++ b/GlobalConf.toml @@ -1,8 +1,8 @@ Title = "SaraSortd Config" -Version = "6.4" +Version = "7.0" SafeMode = 1 SilentMode = 0 -CheckInput = 5 +SortTimer = 1 DotFiles = 0 Logging = 1 OverwriteDirConf = 0 diff --git a/InputDirConf.toml b/InputDirConf.toml index 62dde71..495fb16 100644 --- a/InputDirConf.toml +++ b/InputDirConf.toml @@ -1,5 +1,5 @@ Title = "Unset" -Version = "6.4" +Version = "7.0" ParentDir = "Unset" SortDirs = 0 diff --git a/OutputDirConf.toml b/OutputDirConf.toml index 81e9965..ac50468 100644 --- a/OutputDirConf.toml +++ b/OutputDirConf.toml @@ -1,11 +1,11 @@ Title = "Unset" -Version = "6.4" +Version = "7.0" LastFile = "Unset" ParentDir = "Unset" ValidInputDirs = ["*"] FileLimit = 0 DeleteOrg = 1 -Unzip = 1 +Unzip = [] [[Files]] Pattern = "*" diff --git a/README.md b/README.md index ff85bd7..4d6cc00 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ SaraSortd: a file and directory sorting daemon built with python. -(Version = "6.4") +(Version = "7.0") It's made by Sarah, hence the name. :3 @@ -58,13 +58,13 @@ Here's a step-by-step tutorial (in case you don't want to watch the video). ``` Title = "SaraSortd Config" # NOTE: Do not change the title. This is so that the program knows which config file is which. -Version = "6.4" # Just the version number for the config file. +Version = "7.0" # Just the version number for the config file. SafeMode = 1 # If SaraSortd should stop if an error with the config appears. 1 is stop, 0 is continue. SilentMode = 0 # If SaraSortd should write things it does, to the terminal. -CheckInput = 3 # How many seconds it takes for SaraSortd to check input directories for new files to sort. +SortTimer = 3 # How many seconds it takes for SaraSortd to check input directories for new files to sort. DotFiles = 0 # If SaraSortd should sort files that begin with ".". This is mainly for linux users, since hidden files always have "." in front of them. @@ -158,7 +158,7 @@ The output directory config references the SaraSortd config (GlobalConf.toml). T ``` Title = "Unset" # NOTE: Do not change the title. This is so that the program knows which config file is which. -Version = "6.4" # The version number of the config. +Version = "7.0" # The version number of the config. LastFile = "Unset" # The last file that was sorted to this directory. It gets automatically updated whenever a file gets sorted to this directory. @@ -170,7 +170,8 @@ FileLimit = 0 # The max limit of files a directory can have. If this is 0, then DeleteOrg = 1 # If SaraSortd should delete the original file or not. If this is 1, then sorted files will be 'moved' to an output directory. If not, they will be 'copied' to an output directory. -Unzip = 1 # If this output directory should unzip zip files that get sent here. +Unzip = [] # What type of files this output directory should try to unzip. E.G: +# Unzip = ["zip", "tar.gz"] would unzip .zip files and .tar files. This pairs insanely well with input directories' config's "SortDirs" parameter. [[Files]] # The double brackets means that you can add multiple types of files to be sorted here. Just copy [[Files]] and all the parameters under it, and paste it under or over this section, then you may change the values of the new parameters. E.G: @@ -211,11 +212,11 @@ Overwrite = 1 # Whether this specific file type can be overwritten by others of ``` Title = "Unset" # NOTE: Do not change the title. This is so that the program knows which config file is which. -Version = "6.4" +Version = "7.0" ParentDir = "Unset" # The name of this directory. It gets automatically updated when this config gets copied to an output directory. -SortDirs = 0 # If the input directory should be allowed to sort directories within it. (Currently needs admin privileges to delete the original directory after sorting it). +SortDirs = 0 # If the input directory should be allowed to sort directories within it. Automatically uses .zip to move directories. [[Files]] # The double brackets means that you can add multiple types of files to be sorted here. Just copy [[Files]] and all the parameters under it, and paste it under or over this section, then you may change the values of the new parameters. diff --git a/SaraSortd.py b/SaraSortd.py index efadf5c..d30013d 100644 --- a/SaraSortd.py +++ b/SaraSortd.py @@ -6,7 +6,7 @@ import shutil import time import toml -# Version = "6.4" +# Version = "7.0" ConfPath = "./GlobalConf.toml" @@ -307,19 +307,6 @@ def DecideNewPath(FilePath): FileLimitConf = GetConf("FileLimit", OutDirConfPath) - if GetConf("Unzip", OutDirConfPath) == 1: - ZipTypes = ["zip", "tar.gz", "bz2"] - for OutputFile in os.listdir(Output): - if OutputFile.startswith("."): - continue - - for ZipType in ZipTypes: - if OutputFile.lower().endswith(ZipType): - shutil.unpack_archive(f"{Output}/{OutputFile}", Output, ZipType) - TextOutput = Parse(String = ConfLog["Unzipping"], VarCall = f"{Output}/{OutputFile}") - LogWrite(TextOutput) - Speak(TextOutput) - if FileLimitConf > 0: for OutputFile in os.listdir(Output): if OutputFile.startswith("."): @@ -513,6 +500,30 @@ def Main(): for Output in ConfDirs["OutputDir"]: OutputPath = Parse(Output) + OutDirConfPath = f"{OutputPath}/{Parse(ConfNames["OutDirConfName"], Parent = os.path.basename(OutputPath))}.toml" + + if len(GetConf("Unzip", OutDirConfPath)) >= 1: + ZipTypes = GetConf("Unzip", OutDirConfPath) + for OutputFile in os.listdir(OutputPath): + if OutputFile.startswith("."): + continue + + for ZipType in ZipTypes: + print(ZipType) + if (OutputFile.lower()).endswith((ZipType).lower()): + shutil.unpack_archive(f"{OutputPath}/{OutputFile}", OutputPath) + TextOutput = Parse(String = ConfLog["Unzipping"], VarCall = f"{OutputPath}/{OutputFile}") + LogWrite(TextOutput) + Speak(TextOutput) + + try: + os.remove(f"{OutputPath}/{OutputFile}") + + except PermissionError: + TextOutput = Parse(String = ConfLog["NoPermission"], VarCall = f"remove {OutputPath}/{OutputFile}") + LogWrite(TextOutput) + Speak(TextOutput) + continue if (OutputPath == InputPath): RecurseDir = True @@ -550,7 +561,7 @@ def Main(): shutil.make_archive(FilePath, "zip", FilePath) try: - os.rmdir(FilePath) + shutil.rmtree(FilePath, ignore_errors=True) except PermissionError: TextOutput = Parse(String = ConfLog["NoPermission"], VarCall = f"remove directory {InputPath}/{FileName}") @@ -568,7 +579,7 @@ def Main(): Sort(FilePath) - time.sleep(Conf.get("CheckInput", 10)) + time.sleep(Conf.get("SortTimer", 10)) except KeyboardInterrupt: TextOutput = GetConf("Stop", ConfPath)