[job] fix 'AttributeError' when enabling 'init' for non-DownloadJob
fixes bug in 56dcd00391
This commit is contained in:
@@ -268,6 +268,9 @@ class Job():
|
|||||||
for key, valuegen in self.kwdict_eval:
|
for key, valuegen in self.kwdict_eval:
|
||||||
kwdict[key] = valuegen(kwdict)
|
kwdict[key] = valuegen(kwdict)
|
||||||
|
|
||||||
|
def initialize(self):
|
||||||
|
pass
|
||||||
|
|
||||||
def _init(self):
|
def _init(self):
|
||||||
self.extractor.initialize()
|
self.extractor.initialize()
|
||||||
self.pred_url = self._prepare_predicates(
|
self.pred_url = self._prepare_predicates(
|
||||||
@@ -596,7 +599,7 @@ class DownloadJob(Job):
|
|||||||
return instance
|
return instance
|
||||||
|
|
||||||
def initialize(self, kwdict=None):
|
def initialize(self, kwdict=None):
|
||||||
"""Delayed initialization of PathFormat, etc."""
|
"""initialize PathFormat, postprocessors, archive, options, etc"""
|
||||||
extr = self.extractor
|
extr = self.extractor
|
||||||
cfg = extr.config
|
cfg = extr.config
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright 2021-2025 Mike Fährmann
|
# Copyright 2021-2026 Mike Fährmann
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License version 2 as
|
# it under the terms of the GNU General Public License version 2 as
|
||||||
@@ -51,19 +51,45 @@ class TestDownloadJob(TestJob):
|
|||||||
func = tjob._build_extractor_filter()
|
func = tjob._build_extractor_filter()
|
||||||
self.assertEqual(func(TestExtractor) , False)
|
self.assertEqual(func(TestExtractor) , False)
|
||||||
self.assertEqual(func(TestExtractorParent), False)
|
self.assertEqual(func(TestExtractorParent), False)
|
||||||
self.assertEqual(func(TestExtractorAlt) , True)
|
self.assertEqual(func(TestExtractorNoop) , True)
|
||||||
|
|
||||||
config.set((), "blacklist", ":test_subcategory")
|
config.set((), "blacklist", ":test_subcategory")
|
||||||
func = tjob._build_extractor_filter()
|
func = tjob._build_extractor_filter()
|
||||||
self.assertEqual(func(TestExtractor) , False)
|
self.assertEqual(func(TestExtractor) , False)
|
||||||
self.assertEqual(func(TestExtractorParent), True)
|
self.assertEqual(func(TestExtractorParent), True)
|
||||||
self.assertEqual(func(TestExtractorAlt) , False)
|
self.assertEqual(func(TestExtractorNoop) , False)
|
||||||
|
|
||||||
config.set((), "whitelist", "test_category:test_subcategory")
|
config.set((), "whitelist", "test_category:test_subcategory")
|
||||||
func = tjob._build_extractor_filter()
|
func = tjob._build_extractor_filter()
|
||||||
self.assertEqual(func(TestExtractor) , True)
|
self.assertEqual(func(TestExtractor) , True)
|
||||||
self.assertEqual(func(TestExtractorParent), False)
|
self.assertEqual(func(TestExtractorParent), False)
|
||||||
self.assertEqual(func(TestExtractorAlt) , False)
|
self.assertEqual(func(TestExtractorNoop) , False)
|
||||||
|
|
||||||
|
def test_opt_init(self):
|
||||||
|
config.set((), "init", True)
|
||||||
|
config.set((), "archive", ":memory:")
|
||||||
|
config.set((), "postprocessors", "directory")
|
||||||
|
|
||||||
|
extr = TestExtractorNoop.from_url("test:noop")
|
||||||
|
tjob = self.jobclass(extr)
|
||||||
|
tjob._init()
|
||||||
|
|
||||||
|
self.assertTrue(tjob.pathfmt)
|
||||||
|
self.assertTrue(tjob.archive)
|
||||||
|
self.assertTrue(tjob.hooks)
|
||||||
|
|
||||||
|
def test_opt_init_false(self):
|
||||||
|
config.set((), "init", False)
|
||||||
|
config.set((), "archive", ":memory:")
|
||||||
|
config.set((), "postprocessors", "directory")
|
||||||
|
|
||||||
|
extr = TestExtractorNoop.from_url("test:noop")
|
||||||
|
tjob = self.jobclass(extr)
|
||||||
|
tjob._init()
|
||||||
|
|
||||||
|
self.assertFalse(tjob.pathfmt)
|
||||||
|
self.assertFalse(tjob.archive)
|
||||||
|
self.assertFalse(tjob.hooks)
|
||||||
|
|
||||||
|
|
||||||
class TestKeywordJob(TestJob):
|
class TestKeywordJob(TestJob):
|
||||||
@@ -122,6 +148,13 @@ user['self']
|
|||||||
<circular reference>
|
<circular reference>
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
def test_opt_init(self):
|
||||||
|
config.set((), "init", True)
|
||||||
|
|
||||||
|
extr = TestExtractorNoop.from_url("test:noop")
|
||||||
|
tjob = self.jobclass(extr)
|
||||||
|
tjob._init()
|
||||||
|
|
||||||
|
|
||||||
class TestUrlJob(TestJob):
|
class TestUrlJob(TestJob):
|
||||||
jobclass = job.UrlJob
|
jobclass = job.UrlJob
|
||||||
@@ -165,6 +198,13 @@ https://example.org/2.jpg
|
|||||||
https://example.org/3.jpg
|
https://example.org/3.jpg
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
def test_opt_init(self):
|
||||||
|
config.set((), "init", True)
|
||||||
|
|
||||||
|
extr = TestExtractorNoop.from_url("test:noop")
|
||||||
|
tjob = self.jobclass(extr)
|
||||||
|
tjob._init()
|
||||||
|
|
||||||
|
|
||||||
class TestInfoJob(TestJob):
|
class TestInfoJob(TestJob):
|
||||||
jobclass = job.InfoJob
|
jobclass = job.InfoJob
|
||||||
@@ -228,6 +268,13 @@ Directory format (default):
|
|||||||
|
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
def test_opt_init(self):
|
||||||
|
config.set((), "init", True)
|
||||||
|
|
||||||
|
extr = TestExtractorNoop.from_url("test:noop")
|
||||||
|
tjob = self.jobclass(extr)
|
||||||
|
tjob._init()
|
||||||
|
|
||||||
|
|
||||||
class TestDataJob(TestJob):
|
class TestDataJob(TestJob):
|
||||||
jobclass = job.DataJob
|
jobclass = job.DataJob
|
||||||
@@ -378,6 +425,13 @@ class TestDataJob(TestJob):
|
|||||||
for line in file.getvalue().split():
|
for line in file.getvalue().split():
|
||||||
self.assertRegex(line, r"""^\[[23],("http[^"]+",)?\{.+\}\]$""")
|
self.assertRegex(line, r"""^\[[23],("http[^"]+",)?\{.+\}\]$""")
|
||||||
|
|
||||||
|
def test_opt_init(self):
|
||||||
|
config.set((), "init", True)
|
||||||
|
|
||||||
|
extr = TestExtractorNoop.from_url("test:noop")
|
||||||
|
tjob = self.jobclass(extr)
|
||||||
|
tjob._init()
|
||||||
|
|
||||||
|
|
||||||
class TestExtractor(Extractor):
|
class TestExtractor(Extractor):
|
||||||
category = "test_category"
|
category = "test_category"
|
||||||
@@ -437,9 +491,10 @@ class TestExtractorException(Extractor):
|
|||||||
return 1/0
|
return 1/0
|
||||||
|
|
||||||
|
|
||||||
class TestExtractorAlt(Extractor):
|
class TestExtractorNoop(Extractor):
|
||||||
category = "test_category_alt"
|
category = "test_category_alt"
|
||||||
subcategory = "test_subcategory"
|
subcategory = "test_subcategory"
|
||||||
|
pattern = r"test:noop"
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user