예제 #1
0
 def update_method(self):
     """Getting user input to change the way the utility works"""
     while 1:
         method_dict = {
             n: m
             for n, m in enumerate(['destroy', 'zeroing', 'delete', 'test'],
                                   1)
         }
         print('0. Cancel')
         for n, m in method_dict.items():
             msg = f'{n}: {m}'
             if self.method == m:
                 msg += ' [x]'
             print(msg)
         user_method = click.prompt(f'Select a method', type=int)
         if not user_method:
             break
         smart.smart_print()
         if user_method not in method_dict:
             print('Input Error!')
             continue
         else:
             self.method = method_dict[user_method]
             print(f'The method is successfully changed to {self.method}!')
         break
예제 #2
0
 def prompt_path(self):
     """Getting path input from the user and adding them"""
     while 1:
         user_path = click.prompt('Enter the path (0 - back)')
         smart.smart_print()
         if user_path == '0':
             break
         if self.add_path(user_path):
             print('Path added successfully!')
         else:
             print('Error! Invalid path or path was added earlier!')
예제 #3
0
def logo_start():
    """Output of the welcome logo"""
    smart.smart_print('', '*')
    smart.smart_print(f' {TITLE} v{VERSION} ', '=')
    smart.smart_print('', '*')
    smart.smart_print(
        'CLI utility for destroying, zeroing, and deleting files', ' ')
예제 #4
0
 def show(self):
     """Displays all folders and files that are contained in the added paths"""
     if self.__paths:
         for path in self.__paths:
             click.echo()
             click.echo(f'Path[{path}]')
             smart.smart_print()
             if os.path.isdir(path):
                 click.echo('Folders:')
                 for n, folder in enumerate(smart.get_folders_gen(path), 1):
                     print(f'{n} Path[{folder}]')
                 click.echo()
                 click.echo('Files:')
                 for n, file in enumerate(smart.get_files_gen(path), 1):
                     print(f'{n} Path[{file}]')
     else:
         print('There is no way to display...')
예제 #5
0
 def start(self):
     """Working with paths destroying, zeroing, and deleting files"""
     if self.__paths:
         smart.smart_print()
         click.echo(f'The selected method: {self.method}')
         count_files = 0
         count_dirs = 0
         obj_data = smart.DataObj()
         smart_cleaner = cleaner.Cleaner(shreds=self.num)
         for path in self.__paths:
             obj_data.add_path(path)
         for file in obj_data.get_files():
             count_files += 1
             smart.smart_print()
             print(f'[{count_files}][{self.method}] File: {file}')
             status = self.__work(smart_cleaner, file)
             smart.print_status(status)
         smart.smart_print()
         if self.del_dirs:
             for path in obj_data.get_dirs():
                 print(f'Delete folder: {path}')
                 if self.method != 'test':
                     status = smart_cleaner.del_dir(path)
                 else:
                     status = True
                 smart.print_status(status)
                 count_dirs += 1
             smart.smart_print()
         print(
             f'The work has been completed:\n'
             f'Processed files: [{count_files - len(smart_cleaner.errors)}]\n'
             f'Deleted folders: [{count_dirs}]\n'
             f'Errors: [{len(smart_cleaner.errors)}]')
         if smart_cleaner.errors:
             smart.smart_print(f' Errors: [{len(smart_cleaner.errors)}]')
             for err in smart_cleaner.errors:
                 print(err)
         self.clear()
     else:
         print('There is no way to work...')
예제 #6
0
 def prompt_remove_path(self):
     """User's choice of paths to exclude"""
     while 1:
         path_num_list = {n: path for n, path in enumerate(self.__paths, 1)}
         if not path_num_list:
             click.echo('There is no way to remove...')
             break
         click.echo('Added paths: ')
         smart.smart_print()
         for n, path in path_num_list.items():
             print(f'{n}. Path{path}')
         user_input = click.prompt(
             'Enter the path number to delete (0 - back)', type=int)
         smart.smart_print()
         if user_input == 0:
             break
         if user_input not in path_num_list:
             print('Input Error!')
         else:
             if self.remove_path(path_num_list[user_input]):
                 print('The path was successfully deleted!')
             else:
                 print('Error while deleting route!')
예제 #7
0
def cli(paths, yes, num, method, del_dirs):
    """
    Smart Files Destroyer - CLI utility for destroying, zeroing, and deleting files.

    PATHS - these are the paths to files and folders with files separated by a space,
    if there are spaces in the path name, escape them, or put them in quotation marks.

    - Console utility for destruction,
    zeroing, and deleting files.

    - The utility allows you to destruct files,
    reset them to zero and delete them,
    for complete or partial difficulty in
    restoring them after deletion.

    - Be careful! When adding folders, all files from all subfolders
    will be added recursively.

    -Use:
    sfd /path1 /path2 /pathN/file.file --shred -n 30 -dd -y

    https://github.com/mysmarthub/sfd
    [email protected]
    """
    work = True
    logo_start()
    my_cleaner = SmartCleaner(paths=set(paths),
                              method=method,
                              num=num,
                              del_dirs=del_dirs)
    if not yes or not my_cleaner.paths:
        while 1:
            smart.smart_print()
            click.echo(f'Main Menu. {my_cleaner}:')
            smart.smart_print()
            click.echo(f'0. Exit')
            click.echo(f'1. Start')
            click.echo(f'2. Add Path')
            click.echo(f'3. Remove Path')
            click.echo(f'4. Information about paths')
            click.echo(f'5. Show files and folders')
            click.echo(f'6. To change the method [{my_cleaner.method}]')
            click.echo(f'7. Open help url')
            smart.smart_print()
            action = click.prompt('Enter', type=int)
            smart.smart_print()
            if action == 1:
                if not my_cleaner.paths:
                    print("Error! You didn't add a path!")
                    continue
                work = True
                break
            elif action == 2:
                my_cleaner.prompt_path()
            elif action == 3:
                my_cleaner.prompt_remove_path()
            elif action == 4:
                my_cleaner.show_info()
            elif action == 5:
                my_cleaner.show()
            elif action == 6:
                my_cleaner.update_method()
            elif action == 7:
                open_url(README_URL)
            elif action == 0:
                work = False
                break
            else:
                print('Invalid input!')
    if work:
        my_cleaner.start()
    logo_finish()
    if os.name != 'posix':
        input('Enter for exit...')
예제 #8
0
def logo_finish():
    """Output of the completion logo"""
    click.echo()
    click.echo('Exit...')
    smart.smart_print('The program is complete', '-')
    smart.smart_print(f'{URL}', ' ')
    smart.smart_print(f'{YANDEX}', ' ')
    smart.smart_print(f'{PAYPAL}', ' ')
    smart.smart_print(f'{COPYRIGHT}', ' ')
    smart.smart_print('', '=')