Fix duplicate module detection

This commit is contained in:
Tobias Gruetzmacher 2021-01-19 01:19:07 +01:00
parent 6835d490d8
commit c43bc0cef4
3 changed files with 15 additions and 4 deletions

View file

@ -1,7 +1,7 @@
# SPDX-License-Identifier: MIT
# Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs
# Copyright (C) 2012-2014 Bastian Kleineidam
# Copyright (C) 2015-2020 Tobias Gruetzmacher
# Copyright (C) 2015-2021 Tobias Gruetzmacher
import html
import os
import re
@ -541,6 +541,7 @@ class Cache:
"""
def __init__(self):
self.data = []
self.userdirs = set()
def find(self, comic, multiple_allowed=False):
"""Get a list comic scraper objects.
@ -585,6 +586,8 @@ class Cache:
"""Add an additional directory with python modules to the scraper list.
These are handled as if the were part of the plugins package.
"""
if path in self.userdirs:
return
if not self.data:
self.load()
modules = 0
@ -594,6 +597,7 @@ class Cache:
modules += 1
classes += self.addmodule(module)
self.validate()
self.userdirs.add(path)
if classes > 0:
out.debug("Added %d user classes from %d modules." % (
classes, modules))
@ -630,7 +634,7 @@ class Cache:
name2 = d[name].name
raise ValueError('duplicate scrapers %s and %s found' %
(name1, name2))
d[name] = scraper
d[name] = scraper
scrapers = Cache()

View file

@ -0,0 +1,7 @@
# SPDX-License-Identifier: MIT
# Copyright (C) 2021 Tobias Gruetzmacher
from ..scraper import _ParserScraper
class AnotherDummyTestScraper(_ParserScraper):
url = 'https://dummy.example/'

View file

@ -30,6 +30,6 @@ class TestScraper(object):
def test_user_dir(self):
oldlen = len(scrapers.get())
scrapers.adddir(Path(__file__).parent / 'mocks' / 'plugins')
scrapers.adddir(Path(__file__).parent / 'mocks' / 'extra')
assert len(scrapers.get()) == oldlen + 1
assert len(scrapers.find('ADummyTestScraper')) == 1
assert len(scrapers.find('AnotherDummyTestScraper')) == 1