diff --git a/GlobalConf.toml b/GlobalConf.toml index cf1a3bd..3eaee6e 100644 --- a/GlobalConf.toml +++ b/GlobalConf.toml @@ -1,5 +1,5 @@ Title = "SaraSortd Config" -Version = "7.0" +Version = "7.1" SafeMode = 1 SilentMode = 0 SortTimer = 1 diff --git a/InputDirConf.toml b/InputDirConf.toml index 495fb16..d1db176 100644 --- a/InputDirConf.toml +++ b/InputDirConf.toml @@ -1,5 +1,5 @@ Title = "Unset" -Version = "7.0" +Version = "7.1" ParentDir = "Unset" SortDirs = 0 diff --git a/OutputDirConf.toml b/OutputDirConf.toml index ac50468..84c9d8f 100644 --- a/OutputDirConf.toml +++ b/OutputDirConf.toml @@ -1,5 +1,5 @@ Title = "Unset" -Version = "7.0" +Version = "7.1" LastFile = "Unset" ParentDir = "Unset" ValidInputDirs = ["*"] diff --git a/README.md b/README.md index 86cce7c..ff3fb87 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ SaraSortd: a file and directory sorting daemon built with python. -(Version = "7.0") +(Version = "7.1") 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 = "7.0" # Just the version number for the config file. +Version = "7.1" # 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. @@ -73,13 +73,13 @@ Logging = 1 # If SaraSortd's logging system should be active. If this is 0, noth OverwriteDirConf = 0 # If SaraSortd should overwrite directory configs with the config templates. 0 is no, 1 is yes. [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. +NextNum = "!" # The next available number. If 1 already exists, 2 will be used. 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". +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". @@ -109,9 +109,11 @@ 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. +LogFileName = "[y].[m].[d]" # Name for log files. -DirConfName = ".@Config" # Name for config files for directories. +InDirConfName = ".@Config" # Name for config files for input directories. + +OutDirConfName = ".@Config" # Name for config files for output directories. If a directory is both an input and an output and both names are the same, it uses one config file for both. FileHistoryName = ".@History" # Name for file history files. This keeps track of sorted files if an input and output are the same directory. @@ -158,7 +160,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 = "7.0" # The version number of the config. +Version = "7.1" # 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. @@ -202,6 +204,8 @@ NextChar = "A" # Used to keep track of the next available letter for file names. 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. Overwrite = 1 # Whether this specific file type can be overwritten by others of the same type. 0 is no, 1 is yes. + +# ValidInputDirs = ["%RootDir%/Downloads"] # Optional (since 7.1). Like the ValidInputDirs above, but only for this [[Files]] entry, so different input directories can send different file types here. Without it, this entry takes files from every input directory the ValidInputDirs above allows. ``` --- @@ -212,7 +216,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 = "7.0" +Version = "7.1" 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 d30013d..e30e0d6 100644 --- a/SaraSortd.py +++ b/SaraSortd.py @@ -6,7 +6,7 @@ import shutil import time import toml -# Version = "7.0" +# Version = "7.1" ConfPath = "./GlobalConf.toml" @@ -276,6 +276,21 @@ def LogWrite(Text): File.write(f"{Parse(String = ConfLog['All'], Path = ConfPath)}{Text}\n") +def FileInputValid(File, FilePath, ParentName): + # A [[Files]] entry can have its own ValidInputDirs (since 7.1), so one output directory can take + # different patterns from different input directories. Without one, the entry takes files from + # every input directory the output directory's own ValidInputDirs allows. + ValidInputDirs = File.get("ValidInputDirs") + if ValidInputDirs is None: + return True + + for ValidInputDir in ValidInputDirs: + if fnmatch.fnmatchcase(os.path.dirname(FilePath), Parse(String = ValidInputDir, Parent = ParentName)): + return True + + return False + + def DecideNewPath(FilePath): UnsortedFile = os.path.basename(FilePath) @@ -287,7 +302,8 @@ def DecideNewPath(FilePath): OutDirConfName = Parse(String = ConfNames["OutDirConfName"], Path = ConfPath, Parent = ParentName) OutDirConfPath = f"{Output}/{OutDirConfName}.toml" - ValidInputDirs = GetConf("ValidInputDirs", OutDirConfPath) + ValidInputDirs = GetConf("ValidInputDirs", OutDirConfPath) or [] + InputDirValid = False for ValidInputDir in ValidInputDirs: ValidInputDir = Parse(String = ValidInputDir, Parent = GetConf("ParentDir", OutDirConfPath)) @@ -323,6 +339,9 @@ def DecideNewPath(FilePath): continue for File in FileConf: + if not FileInputValid(File, FilePath, ParentName): + continue + Pattern = File["Pattern"] TextOutput = Parse(String = ConfLog["MatchPattern"], VarCall = f"{UnsortedFile} against {Pattern}")