Print in main
This commit is contained in:
parent
74788d4c41
commit
77a73fadc8
1 changed files with 34 additions and 8 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
import argparse
|
import argparse
|
||||||
import sys
|
import sys
|
||||||
from typing import List
|
from typing import List
|
||||||
|
from typing import Tuple
|
||||||
|
|
||||||
from ytdl_sub.cli.download_args_parser import DownloadArgsParser
|
from ytdl_sub.cli.download_args_parser import DownloadArgsParser
|
||||||
from ytdl_sub.cli.main_args_parser import parser
|
from ytdl_sub.cli.main_args_parser import parser
|
||||||
|
|
@ -8,12 +9,15 @@ from ytdl_sub.config.config_file import ConfigFile
|
||||||
from ytdl_sub.config.preset import Preset
|
from ytdl_sub.config.preset import Preset
|
||||||
from ytdl_sub.subscriptions.subscription import Subscription
|
from ytdl_sub.subscriptions.subscription import Subscription
|
||||||
from ytdl_sub.utils.exceptions import ValidationException
|
from ytdl_sub.utils.exceptions import ValidationException
|
||||||
|
from ytdl_sub.utils.file_handler import FileHandlerTransactionLog
|
||||||
from ytdl_sub.utils.logger import Logger
|
from ytdl_sub.utils.logger import Logger
|
||||||
|
|
||||||
logger = Logger.get()
|
logger = Logger.get()
|
||||||
|
|
||||||
|
|
||||||
def _download_subscriptions_from_yaml_files(config: ConfigFile, args: argparse.Namespace) -> None:
|
def _download_subscriptions_from_yaml_files(
|
||||||
|
config: ConfigFile, args: argparse.Namespace
|
||||||
|
) -> List[Tuple[Subscription, FileHandlerTransactionLog]]:
|
||||||
"""
|
"""
|
||||||
Downloads all subscriptions from one or many subscription yaml files.
|
Downloads all subscriptions from one or many subscription yaml files.
|
||||||
|
|
||||||
|
|
@ -23,10 +27,16 @@ def _download_subscriptions_from_yaml_files(config: ConfigFile, args: argparse.N
|
||||||
Configuration file
|
Configuration file
|
||||||
args
|
args
|
||||||
Arguments from argparse
|
Arguments from argparse
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
List of (subscription, transaction_log)
|
||||||
"""
|
"""
|
||||||
preset_paths: List[str] = args.subscription_paths
|
preset_paths: List[str] = args.subscription_paths
|
||||||
presets: List[Preset] = []
|
presets: List[Preset] = []
|
||||||
|
output: List[Tuple[Subscription, FileHandlerTransactionLog]] = []
|
||||||
|
|
||||||
|
# Load all of the presets first to perform all validation before downloading
|
||||||
for preset_path in preset_paths:
|
for preset_path in preset_paths:
|
||||||
presets += Preset.from_file_path(config=config, subscription_path=preset_path)
|
presets += Preset.from_file_path(config=config, subscription_path=preset_path)
|
||||||
|
|
||||||
|
|
@ -34,12 +44,16 @@ def _download_subscriptions_from_yaml_files(config: ConfigFile, args: argparse.N
|
||||||
subscription = Subscription.from_preset(preset=preset, config=config)
|
subscription = Subscription.from_preset(preset=preset, config=config)
|
||||||
|
|
||||||
logger.info("Beginning subscription download for %s", subscription.name)
|
logger.info("Beginning subscription download for %s", subscription.name)
|
||||||
subscription.download(dry_run=args.dry_run)
|
transaction_log = subscription.download(dry_run=args.dry_run)
|
||||||
|
|
||||||
|
output.append((subscription, transaction_log))
|
||||||
|
|
||||||
|
return output
|
||||||
|
|
||||||
|
|
||||||
def _download_subscription_from_cli(
|
def _download_subscription_from_cli(
|
||||||
config: ConfigFile, args: argparse.Namespace, extra_args: List[str]
|
config: ConfigFile, args: argparse.Namespace, extra_args: List[str]
|
||||||
) -> None:
|
) -> Tuple[Subscription, FileHandlerTransactionLog]:
|
||||||
"""
|
"""
|
||||||
Downloads a one-off subscription using the CLI
|
Downloads a one-off subscription using the CLI
|
||||||
|
|
||||||
|
|
@ -51,6 +65,10 @@ def _download_subscription_from_cli(
|
||||||
Arguments from argparse
|
Arguments from argparse
|
||||||
extra_args
|
extra_args
|
||||||
Extra arguments from argparse that contain dynamic subscription options
|
Extra arguments from argparse that contain dynamic subscription options
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
Subscription and its download transaction log
|
||||||
"""
|
"""
|
||||||
dl_args_parser = DownloadArgsParser(
|
dl_args_parser = DownloadArgsParser(
|
||||||
extra_arguments=extra_args, config_options=config.config_options
|
extra_arguments=extra_args, config_options=config.config_options
|
||||||
|
|
@ -69,7 +87,7 @@ def _download_subscription_from_cli(
|
||||||
config=config,
|
config=config,
|
||||||
)
|
)
|
||||||
|
|
||||||
subscription.download(dry_run=args.dry_run)
|
return subscription, subscription.download(dry_run=args.dry_run)
|
||||||
|
|
||||||
|
|
||||||
def _main():
|
def _main():
|
||||||
|
|
@ -86,14 +104,22 @@ def _main():
|
||||||
config: ConfigFile = ConfigFile.from_file_path(args.config).initialize()
|
config: ConfigFile = ConfigFile.from_file_path(args.config).initialize()
|
||||||
Logger.set_log_level(log_level_name=args.log_level)
|
Logger.set_log_level(log_level_name=args.log_level)
|
||||||
|
|
||||||
|
transaction_logs: List[Tuple[Subscription, FileHandlerTransactionLog]] = []
|
||||||
if args.subparser == "sub":
|
if args.subparser == "sub":
|
||||||
_download_subscriptions_from_yaml_files(config=config, args=args)
|
transaction_logs = _download_subscriptions_from_yaml_files(config=config, args=args)
|
||||||
logger.info("Subscription download complete!")
|
|
||||||
|
|
||||||
# One-off download
|
# One-off download
|
||||||
if args.subparser == "dl":
|
if args.subparser == "dl":
|
||||||
_download_subscription_from_cli(config=config, args=args, extra_args=extra_args)
|
transaction_logs.append(
|
||||||
logger.info("Download complete!")
|
_download_subscription_from_cli(config=config, args=args, extra_args=extra_args)
|
||||||
|
)
|
||||||
|
|
||||||
|
for subscription, transaction_log in transaction_logs:
|
||||||
|
logger.info(
|
||||||
|
"Downloads for %s:\n%s\n",
|
||||||
|
subscription.name,
|
||||||
|
transaction_log.to_output_message(subscription.output_directory),
|
||||||
|
)
|
||||||
|
|
||||||
# Ran successfully, so we can delete the debug file
|
# Ran successfully, so we can delete the debug file
|
||||||
Logger.cleanup(delete_debug_file=True)
|
Logger.cleanup(delete_debug_file=True)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue