1
0
mirror of https://github.com/dkmstr/openuds.git synced 2025-01-12 09:17:56 +03:00

Done refactoring module loader

This commit is contained in:
Adolfo Gómez García 2022-03-10 21:05:59 +01:00
parent 6e69246ca8
commit 07b0b00b90
5 changed files with 20 additions and 49 deletions

View File

@ -134,8 +134,8 @@ CACHES = {
# 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
# }
'memory': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': '127.0.0.1:11211',
'BACKEND': 'django.core.cache.backends.memcached.PyLibMCCache',
'LOCATION': 'db.dkmon.com:11211',
},
}

View File

@ -29,11 +29,7 @@
"""
@author: Adolfo Gómez, dkmaster at dkmon dot com
"""
import importlib
import logging
import os.path
import pkgutil
import sys
import typing
from django import http

View File

@ -27,29 +27,21 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import os.path
import pkgutil
import sys
import importlib
import logging
import typing
from uds.core.util import modfinder
logger = logging.getLogger(__name__)
def loadPlugins():
def __loadPlugins():
"""
This imports all packages that are descendant of this package, and, after that,
it register all subclases of service provider as
"""
logger.debug('Initializing plugins...')
# Dinamycally import children of this package. The __init__.py files must import classes
pkgpath = os.path.dirname(typing.cast(str, sys.modules[__name__].__file__))
for _, name, _ in pkgutil.iter_modules([pkgpath]):
# __import__(name, globals(), locals(), [], 1)
importlib.import_module('.' + name, __name__) # Local import
# Load all modules
modfinder.importModules(__name__)
importlib.invalidate_caches()
loadPlugins()
__loadPlugins()

View File

@ -38,10 +38,6 @@ The registration of modules is done locating subclases of :py:class:`uds.core.re
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
"""
import os.path
import pkgutil
import importlib
import sys
import logging
import typing
@ -53,7 +49,7 @@ logger = logging.getLogger(__name__)
availableReports: typing.List[typing.Type['reports.Report']] = []
def __init__() -> None:
def __loadModules() -> None:
"""
This imports all packages that are descendant of this package, and, after that,
"""
@ -69,4 +65,4 @@ def __init__() -> None:
checker=lambda x: x.uuid is not None and x.uuid not in alreadyAdded,
)
__init__()
__loadModules()

View File

@ -41,37 +41,24 @@ The registration of modules is done locating subclases of :py:class:`uds.core.au
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
"""
# pylint: disable=maybe-no-member
import os.path
import pkgutil
import sys
import importlib
import logging
import typing
from uds.core.util import modfinder
logger = logging.getLogger(__name__)
def __init__():
def __loadModules():
"""
This imports all packages that are descendant of this package, and, after that,
it register all subclases of service provider as
"""
from uds.core import services
modfinder.dynamicLoadAndRegisterModules(
services.factory(),
services.ServiceProvider,
__name__
)
# Dinamycally import children of this package.
pkgpath = os.path.dirname(typing.cast(str, sys.modules[__name__].__file__))
for _, name, _ in pkgutil.iter_modules([pkgpath]):
# __import__('uds.services.' + name, globals(), locals(), [])
importlib.import_module('.' + name, __name__) # import module
importlib.invalidate_caches()
for p in [services.ServiceProvider]:
# This is marked as error in IDE, but it's not (__subclasses__)
for cls in p.__subclasses__():
# Skip ClusteredServiceProvider
services.factory().insert(cls)
__init__()
__loadModules()