mirror of
https://git.srhtnin.garden/sarah/SaraSortd.git
synced 2026-10-13 18:38:11 +02:00
6 files changed
+185
-116
No files matched your search
File renamed without changes.
@@ -0,0 +1,131 @@
|
||||
# SaraSortd
|
||||
A python daemon that can automatically sort your files to your liking without using AI.
|
||||
|
||||
It's made by Sarah, hence the name. :3
|
||||
|
||||
## Dependencies
|
||||
toml: Use ```pip install toml``` to install toml.
|
||||
|
||||
## Config explanation
|
||||
|
||||
### SaraSortd Config (Config.toml)
|
||||
|
||||
```
|
||||
Title = "SaraSortd Config" # NOTE: Do not change the title.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
Logging = 1 # If SaraSortd's logging system should be active. If this is 0, nothing will be logged into files.
|
||||
|
||||
OverwriteDirConf = 0 # If SaraSortd should overwrite directory configs with DirConfig.toml.
|
||||
|
||||
[Variables] # Only use these in config files, not the actual file names themselves.
|
||||
NextNum = "*" # The next available number. If 1 already exists, 2 will be used. Starts at 1.
|
||||
|
||||
NextChar = "&" # The next available character. If A already exists, B will be used.
|
||||
|
||||
Parent = "@" # The name of the parent directory.
|
||||
|
||||
OrgFileName = "\~" # The original name of the sorted file. If "blahblah.txt" gets sorted, "~" would be equal to "blahblah".
|
||||
|
||||
OrgFileType = "^" # The original file type of the sorted file. If "example.png" gets sorted, "^" would be equal to ".png".
|
||||
|
||||
Year = "[y]" # The current year, E.G. "2026".
|
||||
|
||||
Month = "[m]" # The date of the current month, E.G. "03".
|
||||
|
||||
Day = "[d]" # The date of the current day, E.G. "27".
|
||||
|
||||
Hour = "[h]" # The current hour, E.G. "12".
|
||||
|
||||
Minute = "[n]" # The current minute, E.G. "44".
|
||||
|
||||
Second = "[s]" # The current second, E.G. "11".
|
||||
|
||||
VarCall = "%%" # The characters used at the start and end of variable calls. The first character is to the left; second is to the right. NOTE: If any parameters in the config uses just "%%", it gets a variable from the program itself, not from the config.
|
||||
|
||||
[DirectoryPaths]
|
||||
RootDir = "Unset" # A variable directory. This doesn't NEED to exist for the program to work. It's more of a shorthand for other paths to use! You could add more of these. E.G: Add ImageDir = "%RootDir%/Images", then you could set OutputDir to be "%ImageDir%".
|
||||
|
||||
InputDir = ["%RootDir%"] # If files get put here, they'll be sorted. This is a list, so you can add multiple. E.G: ["%RootDir%", "%RootDir%/input"]
|
||||
|
||||
OutputDir = ["%RootDir%/Output"] # Where sorted files go. This is a list, so you can add multiple. E.G: ["%RootDir%/Output", "%RootDir%/Output2"]. The output directories have separate config files.
|
||||
|
||||
LogDir = "%RootDir%/.Logs" # Where log files from SaraSortd go.
|
||||
|
||||
FailedDir ="%RootDir%/.Failed" # For files that failed to be sorted.
|
||||
|
||||
[Names]
|
||||
LogFileName = "[y].[m].[d]._*" # Name for log files.
|
||||
|
||||
DirConfName = ".@Config" # Name for config files for directories.
|
||||
|
||||
[Log]
|
||||
All = "[h]:[n]:[s] | " # What to put at the start of all lines in Log file.
|
||||
|
||||
Start = "Started: SaraSortd" # When SaraSortd starts.
|
||||
|
||||
NotStart = "Error: Failed to start SaraSortd." # When SaraSortd fails to start for some reason.
|
||||
|
||||
Stop = "\nStopped SaraSortd." # When SaraSortd stops for whatever reason. Usually when you interrupt it in the terminal you ran it in.
|
||||
|
||||
MatchPattern = "Checking %%." # When a file that's trying to be sorted gets checked against a pattern.
|
||||
# %% here is the file against the pattern. E.G: "picture.png against *.jpg"
|
||||
|
||||
Sorted = "Sorted: %%." # When a file gets sorted and where.
|
||||
# %% here is the oldfile to the newfile, E.G: "picture.png to SortedPicture.png".
|
||||
|
||||
NotSorted = "Error: Failed to sort %%. No valid output directory." # When a file from an input directory fails to be sorted to an output directory.
|
||||
# %% here is the path of the file. E.G: "/home/janedoe/picture.png".
|
||||
|
||||
ValueSet = "Set: %%." # When a value in a config is set.
|
||||
# %% here is the parameter and what it got set to. E.G: "Title to TestDir Config File".
|
||||
|
||||
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".
|
||||
```
|
||||
|
||||
### 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).
|
||||
|
||||
```
|
||||
Title = "Unset" # The title of the config. This currently does nothing for SaraSortd, so it can be anything. It gets automatically updated when DirConfig.toml gets copied to an output directory.
|
||||
|
||||
LastFile = "Unset" # The last file that was sorted to this directory. It gets automatically updated whenever a file gets sorted to this directory.
|
||||
|
||||
ParentDir = "Unset" # The name of this directory. It gets automatically updated when DirConfig.toml gets 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]]
|
||||
# Pattern = "*.png"
|
||||
# NewFileName = "GoodImage^"
|
||||
# NextNum = 1
|
||||
# NextChar = "A"
|
||||
# CaseSensitive = 0
|
||||
# [[Files]]
|
||||
# Pattern = "*.jpg"
|
||||
# NewFileName = "BetterImage^"
|
||||
# NextNum = 1
|
||||
# NextChar = "A"
|
||||
# CaseSensitive = 0
|
||||
|
||||
# Will sort .png files to this directory and rename them to "GoodImage.png", but also sort .jpg files into this directory yet rename those to "BetterImage.jpg".
|
||||
|
||||
Pattern = "*" # A pattern used to sort files to this directory. * is a wildcard; ? is a one-character wildcard. E.G: if Pattern is "*.png", all files ending with .png will end up here.
|
||||
|
||||
NewFileName = "~^" # A pattern for the new names of the files that get sorted to this directory from matching this "Pattern".
|
||||
|
||||
NextNum = 1 # Used to keep track of the next available number for file names. It gets automatically incremented when NextNum is used in NewFileName, and a file gets sorted to this directory and renamed.
|
||||
|
||||
NextChar = "A" # Used to keep track of the next available letter for file names. It gets automatically incremented (E.G: A into B) when NextChar is used in NewFileName, and a file gets sorted to this directory and renamed.
|
||||
|
||||
CaseSensitive = 0 # Whether this "Pattern" is case-sensitive or not. 1 is yes, 0 is no. E.G: if CaseSensitive = 1 and this "Pattern" is "*.PNG", a file named "picture.png" won't get sorted to this directory. if CaseSensitive = 0 and this "Pattern" is "*.PNG", a file named "picture.png" *will* get sorted to this directory.
|
||||
```
|
||||
+5
-2
@@ -2,7 +2,9 @@ Title = "SaraSortd Config"
|
||||
SafeMode = 1
|
||||
SilentMode = 0
|
||||
CheckInput = 3
|
||||
DotFiles = 1
|
||||
DotFiles = 0
|
||||
Logging = 1
|
||||
OverwriteDirConf = 0
|
||||
|
||||
[Variables]
|
||||
NextNum = "!"
|
||||
@@ -20,7 +22,7 @@ VarCall = "%%"
|
||||
|
||||
[DirectoryPaths]
|
||||
RootDir = "Unset"
|
||||
InputDir = [ "%RootDir%"]
|
||||
InputDir = [ "%Pic%/Input"]
|
||||
OutputDir = [ "%RootDir%/Output"]
|
||||
LogDir = "%RootDir%/.Logs"
|
||||
FailedDir = "%RootDir%/.Failed"
|
||||
@@ -33,6 +35,7 @@ DirConfName = ".@Config"
|
||||
All = "[h]:[n]:[s] | "
|
||||
Start = "Started SaraSortd."
|
||||
NotStart = "Error: Failed to start SaraSortd."
|
||||
Stop = "\nStopped SaraSortd."
|
||||
MatchPattern = "Checking %%."
|
||||
Sorted = "Sorted %%."
|
||||
NotSorted = "Error: Failed to sort %%. No valid output directory."
|
||||
|
||||
+7
-5
@@ -1,8 +1,10 @@
|
||||
Title = "Unset"
|
||||
|
||||
Files = [
|
||||
{Pattern = "*", NewFileName = "~^", NextNum = 1, NextChar = "A"},
|
||||
]
|
||||
|
||||
LastFile = "Unset"
|
||||
ParentDir = "Unset"
|
||||
|
||||
[[Files]]
|
||||
Pattern = "*"
|
||||
NewFileName = "~^"
|
||||
NextNum = 1
|
||||
NextChar = "A"
|
||||
CaseSensitive = 0
|
||||
@@ -1,82 +0,0 @@
|
||||
# SaraSortd
|
||||
A python daemon that can automatically sort your files to your liking without using AI.
|
||||
|
||||
It's made by Sarah, hence the name. :3
|
||||
|
||||
## Dependencies
|
||||
toml: Use ```pip install toml``` to install toml.
|
||||
|
||||
## Config explanation
|
||||
|
||||
### SaraSortd Config (Config.toml)
|
||||
|
||||
```
|
||||
Title = "SaraSortd Config" # NOTE: Do not change the title.
|
||||
|
||||
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 stuff to the terminal as well.
|
||||
|
||||
CheckInput = 10 # How many seconds it takes for SaraSortd to check input directories for new files to sort.
|
||||
|
||||
[Variables] # Only use these in config files, not the actual file names themselves.
|
||||
NextNum = "*" # The next available number. If 1 already exists, 2 will be used. Starts at 1.
|
||||
NextChar = "&" # The next available character. If A already exists, B will be used.
|
||||
|
||||
Parent = "@" # The name of the parent directory.
|
||||
|
||||
OrgFileName = "\~" # The original name of the sorted file. If "blahblah.txt" gets sorted, "~" would be equal to "blahblah".
|
||||
OrgFileType = "^" # The original file type of the sorted file. If "example.png" gets sorted, "^" would be equal to ".png".
|
||||
|
||||
Year = "[y]" # The current year, E.G. "2026".
|
||||
Month = "[m]" # The date of the current month, E.G. "03".
|
||||
Day = "[d]" # The date of the current day, E.G. "27".
|
||||
|
||||
Hour = "[h]" # The current hour, E.G. "12".
|
||||
Minute = "[n]" # The current minute, E.G. "44".
|
||||
Second = "[s]" # The current second, E.G. "11".
|
||||
|
||||
VarCall = "%%" # The characters used at the start and end of variable calls. The first character is to the left; second is to the right. NOTE: If any parameters in the config uses just "%%", it gets a variable from the program itself, not from the config.
|
||||
|
||||
[DirectoryPaths]
|
||||
RootDir = "/home/sarah/TESTDIR" # Parent directory. Directory where all SaraSortd directories live.
|
||||
InputDir = ["%RootDir%"] # If files get put here, they'll be sorted.
|
||||
OutputDir = ["%RootDir%/Output"] # Where sortted files go.
|
||||
LogDir = "%RootDir%/.Logs" # Where log files from SaraSortd go.
|
||||
FailedDir ="%RootDir%/.Failed" # For files that failed to be sorted.
|
||||
|
||||
[Names]
|
||||
LogFileName = "[y].[m].[d]._*" # Name of log files.
|
||||
DirConfName = ".@Config" # Name of config files for directories.
|
||||
|
||||
[Log]
|
||||
All = "[h]:[n]:[s] | " # What to put at the start of all lines in Log file.
|
||||
|
||||
Start = "Started: SaraSortd" # When SaraSortd starts.
|
||||
NotStart = "Error: Failed to start SaraSortd." # When SaraSortd fails to start for some reason.
|
||||
|
||||
Sorted = "Sorted: %% to %%." # When a file gets sorted.
|
||||
ValueSet = "Set: %% to be %% in %%." # When a value in a config is set.
|
||||
|
||||
WrongType = "Error: %% is not a %%." # When a parameter in the config is of the wrong type. E.G. setting a text parameter to be a list.
|
||||
Unset = "Error: %% is not set." # When a parameter in the config is not set. %% is the parameter that wasn't set.
|
||||
```
|
||||
|
||||
### Directory Config (DirConfig.toml)
|
||||
|
||||
```
|
||||
Title = "Unset" # NOTE: Do not change the title.
|
||||
|
||||
Files = [
|
||||
{Pattern = "?", NewFileName = "~^", NextNum = 1, NextChar = "A"},
|
||||
]
|
||||
# Pattern: the pattern used to sort files here. * is a wildcard, ? is a one-character wildcard.
|
||||
# E.G: if Pattern is "*.png", all files ending with .png will end up here.
|
||||
|
||||
# NewFileName: the pattern for the new names of the files that get sorted here.
|
||||
|
||||
# NextNum and Nextchar: used to keep track of the next
|
||||
# available number and character for file names.
|
||||
|
||||
LastFile = "Unset" # The last modified file in the directory.
|
||||
ParentDir = "Unset" # The name of the parent directory.
|
||||
```
|
||||
+42
-27
@@ -194,10 +194,11 @@ def Dir(Path, Output = True, CopyConf = True):
|
||||
os.makedirs(Path, exist_ok=True)
|
||||
|
||||
if (CopyConf):
|
||||
Clone("DirConfig.toml", Path, f"{Parse(String = ConfNames["DirConfName"], Path = ConfPath, Parent = ParentName)}.toml")
|
||||
|
||||
UpdateConf(f"{Path}/{Parse(String = ConfNames["DirConfName"], Path = ConfPath, Parent = ParentName)}.toml", "ParentDir", ParentName)
|
||||
UpdateConf(f"{Path}/{Parse(String = ConfNames["DirConfName"], Path = ConfPath, Parent = ParentName)}.toml", "Title", f"{ParentName} Config")
|
||||
NewDirConf = f"{Parse(String = ConfNames["DirConfName"], Path = ConfPath, Parent = ParentName)}.toml"
|
||||
if (Conf["OverwriteDirConf"] == 1 or not os.path.exists(os.path.join(f"{Path}/{NewDirConf}"))):
|
||||
Clone("DirConfig.toml", Path, NewDirConf)
|
||||
UpdateConf(f"{Path}/{Parse(String = ConfNames["DirConfName"], Path = ConfPath, Parent = ParentName)}.toml", "ParentDir", ParentName)
|
||||
UpdateConf(f"{Path}/{Parse(String = ConfNames["DirConfName"], Path = ConfPath, Parent = ParentName)}.toml", "Title", f"{ParentName} Config")
|
||||
|
||||
if (Output):
|
||||
ParsedPath = Parse(String = Path)
|
||||
@@ -207,12 +208,13 @@ def Dir(Path, Output = True, CopyConf = True):
|
||||
|
||||
|
||||
def LogWrite(Text):
|
||||
if (ConfDirs["LogDir"] != None and ConfNames != "Unset"):
|
||||
if (ConfNames["LogFileName"] != None and ConfNames["LogFileName"] != "Unset"):
|
||||
Dir(Parse(String = ConfDirs["LogDir"], Path = ConfPath), Output = False, CopyConf = False)
|
||||
LogFile = f"{Parse(String = ConfDirs["LogDir"], Path = ConfPath)}/{Parse(String = ConfNames["LogFileName"], Path = ConfPath)}.log"
|
||||
with open(LogFile, "a", encoding="utf-8", buffering=1) as File:
|
||||
File.write(f"{Parse(String = ConfLog["All"], Path = ConfPath)}{Text}\n")
|
||||
if (GetConf("Logging", ConfPath) == 1):
|
||||
if (ConfDirs["LogDir"] != None and ConfNames != "Unset"):
|
||||
if (ConfNames["LogFileName"] != None and ConfNames["LogFileName"] != "Unset"):
|
||||
Dir(Parse(String = ConfDirs["LogDir"], Path = ConfPath), Output = False, CopyConf = False)
|
||||
LogFile = f"{Parse(String = ConfDirs["LogDir"], Path = ConfPath)}/{Parse(String = ConfNames["LogFileName"], Path = ConfPath)}.log"
|
||||
with open(LogFile, "a", encoding="utf-8", buffering=1) as File:
|
||||
File.write(f"{Parse(String = ConfLog["All"], Path = ConfPath)}{Text}\n")
|
||||
|
||||
|
||||
def DecideNewPath(FilePath):
|
||||
@@ -241,7 +243,13 @@ def DecideNewPath(FilePath):
|
||||
LogWrite(TextOutput)
|
||||
Speak(TextOutput)
|
||||
|
||||
if fnmatch.fnmatch(UnsortedFile, Pattern):
|
||||
if (File["CaseSensitive"] == 1):
|
||||
Match = fnmatch.fnmatchcase(UnsortedFile, Pattern)
|
||||
|
||||
else:
|
||||
Match = fnmatch.fnmatch(UnsortedFile.lower(), Pattern.lower())
|
||||
|
||||
if Match:
|
||||
NewFileName = File["NewFileName"]
|
||||
|
||||
if (ConfVars["NextNum"] in NewFileName):
|
||||
@@ -275,7 +283,8 @@ def Sort(FilePath):
|
||||
|
||||
try:
|
||||
Clone(FilePath, NewDirPath, NewName, True)
|
||||
|
||||
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)
|
||||
Speak(TextOutput)
|
||||
@@ -319,24 +328,30 @@ def Main():
|
||||
for Output in ConfDirs["OutputDir"]:
|
||||
Output = Parse(String = Output)
|
||||
Dir(Output)
|
||||
|
||||
try:
|
||||
while True:
|
||||
for Input in ConfDirs["InputDir"]:
|
||||
InputPath = Parse(Input)
|
||||
|
||||
if not os.path.exists(InputPath):
|
||||
continue
|
||||
|
||||
while True:
|
||||
for Input in ConfDirs["InputDir"]:
|
||||
InputPath = Parse(Input)
|
||||
|
||||
if not os.path.exists(InputPath):
|
||||
continue
|
||||
for FileName in os.listdir(InputPath):
|
||||
FilePath = os.path.join(InputPath, FileName)
|
||||
|
||||
for FileName in os.listdir(InputPath):
|
||||
FilePath = os.path.join(InputPath, FileName)
|
||||
if os.path.isfile(FilePath):
|
||||
FileName = os.path.basename(FilePath)
|
||||
if (FileName.startswith(".") and Conf["DotFiles"] == 0):
|
||||
continue
|
||||
Sort(FilePath)
|
||||
|
||||
time.sleep(Conf.get("CheckInput", 10))
|
||||
|
||||
if os.path.isfile(FilePath):
|
||||
FileName = os.path.basename(FilePath)
|
||||
if (FileName.startswith(".") and Conf["DotFiles"] == 0):
|
||||
continue
|
||||
Sort(FilePath)
|
||||
|
||||
time.sleep(Conf.get("CheckInput", 10))
|
||||
except KeyboardInterrupt:
|
||||
TextOutput = GetConf("Stop", ConfPath)
|
||||
LogWrite(TextOutput)
|
||||
Speak(TextOutput)
|
||||
|
||||
|
||||
Init()
|
||||
Reference in new issue
Block a user