9 Commits
Author SHA1 Message Date
sarah dd00cf0780 Merge pull request #43 from SRHTNIN/SarahTest
Sarah test
2026-04-20 20:00:19 +02:00
sarah 51c557d228 Added FileHistoryName to config, allowing an input and output dir to be
the same and stopping recursion by saving the new file name. Also fixed
hour, minute, second, and so to be at least 2 wide (19:2:3 => 19:02:03)
2026-04-20 19:58:29 +02:00
sarah e91ce510fc Merge pull request #41 from SRHTNIN/main
Main=>SarahTest
2026-04-20 07:56:04 +02:00
sarah d68550d0a9 Added delete parameter to dirconf. 2026-04-14 07:20:38 +02:00
sarah 9fbdec9120 Update README.md 2026-04-13 06:56:15 +02:00
sarah 0b54a729ff Update README.md 2026-04-13 06:55:40 +02:00
sarah a3bc726086 Update README.md 2026-04-13 05:49:37 +02:00
sarah 739f91a5bf Update README.md 2026-04-13 05:39:12 +02:00
sarah fc6f9bd399 Update README.md 2026-04-10 22:10:41 +02:00
4 changed files with 104 additions and 26 deletions

No files matched your search

+43 -1
View File
@@ -1,11 +1,48 @@
# SaraSortd # SaraSortd
A python daemon that can automatically sort your files to your liking without using AI. A python daemon that can automatically sort your files to your liking without using AI.
It's made by Sarah, hence the name. :3 It's made by Sarah, hence the name. :3
The versioning for SaraSortd is like so: the first number going up means that your
previous config files won't work anymore with the new SaraSortd.py.
The second number going up means that something has been changed, but you can still
use your old config files with SaraSortd.py.
## Usage
SaraSortd is for people who don't want to manually sort files, people who want to organise files, and people who want an automatic naming standard for their files.
Example use-cases:
- Sorting log files from multiple programs into one directory.
- Sorting downloaded github repositories to a directory for your IDE.
- Regularly cloning important files into a backup directory.
## Dependencies ## Dependencies
python
toml: Use ```pip install toml``` to install toml. toml: Use ```pip install toml``` to install toml.
## Installation
Here's an [installation video.](https://youtu.be/ZMIaOhZA0kE).
Here's a step-by-step tutorial (in case you don't want to watch the video).
1. Install ZIP-file.
2. Unzip ZIP-file wherever you want the program to live.
3. Navigate to the new SaraSortd directory in your terminal.
4. Edit your config files to your liking.
5. Run ```python SaraSortd.py``` to run the program. (This will make new directories for you.)
6. Edit your output directories' configs.
## Config explanation ## Config explanation
### SaraSortd Config (Config.toml) ### SaraSortd Config (Config.toml)
@@ -66,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.
@@ -91,6 +130,7 @@ Unset = "Error: %% is not set." # When a value isn't set.
# %% here is just the parameter who's value was either "Unset" or None. E.G: "RootDir". # %% here is just the parameter who's value was either "Unset" or None. E.G: "RootDir".
``` ```
### Output Directory Config (DirConfig.toml) ### Output Directory Config (DirConfig.toml)
The output directory config references the SaraSortd config (Config.toml). This means that you can, for example, use the character assigned to "NextNum" in Config.toml in this config (DirConfig.toml). This applies to all Variables in the SaraSortd config (Config.toml). The output directory config references the SaraSortd config (Config.toml). This means that you can, for example, use the character assigned to "NextNum" in Config.toml in this config (DirConfig.toml). This applies to all Variables in the SaraSortd config (Config.toml).
@@ -104,7 +144,9 @@ ParentDir = "Unset" # The name of this directory. It gets automatically updated
ValidInputDirs = ["*"] # Directories that are valid for sorting. Basically, if a file is from one of these directories, they can be sorted here. * is a wildcard; ? is a one-character wilcard. E.G: if "ValidInputDirs = ["/TestDir/*"]" any file from any directory in "/TestDir" will be allowed to be sorted here. ValidInputDirs = ["*"] # Directories that are valid for sorting. Basically, if a file is from one of these directories, they can be sorted here. * is a wildcard; ? is a one-character wilcard. E.G: if "ValidInputDirs = ["/TestDir/*"]" any file from any directory in "/TestDir" will be allowed to be sorted here.
FileLimit = 0 FileLimit = 0 # The max limit of files a directory can have. If this is 0, then there's no limit.
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.
[[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]] # 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:
+4 -3
View File
@@ -1,7 +1,7 @@
Title = "SaraSortd Config" Title = "SaraSortd Config"
SafeMode = 1 SafeMode = 1
SilentMode = 0 SilentMode = 0
CheckInput = 3 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."
+1
View File
@@ -3,6 +3,7 @@ LastFile = "Unset"
ParentDir = "Unset" ParentDir = "Unset"
ValidInputDirs = ["*"] ValidInputDirs = ["*"]
FileLimit = 0 FileLimit = 0
DeleteOrg = 1
[[Files]] [[Files]]
Pattern = "*" Pattern = "*"
+56 -22
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)
@@ -266,7 +283,6 @@ def DecideNewPath(FilePath):
if not os.path.exists(DirConfPath) or not InputDirValid: if not os.path.exists(DirConfPath) or not InputDirValid:
continue continue
OutputFiles = 0 OutputFiles = 0
FileLimitConf = GetConf("FileLimit", DirConfPath) FileLimitConf = GetConf("FileLimit", DirConfPath)
@@ -378,24 +394,24 @@ def Sort(FilePath):
NewDirPath = os.path.dirname(NewPath) NewDirPath = os.path.dirname(NewPath)
NewName = os.path.basename(NewPath) NewName = os.path.basename(NewPath)
try: if (GetConf("DeleteOrg", f"{NewDirPath}/{Parse(String = ConfNames['DirConfName'], Parent = (os.path.basename(NewDirPath)))}.toml") == 1):
Clone(FilePath, NewDirPath, NewName, True) Delete = True
UpdateConf(
f"{NewDirPath}/{Parse(String = ConfNames['DirConfName'], Parent = os.path.basename(NewDirPath))}.toml",
"LastFile",
NewName,
)
TextOutput = Parse( else:
String = ConfLog["Sorted"], VarCall = f"{FilePath} to {NewDirPath}/{NewName}" Delete = False
)
try:
Clone(FilePath, NewDirPath, NewName, Delete)
UpdateConf(f"{NewDirPath}/{Parse(String = ConfNames['DirConfName'], Parent = os.path.basename(NewDirPath))}.toml", "LastFile", NewName)
TextOutput = Parse(String = ConfLog["Sorted"], VarCall = f"{FilePath} to {NewDirPath}/{NewName}")
LogWrite(TextOutput) LogWrite(TextOutput)
Speak(TextOutput) Speak(TextOutput)
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(NewPath) NewName = os.path.basename(NewPath)
Clone(FilePath, Parse(String = ConfDirs["FailedDir"]), NewName, True) Clone(FilePath, Parse(String = ConfDirs["FailedDir"]), NewName, Delete)
TextOutput = Parse(String = ConfLog["NotSorted"], VarCall = FilePath) TextOutput = Parse(String = ConfLog["NotSorted"], VarCall = FilePath)
LogWrite(TextOutput) LogWrite(TextOutput)
@@ -419,7 +435,7 @@ 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"{os.path.join(Output, Parse(String = ConfNames["DirConfName"], Parent = os.path.basename(Output)))}.toml" DirConfPath = f"{Output}/{Parse(String = ConfNames["DirConfName"], Parent = os.path.basename(Output))}.toml"
ConfData = toml.load(DirConfPath) ConfData = toml.load(DirConfPath)
for Item in ConfData.get("Files", []): for Item in ConfData.get("Files", []):
@@ -444,27 +460,45 @@ def Init():
Speak(TextOutput) Speak(TextOutput)
else: else:
print( print("NO CONFIG FOUND! Make sure the 'Config.toml' is in the same directory as 'SaraSortd.py'")
"NO CONFIG FOUND! Make sure the 'Config.toml' is in the same directory as 'SaraSortd.py'"
)
def Main(): 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 = os.path.join(InputPath, FileName) FilePath = f"{InputPath}/{FileName}"
if os.path.isfile(FilePath): if os.path.isfile(FilePath):
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))