Abstract configuration into class
This commit is contained in:
parent
92386000d8
commit
271c0b989d
@ -4,6 +4,7 @@ import argparse
|
||||
import logging
|
||||
import sys
|
||||
|
||||
from bulkredditdownloader.configuration import Configuration
|
||||
from bulkredditdownloader.downloader import RedditDownloader
|
||||
from bulkredditdownloader.exceptions import BulkDownloaderException
|
||||
|
||||
@ -116,7 +117,7 @@ def _setup_logging(verbosity: int):
|
||||
logging.getLogger('urllib3').setLevel(logging.CRITICAL)
|
||||
|
||||
|
||||
def main(args: argparse.Namespace):
|
||||
def main(args: Configuration):
|
||||
_setup_logging(args.verbose)
|
||||
try:
|
||||
reddit_downloader = RedditDownloader(args)
|
||||
@ -127,5 +128,6 @@ def main(args: argparse.Namespace):
|
||||
|
||||
if __name__ == '__main__':
|
||||
_add_options()
|
||||
args = parser.parse_args()
|
||||
read_configuration = Configuration()
|
||||
args = parser.parse_args(namespace=read_configuration)
|
||||
main(args)
|
||||
|
28
bulkredditdownloader/configuration.py
Normal file
28
bulkredditdownloader/configuration.py
Normal file
@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env python3
|
||||
# coding=utf-8
|
||||
|
||||
from argparse import Namespace
|
||||
from typing import Optional
|
||||
|
||||
|
||||
class Configuration(Namespace):
|
||||
def __init__(self):
|
||||
super(Configuration, self).__init__()
|
||||
self.directory: str = '.'
|
||||
self.limit: Optional[int] = None
|
||||
self.link: list[str] = []
|
||||
self.multireddit: list[str] = []
|
||||
self.no_dupes: bool = False
|
||||
self.saved: bool = False
|
||||
self.search: Optional[str] = None
|
||||
self.set_file_scheme: str = '{REDDITOR}_{TITLE}_{POSTID}'
|
||||
self.set_folder_scheme: str = '{SUBREDDIT}'
|
||||
self.skip: list[str] = []
|
||||
self.skip_domain: list[str] = []
|
||||
self.sort: str = 'hot'
|
||||
self.submitted: bool = False
|
||||
self.subreddit: list[str] = []
|
||||
self.time: str = 'all'
|
||||
self.upvoted: bool = False
|
||||
self.user: Optional[str] = None
|
||||
self.verbose: int = 0
|
@ -1,10 +1,8 @@
|
||||
#!/usr/bin/env python3
|
||||
# coding=utf-8
|
||||
|
||||
import argparse
|
||||
import configparser
|
||||
import logging
|
||||
import re
|
||||
import socket
|
||||
from datetime import datetime
|
||||
from enum import Enum, auto
|
||||
@ -17,6 +15,7 @@ import praw.models
|
||||
import prawcore
|
||||
|
||||
import bulkredditdownloader.exceptions as errors
|
||||
from bulkredditdownloader.configuration import Configuration
|
||||
from bulkredditdownloader.download_filter import DownloadFilter
|
||||
from bulkredditdownloader.file_name_formatter import FileNameFormatter
|
||||
from bulkredditdownloader.oauth2 import OAuth2Authenticator, OAuth2TokenManager
|
||||
@ -44,7 +43,7 @@ class RedditTypes:
|
||||
|
||||
|
||||
class RedditDownloader:
|
||||
def __init__(self, args: argparse.Namespace):
|
||||
def __init__(self, args: Configuration):
|
||||
self.args = args
|
||||
self.config_directories = appdirs.AppDirs('bulk_reddit_downloader', 'BDFR')
|
||||
self.run_time = datetime.now().isoformat()
|
||||
|
@ -12,6 +12,7 @@ import praw.models
|
||||
import pytest
|
||||
|
||||
from bulkredditdownloader.__main__ import _setup_logging
|
||||
from bulkredditdownloader.configuration import Configuration
|
||||
from bulkredditdownloader.download_filter import DownloadFilter
|
||||
from bulkredditdownloader.downloader import RedditDownloader, RedditTypes
|
||||
from bulkredditdownloader.exceptions import BulkDownloaderException, RedditAuthenticationError, RedditUserError
|
||||
@ -20,28 +21,8 @@ from bulkredditdownloader.site_authenticator import SiteAuthenticator
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def args() -> argparse.Namespace:
|
||||
args = argparse.Namespace()
|
||||
|
||||
args.directory = '.'
|
||||
args.verbose = 0
|
||||
args.link = []
|
||||
args.submitted = False
|
||||
args.upvoted = False
|
||||
args.saved = False
|
||||
args.subreddit = []
|
||||
args.multireddit = []
|
||||
args.user = None
|
||||
args.search = None
|
||||
args.sort = 'hot'
|
||||
args.limit = None
|
||||
args.time = 'all'
|
||||
args.skip = []
|
||||
args.skip_domain = []
|
||||
args.set_folder_scheme = '{SUBREDDIT}'
|
||||
args.set_file_scheme = '{REDDITOR}_{TITLE}_{POSTID}'
|
||||
args.no_dupes = False
|
||||
|
||||
def args() -> Configuration:
|
||||
args = Configuration()
|
||||
return args
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user