Add option to specify logfile location
This commit is contained in:
@@ -20,6 +20,7 @@ _common_options = [
|
|||||||
click.option('-m', '--multireddit', multiple=True, default=None, type=str),
|
click.option('-m', '--multireddit', multiple=True, default=None, type=str),
|
||||||
click.option('-L', '--limit', default=None, type=int),
|
click.option('-L', '--limit', default=None, type=int),
|
||||||
click.option('--authenticate', is_flag=True, default=None),
|
click.option('--authenticate', is_flag=True, default=None),
|
||||||
|
click.option('--log', type=str, default=None),
|
||||||
click.option('--submitted', is_flag=True, default=None),
|
click.option('--submitted', is_flag=True, default=None),
|
||||||
click.option('--upvoted', is_flag=True, default=None),
|
click.option('--upvoted', is_flag=True, default=None),
|
||||||
click.option('--saved', is_flag=True, default=None),
|
click.option('--saved', is_flag=True, default=None),
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ class Configuration(Namespace):
|
|||||||
self.exclude_id_file = []
|
self.exclude_id_file = []
|
||||||
self.limit: Optional[int] = None
|
self.limit: Optional[int] = None
|
||||||
self.link: list[str] = []
|
self.link: list[str] = []
|
||||||
|
self.log: Optional[str] = None
|
||||||
self.max_wait_time = None
|
self.max_wait_time = None
|
||||||
self.multireddit: list[str] = []
|
self.multireddit: list[str] = []
|
||||||
self.no_dupes: bool = False
|
self.no_dupes: bool = False
|
||||||
|
|||||||
@@ -190,7 +190,12 @@ class RedditDownloader:
|
|||||||
|
|
||||||
def _create_file_logger(self):
|
def _create_file_logger(self):
|
||||||
main_logger = logging.getLogger()
|
main_logger = logging.getLogger()
|
||||||
|
if self.args.log is None:
|
||||||
log_path = Path(self.config_directory, 'log_output.txt')
|
log_path = Path(self.config_directory, 'log_output.txt')
|
||||||
|
else:
|
||||||
|
log_path = Path(self.args.log).resolve().expanduser()
|
||||||
|
if not log_path.parent.exists():
|
||||||
|
raise errors.BulkDownloaderException(f'Designated location for logfile does not exist')
|
||||||
backup_count = self.cfg_parser.getint('DEFAULT', 'backup_log_count', fallback=3)
|
backup_count = self.cfg_parser.getint('DEFAULT', 'backup_log_count', fallback=3)
|
||||||
file_handler = logging.handlers.RotatingFileHandler(
|
file_handler = logging.handlers.RotatingFileHandler(
|
||||||
log_path,
|
log_path,
|
||||||
|
|||||||
+33
-18
@@ -12,6 +12,21 @@ from bdfr.__main__ import cli
|
|||||||
does_test_config_exist = Path('test_config.cfg').exists()
|
does_test_config_exist = Path('test_config.cfg').exists()
|
||||||
|
|
||||||
|
|
||||||
|
def create_basic_args_for_download_runner(test_args: list[str], tmp_path: Path):
|
||||||
|
out = [
|
||||||
|
'download', str(tmp_path),
|
||||||
|
'-v',
|
||||||
|
'--config', 'test_config.cfg',
|
||||||
|
'--log', str(Path(tmp_path, 'test_log.txt')),
|
||||||
|
] + test_args
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
def create_basic_args_for_archive_runner(test_args: list[str], tmp_path: Path):
|
||||||
|
out = ['archive', str(tmp_path), '-v', '--config', 'test_config.cfg'] + test_args
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.online
|
@pytest.mark.online
|
||||||
@pytest.mark.reddit
|
@pytest.mark.reddit
|
||||||
@pytest.mark.skipif(not does_test_config_exist, reason='A test config file is required for integration tests')
|
@pytest.mark.skipif(not does_test_config_exist, reason='A test config file is required for integration tests')
|
||||||
@@ -36,7 +51,7 @@ does_test_config_exist = Path('test_config.cfg').exists()
|
|||||||
))
|
))
|
||||||
def test_cli_download_subreddits(test_args: list[str], tmp_path: Path):
|
def test_cli_download_subreddits(test_args: list[str], tmp_path: Path):
|
||||||
runner = CliRunner()
|
runner = CliRunner()
|
||||||
test_args = ['download', str(tmp_path), '-v', '--config', 'test_config.cfg'] + test_args
|
test_args = create_basic_args_for_download_runner(test_args, tmp_path)
|
||||||
result = runner.invoke(cli, test_args)
|
result = runner.invoke(cli, test_args)
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
assert 'Added submissions from subreddit ' in result.output
|
assert 'Added submissions from subreddit ' in result.output
|
||||||
@@ -54,7 +69,7 @@ def test_cli_download_subreddits(test_args: list[str], tmp_path: Path):
|
|||||||
))
|
))
|
||||||
def test_cli_download_links(test_args: list[str], tmp_path: Path):
|
def test_cli_download_links(test_args: list[str], tmp_path: Path):
|
||||||
runner = CliRunner()
|
runner = CliRunner()
|
||||||
test_args = ['download', str(tmp_path), '-v', '--config', 'test_config.cfg'] + test_args
|
test_args = create_basic_args_for_download_runner(test_args, tmp_path)
|
||||||
result = runner.invoke(cli, test_args)
|
result = runner.invoke(cli, test_args)
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
|
|
||||||
@@ -70,7 +85,7 @@ def test_cli_download_links(test_args: list[str], tmp_path: Path):
|
|||||||
))
|
))
|
||||||
def test_cli_download_multireddit(test_args: list[str], tmp_path: Path):
|
def test_cli_download_multireddit(test_args: list[str], tmp_path: Path):
|
||||||
runner = CliRunner()
|
runner = CliRunner()
|
||||||
test_args = ['download', str(tmp_path), '-v', '--config', 'test_config.cfg'] + test_args
|
test_args = create_basic_args_for_download_runner(test_args, tmp_path)
|
||||||
result = runner.invoke(cli, test_args)
|
result = runner.invoke(cli, test_args)
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
assert 'Added submissions from multireddit ' in result.output
|
assert 'Added submissions from multireddit ' in result.output
|
||||||
@@ -84,7 +99,7 @@ def test_cli_download_multireddit(test_args: list[str], tmp_path: Path):
|
|||||||
))
|
))
|
||||||
def test_cli_download_multireddit_nonexistent(test_args: list[str], tmp_path: Path):
|
def test_cli_download_multireddit_nonexistent(test_args: list[str], tmp_path: Path):
|
||||||
runner = CliRunner()
|
runner = CliRunner()
|
||||||
test_args = ['download', str(tmp_path), '-v', '--config', 'test_config.cfg'] + test_args
|
test_args = create_basic_args_for_download_runner(test_args, tmp_path)
|
||||||
result = runner.invoke(cli, test_args)
|
result = runner.invoke(cli, test_args)
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
assert 'Failed to get submissions for multireddit' in result.output
|
assert 'Failed to get submissions for multireddit' in result.output
|
||||||
@@ -105,7 +120,7 @@ def test_cli_download_multireddit_nonexistent(test_args: list[str], tmp_path: Pa
|
|||||||
))
|
))
|
||||||
def test_cli_download_user_data_good(test_args: list[str], tmp_path: Path):
|
def test_cli_download_user_data_good(test_args: list[str], tmp_path: Path):
|
||||||
runner = CliRunner()
|
runner = CliRunner()
|
||||||
test_args = ['download', str(tmp_path), '-v', '--config', 'test_config.cfg'] + test_args
|
test_args = create_basic_args_for_download_runner(test_args, tmp_path)
|
||||||
result = runner.invoke(cli, test_args)
|
result = runner.invoke(cli, test_args)
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
assert 'Downloaded submission ' in result.output
|
assert 'Downloaded submission ' in result.output
|
||||||
@@ -120,7 +135,7 @@ def test_cli_download_user_data_good(test_args: list[str], tmp_path: Path):
|
|||||||
))
|
))
|
||||||
def test_cli_download_user_data_bad_me_unauthenticated(test_args: list[str], tmp_path: Path):
|
def test_cli_download_user_data_bad_me_unauthenticated(test_args: list[str], tmp_path: Path):
|
||||||
runner = CliRunner()
|
runner = CliRunner()
|
||||||
test_args = ['download', str(tmp_path), '-v', '--config', 'test_config.cfg'] + test_args
|
test_args = create_basic_args_for_download_runner(test_args, tmp_path)
|
||||||
result = runner.invoke(cli, test_args)
|
result = runner.invoke(cli, test_args)
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
assert 'To use "me" as a user, an authenticated Reddit instance must be used' in result.output
|
assert 'To use "me" as a user, an authenticated Reddit instance must be used' in result.output
|
||||||
@@ -135,7 +150,7 @@ def test_cli_download_user_data_bad_me_unauthenticated(test_args: list[str], tmp
|
|||||||
def test_cli_download_search_existing(test_args: list[str], tmp_path: Path):
|
def test_cli_download_search_existing(test_args: list[str], tmp_path: Path):
|
||||||
Path(tmp_path, 'test.txt').touch()
|
Path(tmp_path, 'test.txt').touch()
|
||||||
runner = CliRunner()
|
runner = CliRunner()
|
||||||
test_args = ['download', str(tmp_path), '-v', '--config', 'test_config.cfg'] + test_args
|
test_args = create_basic_args_for_download_runner(test_args, tmp_path)
|
||||||
result = runner.invoke(cli, test_args)
|
result = runner.invoke(cli, test_args)
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
assert 'Calculating hashes for' in result.output
|
assert 'Calculating hashes for' in result.output
|
||||||
@@ -149,7 +164,7 @@ def test_cli_download_search_existing(test_args: list[str], tmp_path: Path):
|
|||||||
))
|
))
|
||||||
def test_cli_download_download_filters(test_args: list[str], tmp_path: Path):
|
def test_cli_download_download_filters(test_args: list[str], tmp_path: Path):
|
||||||
runner = CliRunner()
|
runner = CliRunner()
|
||||||
test_args = ['download', str(tmp_path), '-v', '--config', 'test_config.cfg'] + test_args
|
test_args = create_basic_args_for_download_runner(test_args, tmp_path)
|
||||||
result = runner.invoke(cli, test_args)
|
result = runner.invoke(cli, test_args)
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
assert 'Download filter removed submission' in result.output
|
assert 'Download filter removed submission' in result.output
|
||||||
@@ -164,7 +179,7 @@ def test_cli_download_download_filters(test_args: list[str], tmp_path: Path):
|
|||||||
))
|
))
|
||||||
def test_cli_download_long(test_args: list[str], tmp_path: Path):
|
def test_cli_download_long(test_args: list[str], tmp_path: Path):
|
||||||
runner = CliRunner()
|
runner = CliRunner()
|
||||||
test_args = ['download', str(tmp_path), '-v', '--config', 'test_config.cfg'] + test_args
|
test_args = create_basic_args_for_download_runner(test_args, tmp_path)
|
||||||
result = runner.invoke(cli, test_args)
|
result = runner.invoke(cli, test_args)
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
|
|
||||||
@@ -178,7 +193,7 @@ def test_cli_download_long(test_args: list[str], tmp_path: Path):
|
|||||||
))
|
))
|
||||||
def test_cli_archive_single(test_args: list[str], tmp_path: Path):
|
def test_cli_archive_single(test_args: list[str], tmp_path: Path):
|
||||||
runner = CliRunner()
|
runner = CliRunner()
|
||||||
test_args = ['archive', str(tmp_path), '-v', '--config', 'test_config.cfg'] + test_args
|
test_args = create_basic_args_for_archive_runner(test_args, tmp_path)
|
||||||
result = runner.invoke(cli, test_args)
|
result = runner.invoke(cli, test_args)
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
assert re.search(r'Writing entry .*? to file in .*? format', result.output)
|
assert re.search(r'Writing entry .*? to file in .*? format', result.output)
|
||||||
@@ -197,7 +212,7 @@ def test_cli_archive_single(test_args: list[str], tmp_path: Path):
|
|||||||
))
|
))
|
||||||
def test_cli_archive_subreddit(test_args: list[str], tmp_path: Path):
|
def test_cli_archive_subreddit(test_args: list[str], tmp_path: Path):
|
||||||
runner = CliRunner()
|
runner = CliRunner()
|
||||||
test_args = ['archive', str(tmp_path), '-v', '--config', 'test_config.cfg'] + test_args
|
test_args = create_basic_args_for_archive_runner(test_args, tmp_path)
|
||||||
result = runner.invoke(cli, test_args)
|
result = runner.invoke(cli, test_args)
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
assert re.search(r'Writing entry .*? to file in .*? format', result.output)
|
assert re.search(r'Writing entry .*? to file in .*? format', result.output)
|
||||||
@@ -211,7 +226,7 @@ def test_cli_archive_subreddit(test_args: list[str], tmp_path: Path):
|
|||||||
))
|
))
|
||||||
def test_cli_archive_all_user_comments(test_args: list[str], tmp_path: Path):
|
def test_cli_archive_all_user_comments(test_args: list[str], tmp_path: Path):
|
||||||
runner = CliRunner()
|
runner = CliRunner()
|
||||||
test_args = ['archive', str(tmp_path), '-v', '--config', 'test_config.cfg'] + test_args
|
test_args = create_basic_args_for_archive_runner(test_args, tmp_path)
|
||||||
result = runner.invoke(cli, test_args)
|
result = runner.invoke(cli, test_args)
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
|
|
||||||
@@ -226,7 +241,7 @@ def test_cli_archive_all_user_comments(test_args: list[str], tmp_path: Path):
|
|||||||
))
|
))
|
||||||
def test_cli_archive_long(test_args: list[str], tmp_path: Path):
|
def test_cli_archive_long(test_args: list[str], tmp_path: Path):
|
||||||
runner = CliRunner()
|
runner = CliRunner()
|
||||||
test_args = ['archive', str(tmp_path), '-v', '--config', 'test_config.cfg'] + test_args
|
test_args = create_basic_args_for_archive_runner(test_args, tmp_path)
|
||||||
result = runner.invoke(cli, test_args)
|
result = runner.invoke(cli, test_args)
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
assert re.search(r'Writing entry .*? to file in .*? format', result.output)
|
assert re.search(r'Writing entry .*? to file in .*? format', result.output)
|
||||||
@@ -243,7 +258,7 @@ def test_cli_archive_long(test_args: list[str], tmp_path: Path):
|
|||||||
))
|
))
|
||||||
def test_cli_download_soft_fail(test_args: list[str], tmp_path: Path):
|
def test_cli_download_soft_fail(test_args: list[str], tmp_path: Path):
|
||||||
runner = CliRunner()
|
runner = CliRunner()
|
||||||
test_args = ['download', str(tmp_path), '-v', '--config', 'test_config.cfg'] + test_args
|
test_args = create_basic_args_for_download_runner(test_args, tmp_path)
|
||||||
result = runner.invoke(cli, test_args)
|
result = runner.invoke(cli, test_args)
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
|
|
||||||
@@ -258,7 +273,7 @@ def test_cli_download_soft_fail(test_args: list[str], tmp_path: Path):
|
|||||||
))
|
))
|
||||||
def test_cli_download_hard_fail(test_args: list[str], tmp_path: Path):
|
def test_cli_download_hard_fail(test_args: list[str], tmp_path: Path):
|
||||||
runner = CliRunner()
|
runner = CliRunner()
|
||||||
test_args = ['download', str(tmp_path), '-v', '--config', 'test_config.cfg'] + test_args
|
test_args = create_basic_args_for_download_runner(test_args, tmp_path)
|
||||||
result = runner.invoke(cli, test_args)
|
result = runner.invoke(cli, test_args)
|
||||||
assert result.exit_code != 0
|
assert result.exit_code != 0
|
||||||
|
|
||||||
@@ -278,7 +293,7 @@ def test_cli_download_use_default_config(tmp_path: Path):
|
|||||||
))
|
))
|
||||||
def test_cli_download_links_exclusion(test_args: list[str], tmp_path: Path):
|
def test_cli_download_links_exclusion(test_args: list[str], tmp_path: Path):
|
||||||
runner = CliRunner()
|
runner = CliRunner()
|
||||||
test_args = ['download', str(tmp_path), '-v', '--config', 'test_config.cfg'] + test_args
|
test_args = create_basic_args_for_download_runner(test_args, tmp_path)
|
||||||
result = runner.invoke(cli, test_args)
|
result = runner.invoke(cli, test_args)
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
assert 'in exclusion list' in result.output
|
assert 'in exclusion list' in result.output
|
||||||
@@ -294,7 +309,7 @@ def test_cli_download_links_exclusion(test_args: list[str], tmp_path: Path):
|
|||||||
))
|
))
|
||||||
def test_cli_download_subreddit_exclusion(test_args: list[str], tmp_path: Path):
|
def test_cli_download_subreddit_exclusion(test_args: list[str], tmp_path: Path):
|
||||||
runner = CliRunner()
|
runner = CliRunner()
|
||||||
test_args = ['download', str(tmp_path), '-v', '--config', 'test_config.cfg'] + test_args
|
test_args = create_basic_args_for_download_runner(test_args, tmp_path)
|
||||||
result = runner.invoke(cli, test_args)
|
result = runner.invoke(cli, test_args)
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
assert 'in skip list' in result.output
|
assert 'in skip list' in result.output
|
||||||
@@ -310,7 +325,7 @@ def test_cli_download_subreddit_exclusion(test_args: list[str], tmp_path: Path):
|
|||||||
))
|
))
|
||||||
def test_cli_file_scheme_warning(test_args: list[str], tmp_path: Path):
|
def test_cli_file_scheme_warning(test_args: list[str], tmp_path: Path):
|
||||||
runner = CliRunner()
|
runner = CliRunner()
|
||||||
test_args = ['download', str(tmp_path), '-v', '--config', 'test_config.cfg'] + test_args
|
test_args = create_basic_args_for_download_runner(test_args, tmp_path)
|
||||||
result = runner.invoke(cli, test_args)
|
result = runner.invoke(cli, test_args)
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
assert 'Some files might not be downloaded due to name conflicts' in result.output
|
assert 'Some files might not be downloaded due to name conflicts' in result.output
|
||||||
|
|||||||
Reference in New Issue
Block a user