Changeset View
Changeset View
Standalone View
Standalone View
swh/lister/__init__.py
# Copyright (C) 2018-2019 The Software Heritage developers | # Copyright (C) 2018-2022 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import logging | import logging | ||||
import pkg_resources | import pkg_resources | ||||
from swh.lister import pattern | |||||
logger = logging.getLogger(__name__) | logger = logging.getLogger(__name__) | ||||
try: | try: | ||||
__version__ = pkg_resources.get_distribution("swh.lister").version | __version__ = pkg_resources.get_distribution("swh.lister").version | ||||
except pkg_resources.DistributionNotFound: | except pkg_resources.DistributionNotFound: | ||||
__version__ = "devel" | __version__ = "devel" | ||||
Show All 28 Lines | if lister_name not in LISTERS: | ||||
"Invalid lister %s: only supported listers are %s" | "Invalid lister %s: only supported listers are %s" | ||||
% (lister_name, SUPPORTED_LISTERS) | % (lister_name, SUPPORTED_LISTERS) | ||||
) | ) | ||||
if db_url: | if db_url: | ||||
conf["lister"] = {"cls": "local", "args": {"db": db_url}} | conf["lister"] = {"cls": "local", "args": {"db": db_url}} | ||||
registry_entry = LISTERS[lister_name].load()() | registry_entry = LISTERS[lister_name].load()() | ||||
lister_cls = registry_entry["lister"] | lister_cls = registry_entry["lister"] | ||||
from swh.lister import pattern | |||||
if issubclass(lister_cls, pattern.Lister): | if issubclass(lister_cls, pattern.Lister): | ||||
return lister_cls.from_config(**conf) | return lister_cls.from_config(**conf) | ||||
else: | else: | ||||
# Old-style lister | # Old-style lister | ||||
return lister_cls(override_config=conf) | return lister_cls(override_config=conf) |