From 11eabcb856a72a02b96daa40798345b96053e69e Mon Sep 17 00:00:00 2001 From: Hackerjatti32 Date: Fri, 23 Aug 2024 12:12:43 +0530 Subject: [PATCH] Update main --- main/main | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/main/main b/main/main index fccebde..45caf37 100644 --- a/main/main +++ b/main/main @@ -12,29 +12,26 @@ import shutil sys.dont_write_bytecode = True -# Function to dynamically load modules with correct extensions +# Load module without extension def load_module(module_name, module_path): - if not os.path.exists(module_path): - raise FileNotFoundError(f"Module '{module_name}' not found at '{module_path}'") - spec = importlib.util.spec_from_file_location(module_name, module_path) if spec is None: - raise ImportError(f"Cannot load the spec for module '{module_name}' from '{module_path}'") - + raise FileNotFoundError(f"Module '{module_name}' not found at '{module_path}'") module = importlib.util.module_from_spec(spec) spec.loader.exec_module(module) return module -# Ensure the paths are correct; adjust as needed -encryptor = load_module("encryptor", "./encryptor.py") -storage = load_module("storage", "./storage.py") +# Load encryptor and storage modules +encryptor = load_module("encryptor", "./encryptor") +storage = load_module("storage", "./storage") -# Assign functions from the loaded modules +# Import functions from the loaded modules generate_key = encryptor.generate_key load_key = encryptor.load_key encrypt_message = encryptor.encrypt_message decrypt_message = encryptor.decrypt_message validate_password = encryptor.validate_password + save_passwords = storage.save_passwords load_passwords = storage.load_passwords delete_service = storage.delete_service @@ -49,6 +46,9 @@ remove_pycache() colorama.init(autoreset=True) def clear_screen(): + """ + Clears the terminal screen based on the operating system. + """ os.system('cls' if os.name == 'nt' else 'clear') def print_banner(): @@ -67,7 +67,7 @@ def print_help(): help_text = f""" {Fore.CYAN}LockBoxXtreme - Password Management Tool -Usage: python main.py [options] +Usage: python main [options] Options: -h, --help Show this help message and exit @@ -78,12 +78,15 @@ Options: 5) Exit Exit the application. {Fore.YELLOW}Example: -python main.py Run the interactive menu. -python main.py -h Show help message. +python main Run the interactive menu. +python main -h Show help message. """ print(help_text) def main(): + """ + Main function to interact with the user and manage passwords. + """ if len(sys.argv) > 1 and sys.argv[1] in ['-h', '--help']: print_help() return @@ -130,7 +133,7 @@ def main(): encrypted_password = encrypt_message(password, key) passwords = load_passwords() - passwords[service] = encrypted_password.decode() + passwords[service] = encrypted_password.decode() # Store as a string in JSON save_passwords(passwords) print(f"{Fore.GREEN}✅ Password for {service} has been locked away safely! 🔒") time.sleep(2) @@ -160,7 +163,7 @@ def main(): print(f"{Fore.YELLOW} - {service}") else: print(f"{Fore.RED}🚨 No services saved yet.") - print() + print() # Adding space for better readability time.sleep(1) elif choice == "4": @@ -183,4 +186,6 @@ def main(): if __name__ == "__main__": main() + + # Ensure __pycache__ is removed at the end of the script remove_pycache()