2017-02-21 13:37:11 +00:00
|
|
|
# Copyright 2013-2015 ARM Limited
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
#
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
class __LoaderWrapper(object):
|
|
|
|
|
2017-03-06 11:10:25 +00:00
|
|
|
@property
|
|
|
|
def kinds(self):
|
|
|
|
if not self._loader:
|
|
|
|
self.reset()
|
|
|
|
return self._loader.kind_map.keys()
|
|
|
|
|
|
|
|
@property
|
|
|
|
def kind_map(self):
|
|
|
|
if not self._loader:
|
|
|
|
self.reset()
|
|
|
|
return self._loader.kind_map
|
|
|
|
|
2017-02-21 13:37:11 +00:00
|
|
|
def __init__(self):
|
|
|
|
self._loader = None
|
|
|
|
|
|
|
|
def reset(self):
|
2017-03-06 11:10:25 +00:00
|
|
|
# These imports cannot be done at top level, because of
|
2017-02-21 13:37:11 +00:00
|
|
|
# sys.modules manipulation below
|
|
|
|
from wa.framework.plugin import PluginLoader
|
|
|
|
from wa.framework.configuration.core import settings
|
|
|
|
self._loader = PluginLoader(settings.plugin_packages,
|
2018-04-10 10:16:06 +01:00
|
|
|
settings.plugin_paths, [])
|
2017-02-21 13:37:11 +00:00
|
|
|
|
|
|
|
def update(self, packages=None, paths=None, ignore_paths=None):
|
2017-03-06 11:10:25 +00:00
|
|
|
if not self._loader:
|
|
|
|
self.reset()
|
2017-02-21 13:37:11 +00:00
|
|
|
self._loader.update(packages, paths, ignore_paths)
|
|
|
|
|
|
|
|
def reload(self):
|
2017-03-06 11:10:25 +00:00
|
|
|
if not self._loader:
|
|
|
|
self.reset()
|
2017-02-21 13:37:11 +00:00
|
|
|
self._loader.reload()
|
|
|
|
|
|
|
|
def list_plugins(self, kind=None):
|
2017-03-06 11:10:25 +00:00
|
|
|
if not self._loader:
|
|
|
|
self.reset()
|
2017-02-21 13:37:11 +00:00
|
|
|
return self._loader.list_plugins(kind)
|
|
|
|
|
|
|
|
def has_plugin(self, name, kind=None):
|
2017-03-06 11:10:25 +00:00
|
|
|
if not self._loader:
|
|
|
|
self.reset()
|
2017-02-21 13:37:11 +00:00
|
|
|
return self._loader.has_plugin(name, kind)
|
|
|
|
|
|
|
|
def get_plugin_class(self, name, kind=None):
|
2017-03-06 11:10:25 +00:00
|
|
|
if not self._loader:
|
|
|
|
self.reset()
|
|
|
|
return self._loader.get_plugin_class(name, kind)
|
2017-02-21 13:37:11 +00:00
|
|
|
|
2017-03-06 11:10:25 +00:00
|
|
|
def get_plugin(self, name=None, kind=None, *args, **kwargs):
|
|
|
|
if not self._loader:
|
|
|
|
self.reset()
|
|
|
|
return self._loader.get_plugin(name=name, kind=kind, *args, **kwargs)
|
2017-02-21 13:37:11 +00:00
|
|
|
|
|
|
|
def get_default_config(self, name):
|
2017-03-06 11:10:25 +00:00
|
|
|
if not self._loader:
|
|
|
|
self.reset()
|
2017-02-21 13:37:11 +00:00
|
|
|
return self._loader.get_default_config(name)
|
|
|
|
|
|
|
|
def resolve_alias(self, name):
|
2017-03-06 11:10:25 +00:00
|
|
|
if not self._loader:
|
|
|
|
self.reset()
|
2017-02-21 13:37:11 +00:00
|
|
|
return self._loader.resolve_alias(name)
|
|
|
|
|
|
|
|
def __getattr__(self, name):
|
2017-03-06 11:10:25 +00:00
|
|
|
if not self._loader:
|
|
|
|
self.reset()
|
2017-02-21 13:37:11 +00:00
|
|
|
return getattr(self._loader, name)
|
|
|
|
|
|
|
|
|
2017-03-06 11:10:25 +00:00
|
|
|
sys.modules[__name__] = __LoaderWrapper()
|