Refactor: Move repeated check into its own function.
This commit is contained in:
parent
3235b8b312
commit
d495d95ee0
1 changed files with 16 additions and 15 deletions
|
@ -203,16 +203,12 @@ def getScrapers(comics, basepath=None, adult=True, multiple_allowed=False):
|
||||||
for scraperclass in scraper.get_scraperclasses():
|
for scraperclass in scraper.get_scraperclasses():
|
||||||
dirname = getDirname(scraperclass.getName())
|
dirname = getDirname(scraperclass.getName())
|
||||||
if os.path.isdir(os.path.join(basepath, dirname)):
|
if os.path.isdir(os.path.join(basepath, dirname)):
|
||||||
if not adult and scraperclass.adult:
|
if shouldRunScraper(scraperclass, adult):
|
||||||
warn_adult(scraperclass)
|
|
||||||
continue
|
|
||||||
yield scraperclass()
|
yield scraperclass()
|
||||||
elif '@@' in comics:
|
elif '@@' in comics:
|
||||||
# all scrapers
|
# all scrapers
|
||||||
for scraperclass in scraper.get_scraperclasses():
|
for scraperclass in scraper.get_scraperclasses():
|
||||||
if not adult and scraperclass.adult:
|
if shouldRunScraper(scraperclass, adult):
|
||||||
warn_adult(scraperclass)
|
|
||||||
continue
|
|
||||||
yield scraperclass()
|
yield scraperclass()
|
||||||
else:
|
else:
|
||||||
# get only selected comic scrapers
|
# get only selected comic scrapers
|
||||||
|
@ -233,15 +229,20 @@ def getScrapers(comics, basepath=None, adult=True, multiple_allowed=False):
|
||||||
indexes = None
|
indexes = None
|
||||||
scraperclasses = scraper.find_scraperclasses(name, multiple_allowed=multiple_allowed)
|
scraperclasses = scraper.find_scraperclasses(name, multiple_allowed=multiple_allowed)
|
||||||
for scraperclass in scraperclasses:
|
for scraperclass in scraperclasses:
|
||||||
if not adult and scraperclass.adult:
|
if shouldRunScraper(scraperclass, adult):
|
||||||
warn_adult(scraperclass)
|
|
||||||
continue
|
|
||||||
scraperobj = scraperclass(indexes=indexes)
|
scraperobj = scraperclass(indexes=indexes)
|
||||||
if scraperobj not in scrapers:
|
if scraperobj not in scrapers:
|
||||||
scrapers.add(scraperobj)
|
scrapers.add(scraperobj)
|
||||||
yield scraperobj
|
yield scraperobj
|
||||||
|
|
||||||
|
|
||||||
|
def shouldRunScraper(scraperclass, adult=True):
|
||||||
|
if not adult and scraperclass.adult:
|
||||||
|
warn_adult(scraperclass)
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def warn_adult(scraperclass):
|
def warn_adult(scraperclass):
|
||||||
"""Print warning about adult content."""
|
"""Print warning about adult content."""
|
||||||
out.warn(u"skipping adult comic %s; use the --adult option to confirm your age" % scraperclass.getName())
|
out.warn(u"skipping adult comic %s; use the --adult option to confirm your age" % scraperclass.getName())
|
||||||
|
|
Loading…
Reference in a new issue