From c43bc0cef428d22aa234a94853aa1abd74abdc03 Mon Sep 17 00:00:00 2001 From: Tobias Gruetzmacher Date: Tue, 19 Jan 2021 01:19:07 +0100 Subject: [PATCH] Fix duplicate module detection --- dosagelib/scraper.py | 8 ++++++-- tests/mocks/extra/dummy.py | 7 +++++++ tests/test_scraper.py | 4 ++-- 3 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 tests/mocks/extra/dummy.py diff --git a/dosagelib/scraper.py b/dosagelib/scraper.py index 90a1c5f43..a14076c1f 100644 --- a/dosagelib/scraper.py +++ b/dosagelib/scraper.py @@ -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() diff --git a/tests/mocks/extra/dummy.py b/tests/mocks/extra/dummy.py new file mode 100644 index 000000000..c32584991 --- /dev/null +++ b/tests/mocks/extra/dummy.py @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: MIT +# Copyright (C) 2021 Tobias Gruetzmacher +from ..scraper import _ParserScraper + + +class AnotherDummyTestScraper(_ParserScraper): + url = 'https://dummy.example/' diff --git a/tests/test_scraper.py b/tests/test_scraper.py index 597d5ceaa..9c48be900 100644 --- a/tests/test_scraper.py +++ b/tests/test_scraper.py @@ -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