include graceful exits

This commit is contained in:
rambros 2026-03-01 18:35:38 +05:30
parent cbfeb8e51e
commit 7d547130ea
3 changed files with 47 additions and 42 deletions

View file

@ -61,13 +61,14 @@ def relaunch_in_terminal():
async def main(): async def main():
relaunch_in_terminal() relaunch_in_terminal()
setup_logging() setup_logging()
try:
await run_disco_reaper() await run_disco_reaper()
if __name__ == "__main__":
try:
asyncio.run(main())
except KeyboardInterrupt: except KeyboardInterrupt:
print("\nExiting...") print("\nOperation terminated by user.")
sys.exit(0)
except Exception as e: except Exception as e:
print(f"Error: {e}") print(f"Error: {e}")
sys.exit(1) sys.exit(1)
if __name__ == "__main__":
asyncio.run(main())

View file

@ -148,8 +148,8 @@ def main():
relaunch_in_terminal() relaunch_in_terminal()
config = load_config() config = load_config()
setup_logging() setup_logging()
platform = select_platform(config)
try: try:
platform = select_platform(config)
asyncio.run(run_cli(target_platform=platform)) asyncio.run(run_cli(target_platform=platform))
except KeyboardInterrupt: except KeyboardInterrupt:
print("\nOperation terminated by user.") print("\nOperation terminated by user.")

View file

@ -96,6 +96,7 @@ class DiscoReaperCLI:
async def run(self): async def run(self):
await self.validate_config() await self.validate_config()
try:
while True: while True:
console.print("") console.print("")
console.print(Panel.fit("Disco Reaper - Server Backup Tool", style="bold green")) console.print(Panel.fit("Disco Reaper - Server Backup Tool", style="bold green"))
@ -130,8 +131,11 @@ class DiscoReaperCLI:
elif choice == "4": elif choice == "4":
await self.edit_configuration() await self.edit_configuration()
elif choice == "Q": elif choice == "Q":
await self.engine.close_connections()
break break
except (KeyboardInterrupt, asyncio.CancelledError):
console.print("\n[yellow]Operation terminated by user.[/yellow]")
finally:
await self.engine.close_connections()
async def backup_server_profile(self): async def backup_server_profile(self):
"""Option 1: Backup name, banner, logo, roles, structure, and custom assets.""" """Option 1: Backup name, banner, logo, roles, structure, and custom assets."""