diff --git a/.Github/README.md b/.Github/README.md index 7abbb61..593543f 100644 --- a/.Github/README.md +++ b/.Github/README.md @@ -1,11 +1,48 @@ # 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 +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 + +python + 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 ### SaraSortd Config (Config.toml) @@ -91,6 +128,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". ``` + ### 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). @@ -104,7 +142,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. -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: diff --git a/Config.toml b/Config.toml index eabb173..71ee501 100644 --- a/Config.toml +++ b/Config.toml @@ -1,7 +1,7 @@ Title = "SaraSortd Config" SafeMode = 1 SilentMode = 0 -CheckInput = 3 +CheckInput = 10 DotFiles = 0 Logging = 1 OverwriteDirConf = 0 diff --git a/DirConfig.toml b/DirConfig.toml index 81accb5..c728179 100644 --- a/DirConfig.toml +++ b/DirConfig.toml @@ -3,6 +3,7 @@ LastFile = "Unset" ParentDir = "Unset" ValidInputDirs = ["*"] FileLimit = 0 +DeleteOrg = 1 [[Files]] Pattern = "*" diff --git a/SaraSortd.py b/SaraSortd.py index a24ee20..9435f49 100644 --- a/SaraSortd.py +++ b/SaraSortd.py @@ -266,7 +266,6 @@ def DecideNewPath(FilePath): if not os.path.exists(DirConfPath) or not InputDirValid: continue - OutputFiles = 0 FileLimitConf = GetConf("FileLimit", DirConfPath) @@ -365,37 +364,37 @@ def DecideNewPath(FilePath): def Sort(FilePath): NewPath = DecideNewPath(FilePath) + NewDirPath = os.path.dirname(NewPath) + NewName = os.path.basename(NewPath) + + if (GetConf("DeleteOrg", f"{NewDirPath}/{Parse(String = ConfNames['DirConfName'], Parent = (os.path.basename(NewDirPath)))}.toml") == 1): + Delete = True + + else: + 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, True) + Clone(FilePath, Parse(String = ConfDirs["FailedDir"]), NewName, Delete) TextOutput = Parse(String = ConfLog["NotSorted"], VarCall = FilePath) LogWrite(TextOutput) Speak(TextOutput) return - NewDirPath = os.path.dirname(NewPath) - NewName = os.path.basename(NewPath) - try: - Clone(FilePath, NewDirPath, NewName, True) - UpdateConf( - f"{NewDirPath}/{Parse(String = ConfNames['DirConfName'], Parent = os.path.basename(NewDirPath))}.toml", - "LastFile", - NewName, - ) + 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}" - ) + TextOutput = Parse(String = ConfLog["Sorted"], VarCall = f"{FilePath} to {NewDirPath}/{NewName}") LogWrite(TextOutput) Speak(TextOutput) except Exception: Dir(Parse(String = ConfDirs["FailedDir"]), Output = False, CopyConf = False) 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) LogWrite(TextOutput) @@ -419,7 +418,7 @@ def Init(): Output = Parse(String = Output, Parent = os.path.basename(os.path.dirname(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) for Item in ConfData.get("Files", []): @@ -444,9 +443,7 @@ def Init(): Speak(TextOutput) else: - print( - "NO CONFIG FOUND! Make sure the 'Config.toml' is in the same directory as 'SaraSortd.py'" - ) + print("NO CONFIG FOUND! Make sure the 'Config.toml' is in the same directory as 'SaraSortd.py'") def Main(): @@ -459,7 +456,7 @@ def Main(): continue for FileName in os.listdir(InputPath): - FilePath = os.path.join(InputPath, FileName) + FilePath = f"{InputPath}/{FileName}" if os.path.isfile(FilePath): FileName = os.path.basename(FilePath)