def create_file(file_path, password): """ Create a new file, static method. Uses the FileStorage Helper to coordinate the creation of the file with its addition to the Storage File. :param file_path: Path of the Password File to create. :type file_path: str :param password: Password to assign to the Password File to create. :type password: str :return: False if the operation failed, the FileHandler object created otherwise. :rtype: Union(bool, FileHandler) """ fsh = FileStorageHelper() fsh.load_db() key, salt = EncryptionManager().generate_new_key(password=password) pass_file = PasswordFile(file_path=file_path, salt=salt) if not pass_file.is_complete(): return False if not fsh.add_file(pass_file): return False # initialize an empty file file_handler = FileHandler(file_path=file_path, password=password, salt=salt) file_handler.write_in_file(json.dumps([])) fsh.save_db() return file_handler
def delete(self): """ Delete a file. :return: None """ fsh = FileStorageHelper() fsh.load_db() self.get_all_entries() # check the master password self.delete_all_entries() # make it empty fsh.delete_file( PasswordFile(file_path=self.file_path, salt=self.salt) # removes the entry from the storage file ) fsh.save_db() # then save the db again. os.remove(self.file_path) # removes file from the OS.