From e4cee1bcf1ef3c94144214f18ec1e59f59a4dd3b Mon Sep 17 00:00:00 2001 From: kssvrk Date: Fri, 25 Dec 2020 12:01:27 +0530 Subject: [PATCH 1/3] added command line interface to Clean Py --- README.md | 20 ++++++++++++----- main.py | 65 +++++++++++++++++++++++++++++++++++-------------------- 2 files changed, 56 insertions(+), 29 deletions(-) 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..7ac459d 100644 --- a/main.py +++ b/main.py @@ -4,44 +4,63 @@ # https://t.me/joinchat/INDdLlDf-SFDPURESGgdrQ import os +import errno import sys 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. + # This is where we take inputs from the user. In the CLI , we shall expect the following + # 1) Target directory is a required option + # 2) Default option of arrange is strong , which we will warn the user before executing. + # 3) He can over ride default with --arrange=weak. --arrange=strong also shall work. + # 4) Warnings and user prompts can be escaped using --nowarn - 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" From 58f25a009d1e6b75c512bbdb412d8884cae51686 Mon Sep 17 00:00:00 2001 From: kssvrk Date: Fri, 25 Dec 2020 12:09:37 +0530 Subject: [PATCH 2/3] Added fixes to deepsource --- main.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index 7ac459d..99e2243 100644 --- a/main.py +++ b/main.py @@ -5,7 +5,7 @@ import os import errno -import sys +#import sys import lib.arrange import lib.utils import argparse @@ -15,14 +15,16 @@ if __name__ == "__main__": # Using argparse for the CLI. - # This is where we take inputs from the user. In the CLI , we shall expect the following + # In the CLI , we shall expect the following # 1) Target directory is a required option - # 2) Default option of arrange is strong , which we will warn the user before executing. + # 2) Default option of arrange is strong. # 3) He can over ride default with --arrange=weak. --arrange=strong also shall work. - # 4) Warnings and user prompts can be escaped using --nowarn + # 4) Warnings can be escaped using --nowarning. - parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter) - parser.add_argument("clean_dir", help="The directory which you want to clean up") + 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 @@ -48,7 +50,8 @@ elif args.arrange == "weak": choice = 1 else: - raise OSError(errno.EINVAL, "Arrange value must either be strong or weak") + raise OSError( + errno.EINVAL, "Arrange value must either be strong or weak") else: print("Arrange value defaulting to strong ") choice = 2 @@ -56,7 +59,8 @@ if args.nowarning: warn = False if choice == 1: - res = lib.arrange.weak_arrange(TARGET_FOLDER, destination, FOLDER_TYPES) + res = lib.arrange.weak_arrange( + TARGET_FOLDER, destination, FOLDER_TYPES) elif choice == 2: res = lib.arrange.strong_arrange( TARGET_FOLDER, destination, FOLDER_TYPES, warn=warn From 96db8bf2fb63cf738e1959f5347c3b244c12e1e9 Mon Sep 17 00:00:00 2001 From: kssvrk Date: Fri, 25 Dec 2020 12:13:28 +0530 Subject: [PATCH 3/3] Added fixes to deepsource 2 --- main.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 99e2243..8721960 100644 --- a/main.py +++ b/main.py @@ -5,7 +5,6 @@ import os import errno -#import sys import lib.arrange import lib.utils import argparse @@ -26,9 +25,9 @@ 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 + 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(