Fix duplicate module detection
This commit is contained in:
parent
6835d490d8
commit
c43bc0cef4
3 changed files with 15 additions and 4 deletions
|
@ -1,7 +1,7 @@
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
# Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs
|
# Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs
|
||||||
# Copyright (C) 2012-2014 Bastian Kleineidam
|
# Copyright (C) 2012-2014 Bastian Kleineidam
|
||||||
# Copyright (C) 2015-2020 Tobias Gruetzmacher
|
# Copyright (C) 2015-2021 Tobias Gruetzmacher
|
||||||
import html
|
import html
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
@ -541,6 +541,7 @@ class Cache:
|
||||||
"""
|
"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.data = []
|
self.data = []
|
||||||
|
self.userdirs = set()
|
||||||
|
|
||||||
def find(self, comic, multiple_allowed=False):
|
def find(self, comic, multiple_allowed=False):
|
||||||
"""Get a list comic scraper objects.
|
"""Get a list comic scraper objects.
|
||||||
|
@ -585,6 +586,8 @@ class Cache:
|
||||||
"""Add an additional directory with python modules to the scraper list.
|
"""Add an additional directory with python modules to the scraper list.
|
||||||
These are handled as if the were part of the plugins package.
|
These are handled as if the were part of the plugins package.
|
||||||
"""
|
"""
|
||||||
|
if path in self.userdirs:
|
||||||
|
return
|
||||||
if not self.data:
|
if not self.data:
|
||||||
self.load()
|
self.load()
|
||||||
modules = 0
|
modules = 0
|
||||||
|
@ -594,6 +597,7 @@ class Cache:
|
||||||
modules += 1
|
modules += 1
|
||||||
classes += self.addmodule(module)
|
classes += self.addmodule(module)
|
||||||
self.validate()
|
self.validate()
|
||||||
|
self.userdirs.add(path)
|
||||||
if classes > 0:
|
if classes > 0:
|
||||||
out.debug("Added %d user classes from %d modules." % (
|
out.debug("Added %d user classes from %d modules." % (
|
||||||
classes, modules))
|
classes, modules))
|
||||||
|
|
7
tests/mocks/extra/dummy.py
Normal file
7
tests/mocks/extra/dummy.py
Normal 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/'
|
|
@ -30,6 +30,6 @@ class TestScraper(object):
|
||||||
|
|
||||||
def test_user_dir(self):
|
def test_user_dir(self):
|
||||||
oldlen = len(scrapers.get())
|
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.get()) == oldlen + 1
|
||||||
assert len(scrapers.find('ADummyTestScraper')) == 1
|
assert len(scrapers.find('AnotherDummyTestScraper')) == 1
|
||||||
|
|
Loading…
Reference in a new issue