Refactor: Move repeated check into its own function.

This commit is contained in:
Tobias Gruetzmacher 2014-10-13 21:29:54 +02:00
parent 3235b8b312
commit d495d95ee0

View file

@ -203,17 +203,13 @@ 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) yield scraperclass()
continue
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) yield scraperclass()
continue
yield scraperclass()
else: else:
# get only selected comic scrapers # get only selected comic scrapers
# store them in a set to eliminate duplicates # store them in a set to eliminate duplicates
@ -233,13 +229,18 @@ 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) scraperobj = scraperclass(indexes=indexes)
continue if scraperobj not in scrapers:
scraperobj = scraperclass(indexes=indexes) scrapers.add(scraperobj)
if scraperobj not in scrapers: yield scraperobj
scrapers.add(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):