mirror of https://gitlab.com/KKlochko/tui-rsync
				
				
				
			
							parent
							
								
									ea5d98490d
								
							
						
					
					
						commit
						ea0cc3dab0
					
				| @ -0,0 +1,3 @@ | ||||
| from .remove_all_backup_plans_command import RemoveAllBackupBackupPlansCommand | ||||
| 
 | ||||
| __all__ = ['RemoveAllBackupBackupPlansCommand'] | ||||
| @ -0,0 +1,8 @@ | ||||
| from tui_rsync.infrastructure.orm.models import BackupPlanModel, DestinationModel | ||||
| 
 | ||||
| 
 | ||||
| class RemoveAllBackupBackupPlansCommand: | ||||
|     def execute(self) -> bool: | ||||
|         rows = BackupPlanModel.delete().execute() | ||||
|         rows = DestinationModel.delete().execute() + rows | ||||
|         return rows != 0 | ||||
| @ -0,0 +1,74 @@ | ||||
| ################################################################################ | ||||
| # Copyright (C) 2023 Kostiantyn Klochko <kostya_klochko@ukr.net>               # | ||||
| #                                                                              # | ||||
| # This file is part of tui-rsync.                                              # | ||||
| #                                                                              # | ||||
| # tui-rsync is free software: you can redistribute it and/or modify it under   # | ||||
| # uthe terms of the GNU General Public License as published by the Free        # | ||||
| # Software Foundation, either version 3 of the License, or (at your option)    # | ||||
| # any later version.                                                           # | ||||
| #                                                                              # | ||||
| # tui-rsync is distributed in the hope that it will be useful, but WITHOUT ANY # | ||||
| # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS    # | ||||
| # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more        # | ||||
| # details.                                                                     # | ||||
| #                                                                              # | ||||
| # You should have received a copy of the GNU General Public License along with # | ||||
| # tui-rsync. If not, see <https://www.gnu.org/licenses/>.                      # | ||||
| ################################################################################ | ||||
| 
 | ||||
| from rich.console import Console | ||||
| import typer | ||||
| 
 | ||||
| from tui_rsync.core.components.backup_plan.application.commands import RemoveAllBackupBackupPlansCommand | ||||
| from tui_rsync.core.components.backup_plan.application.repository.backup_plan_repository import BackupPlanRepository | ||||
| from tui_rsync.core.components.backup_plan.application.services.backup_plan_service import BackupPlanService | ||||
| from tui_rsync.core.shared_kernel.components.common import UUID | ||||
| from tui_rsync.infrastructure.orm import SqliteDatabaseManager | ||||
| 
 | ||||
| console = Console() | ||||
| remove_backup_plan = typer.Typer() | ||||
| 
 | ||||
| 
 | ||||
| @remove_backup_plan.command() | ||||
| def one( | ||||
|     id: str = typer.Option( | ||||
|         None, "--id", "-i", | ||||
|         help="[b]The id[/] is an uniq identification of a [b]backup plan[/].", | ||||
|         show_default=False | ||||
|     ) | ||||
| ): | ||||
|     """ | ||||
|     [red b]Remove[/] an [yellow]existing backup plan[/]. | ||||
|     """ | ||||
| 
 | ||||
|     db = SqliteDatabaseManager() | ||||
|     repository = BackupPlanRepository(db) | ||||
|     service = BackupPlanService(repository) | ||||
| 
 | ||||
|     if id is None: | ||||
|         console.print("[red b][ERROR][/] Backup plan does not exists!!!") | ||||
|         return | ||||
| 
 | ||||
|     plan = service.delete(UUID(id)) | ||||
| 
 | ||||
|     if plan is None: | ||||
|         console.print("[red b][ERROR][/] Backup plan does not exists!!!") | ||||
|         return | ||||
| 
 | ||||
|     console.print(f"Removed the backup plan with {id}.") | ||||
| 
 | ||||
| 
 | ||||
| @remove_backup_plan.command() | ||||
| def all(): | ||||
|     """ | ||||
|     [red b]Remove[/] [yellow] all existing backup plans[/]. | ||||
|     """ | ||||
| 
 | ||||
|     db = SqliteDatabaseManager() | ||||
|     removed = RemoveAllBackupBackupPlansCommand().execute() | ||||
| 
 | ||||
|     if removed: | ||||
|         console.print(f"Removed all backup plans.") | ||||
|     else: | ||||
|         console.print(f"Nothing to remove. No backup plans.") | ||||
					Loading…
					
					
				
		Reference in new issue