diff --git a/README.md b/README.md index 8564fdc..bbe0ff3 100644 --- a/README.md +++ b/README.md @@ -1,39 +1,47 @@ # CleanPy + Organizes files in folders and helps you to clean your PC - Join our Telegram group via the link given [below](#community) - Read about it on my [blog](https://prashants.in/blog/cleanpy-python-script-to-organize-your-files/) ## How to use + - `git clone https://github.com/prashantsengar/CleanPy.git` - `cd CleanPy` -- `python main.py` +- `python main.py -h` ## What it does -Organizes the files based on their extensions in folders. + +Organizes the files based on their extensions in folders. - Additional features (to be added) It notifies about Battery Status giving you it's stats along with a csv file in which usage stats are also recorded. The Time Notifier file notifies you to take breaks for every 20 minutes based on 20-20-20 rule by displaying a tkinter window box for 20 seconds with other options too along with displaying a quote. ### Features -Currently it has 2 modes -- Easy mode: Organzises files in the current directory -- Hard mode: Organizes files in the current directory and its subdirectories +Currently it has 2 arrange modes ( -a , --arrange ) + +- Weak mode: Organzises files in the current directory +- Strong mode: Organizes files in the current directory and its subdirectories + +Warning can be subdued using ( -nw , --nowarning ) flag ## What's next ### Make it a complete cleaning suite by adding these features + - Add a feature to walk through the PC and get info about large files - Find duplicate files in PC ### Make a complete PC suite by integrating other features + - Feature to notify the user to take breaks - Notify about battery percentage as in this [repo](https://github.com/prashantsengar/BatteryNotifier) - Get info about PC health -## Community +## Community Read the [contributing guide](./CONTRIBUTING.md) diff --git a/main.py b/main.py index 87881d4..8721960 100644 --- a/main.py +++ b/main.py @@ -4,44 +4,66 @@ # https://t.me/joinchat/INDdLlDf-SFDPURESGgdrQ import os -import sys +import errno import lib.arrange import lib.utils +import argparse RESULT_DIR = "CleanedPy" FOLDER_TYPES = lib.utils.configure() -try: - TARGET_FOLDER = sys.argv[1] -except: - TARGET_FOLDER = os.getcwd() - if __name__ == "__main__": + # Using argparse for the CLI. + # In the CLI , we shall expect the following + # 1) Target directory is a required option + # 2) Default option of arrange is strong. + # 3) He can over ride default with --arrange=weak. --arrange=strong also shall work. + # 4) Warnings can be escaped using --nowarning. - root = TARGET_FOLDER + parser = argparse.ArgumentParser( + formatter_class=argparse.RawTextHelpFormatter) + parser.add_argument( + "clean_dir", help="The directory which you want to clean up") + # help for arrange + arrange_help = """ Different modes of clean up + 1) strong + 2) weak + Defaults to strong """ + parser.add_argument("-a", "--arrange", type=str, help=arrange_help) + parser.add_argument( + "-nw", "--nowarning", action="store_true", help="flag to skip all the warnings" + ) + args = parser.parse_args() + TARGET_FOLDER = args.clean_dir + if not os.path.isdir(TARGET_FOLDER): + # print(" The provided directory for cleaning is not a valid path") + raise OSError(errno.ENOENT, "No such file or directory", TARGET_FOLDER) destination = os.path.join(TARGET_FOLDER, RESULT_DIR) lib.utils.makeFolders(destination, FOLDER_TYPES.keys()) - print("---CleanPy---") - print("Cleaning: ", root) - - choice = int( - input( - "Press [1]: for Weak arrange" - + "\nPress [2]: for Strong arrange" - + "\nPress [0]: to exit\nOption: " - ) - ) + print(f"---CleanPy Activated on {TARGET_FOLDER}---") + if args.arrange: + if args.arrange == "strong": + choice = 2 + elif args.arrange == "weak": + choice = 1 + else: + raise OSError( + errno.EINVAL, "Arrange value must either be strong or weak") + else: + print("Arrange value defaulting to strong ") + choice = 2 + warn = True + if args.nowarning: + warn = False if choice == 1: - res = lib.arrange.weak_arrange(root, destination, FOLDER_TYPES) + res = lib.arrange.weak_arrange( + TARGET_FOLDER, destination, FOLDER_TYPES) elif choice == 2: - res = lib.arrange.strong_arrange(root, destination, FOLDER_TYPES) - elif choice == 0: - sys.exit() - else: - print("Incorrect Input") - sys.exit() + res = lib.arrange.strong_arrange( + TARGET_FOLDER, destination, FOLDER_TYPES, warn=warn + ) # Final Result message = "Result"