Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: startup process refactoring for manager #406

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions cyberdrop_dl/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@
from collections.abc import Callable


def startup() -> Manager:
async def startup() -> Manager:
"""Starts the program and returns the manager.

This will also run the UI for the program
After this function returns, the manager will be ready to use and scraping / downloading can begin.
"""
try:
manager = Manager()
manager.startup()
await manager.startup()
if manager.parsed_args.cli_only_args.multiconfig:
manager.validate_all_configs()

Expand Down Expand Up @@ -218,8 +218,9 @@ async def director(manager: Manager) -> None:
configs_to_run.pop(0)

log(f"Using Debug Log: {debug_log_file_path}", 10)
log("Starting Async Processes...", 10)
await manager.async_startup()
log("Resetting per config values...", 10)
manager.reset()

log_spacer(10)

log("Starting CDL...\n", 20)
Expand Down Expand Up @@ -247,7 +248,7 @@ def main() -> None:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
exit_code = 1
manager = startup()
manager = asyncio.run(startup())
with contextlib.suppress(Exception):
try:
asyncio.run(director(manager))
Expand Down
23 changes: 9 additions & 14 deletions cyberdrop_dl/managers/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,12 @@ def __init__(self) -> None:
self.downloaded_data: int = 0
self.multiconfig: bool = False

def startup(self) -> None:
async def startup(self) -> None:
"""Startup process for the manager."""
if isinstance(self.parsed_args, Field):
self.parsed_args = ParsedArgs.parse_args()

if not self.parsed_args.cli_only_args.appdata_folder:
self.first_time_setup.transfer_v4_to_v5()

self.parsed_args = ParsedArgs.parse_args()
self.path_manager = PathManager(self)
self.path_manager.pre_startup()
# need pathmanager to get proper appdata location
self.first_time_setup.transfer_v5_to_new_hashtable()

self.cache_manager.startup(self.path_manager.cache_folder / "cache.yaml")
self.config_manager = ConfigManager(self)
self.config_manager.startup()
Expand All @@ -85,6 +78,11 @@ def startup(self) -> None:
self.adjust_for_simpcity()
if self.config_manager.loaded_config.casefold() == "all" or self.parsed_args.cli_only_args.multiconfig:
self.multiconfig = True
await self.async_db_hash_startup()
self.first_time_setup.startup()




def adjust_for_simpcity(self) -> None:
"""Adjusts settings for SimpCity update."""
Expand All @@ -106,18 +104,15 @@ def adjust_for_simpcity(self) -> None:

"""~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"""

async def async_startup(self) -> None:
"""Async startup process for the manager."""
def reset(self) -> None:
"""reset settings values per configuration"""
self.args_logging()

if not isinstance(self.client_manager, ClientManager):
self.client_manager = ClientManager(self)
if not isinstance(self.download_manager, DownloadManager):
self.download_manager = DownloadManager(self)
if not isinstance(self.real_debrid_manager, RealDebridManager):
self.real_debrid_manager = RealDebridManager(self)
await self.async_db_hash_startup()

from cyberdrop_dl.utils import constants

constants.MAX_NAME_LENGTHS["FILE"] = self.config_manager.global_settings_data.general.max_file_name_length
Expand Down
1 change: 1 addition & 0 deletions cyberdrop_dl/utils/database/tables/hash_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ async def startup(self) -> None:
"""Startup process for the HistoryTable."""
await self.create_hash_tables()


async def create_hash_tables(self):
await self.db_conn.execute(create_files)
await self.db_conn.execute(create_hash)
Expand Down
9 changes: 9 additions & 0 deletions cyberdrop_dl/utils/transfer/db_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ class TransitionManager:
def __init__(self, manager: Manager) -> None:
self.manager = manager

def startup(self):
"""
Transfers files and configurations from old versions to new versions

"""
if not self.manager.parsed_args.cli_only_args.appdata_folder:
self.transfer_v4_to_v5()
self.transfer_v5_to_new_hashtable()

def transfer_v5_to_new_hashtable(self):
"""
transfers from old v5 hash table to new v5 hash table, that supports multiple hash types per file
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-patched"
version = "6.0.0"
version = "6.0.0.dev"
description = "Bulk downloader for multiple file hosts"
authors = ["Jacob B <[email protected]>"]
readme = "README.md"
Expand Down