Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
Add graceful exit and output of version num in log.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jules-WinnfieldX committed Dec 4, 2023
1 parent 8da680b commit e4f1a96
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cyberdrop_dl/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "5.0.4"
__version__ = "5.0.5"
14 changes: 13 additions & 1 deletion cyberdrop_dl/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import contextlib
import logging
import os
import signal
import sys

import aiorun
Expand Down Expand Up @@ -96,13 +97,24 @@ async def director(manager: Manager) -> None:
asyncio.get_event_loop().stop()


class GracefulExit:
def __enter__(self):
signal.signal(signal.SIGINT, self.exit_gracefully)
return self

@staticmethod
def exit_gracefully(signum, frame):
exit(0)


def main():
manager = startup()

with contextlib.suppress(RuntimeError, asyncio.CancelledError):
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
aiorun.run(director(manager), stop_on_unhandled_errors=True)
with GracefulExit():
aiorun.run(director(manager), stop_on_unhandled_errors=True)
sys.exit(0)


Expand Down
2 changes: 2 additions & 0 deletions cyberdrop_dl/managers/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from dataclasses import field
from pathlib import Path

from cyberdrop_dl import __version__
from cyberdrop_dl.managers.args_manager import ArgsManager
from cyberdrop_dl.managers.client_manager import ClientManager
from cyberdrop_dl.managers.db_manager import DBManager
Expand Down Expand Up @@ -162,6 +163,7 @@ async def args_logging(self) -> None:
print_settings['Sorting']['sort_folder'] = str(print_settings['Sorting']['sort_folder'])

await log(f"Starting Cyberdrop-DL Process for {self.config_manager.loaded_config} Config")
await log(f"Running version {__version__}")
await log(f"Using Authentication: \n{json.dumps(auth_provided, indent=4, sort_keys=True)}")
await log(f"Using Settings: \n{json.dumps(print_settings, indent=4, sort_keys=True)}")
await log(f"Using Global Settings: \n{json.dumps(self.config_manager.global_settings_data, indent=4, sort_keys=True)}")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "cyberdrop-dl"
version = "5.0.4"
version = "5.0.5"
description = "Bulk downloader for multiple file hosts"
authors = ["Jules Winnfield <[email protected]>"]
readme = "README.md"
Expand Down

0 comments on commit e4f1a96

Please sign in to comment.