From 1dffb986b13814af91b76692a1db80f89d37ee93 Mon Sep 17 00:00:00 2001 From: Paul Barker Date: Fri, 16 Oct 2020 19:31:45 +0200 Subject: [PATCH] plugins: Move plugins to dedicated submodule This change groups the plugin modules together under kas.plugins and moves the @kasplugin decorator to this submodule. This will ensure the codebase stays organised as more plugins are added. Signed-off-by: Paul Barker Signed-off-by: Jan Kiszka --- kas/kas.py | 6 +++--- kas/libkas.py | 11 ----------- kas/plugins/__init__.py | 35 +++++++++++++++++++++++++++++++++++ kas/{ => plugins}/build.py | 17 +++++++++-------- kas/{ => plugins}/shell.py | 16 ++++++++-------- 5 files changed, 55 insertions(+), 30 deletions(-) create mode 100644 kas/plugins/__init__.py rename kas/{ => plugins}/build.py (89%) rename kas/{ => plugins}/shell.py (89%) diff --git a/kas/kas.py b/kas/kas.py index fac2e96..e9beff1 100644 --- a/kas/kas.py +++ b/kas/kas.py @@ -47,9 +47,9 @@ from . import __version__, __file_version__, __compatible_file_version__ # Import kas plugins # Since they are added by decorators, they don't need to be called, # just imported. -from .libkas import kasplugin -from . import build -from . import shell +from .plugins import kasplugin +from .plugins import build +from .plugins import shell __all__ = ['build', 'shell'] diff --git a/kas/libkas.py b/kas/libkas.py index eac0789..8979662 100644 --- a/kas/libkas.py +++ b/kas/libkas.py @@ -327,14 +327,3 @@ def ssh_no_host_key_check(): os.mkdir(home + '/.ssh') with open(home + '/.ssh/config', 'w') as fds: fds.write('Host *\n\tStrictHostKeyChecking no\n\n') - - -def kasplugin(plugin_class): - """ - A decorator that registers kas plugins - """ - if not hasattr(kasplugin, 'plugins'): - setattr(kasplugin, 'plugins', {}) - getattr(kasplugin, 'plugins').update({ - plugin_class.name: plugin_class - }) diff --git a/kas/plugins/__init__.py b/kas/plugins/__init__.py new file mode 100644 index 0000000..6c3e1b2 --- /dev/null +++ b/kas/plugins/__init__.py @@ -0,0 +1,35 @@ +# kas - setup tool for bitbake based projects +# +# Copyright (c) Siemens AG, 2017-2018 +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +""" + This module contains and manages kas plugins +""" + + +def kasplugin(plugin_class): + """ + A decorator that registers kas plugins + """ + if not hasattr(kasplugin, 'plugins'): + setattr(kasplugin, 'plugins', {}) + getattr(kasplugin, 'plugins').update({ + plugin_class.name: plugin_class + }) diff --git a/kas/build.py b/kas/plugins/build.py similarity index 89% rename from kas/build.py rename to kas/plugins/build.py index 6261a61..45b6dc3 100644 --- a/kas/build.py +++ b/kas/plugins/build.py @@ -27,14 +27,15 @@ import logging import os import subprocess import sys -from .context import create_global_context -from .config import Config -from .libkas import find_program, run_cmd, kasplugin -from .libcmds import (Macro, Command, SetupDir, CleanupSSHAgent, - SetupSSHAgent, SetupEnviron, - WriteBBConfig, SetupHome, ReposApplyPatches, - Loop, InitSetupRepos, FinishSetupRepos, - SetupReposStep) +from kas.context import create_global_context +from kas.config import Config +from kas.libkas import find_program, run_cmd +from kas.libcmds import (Macro, Command, SetupDir, CleanupSSHAgent, + SetupSSHAgent, SetupEnviron, + WriteBBConfig, SetupHome, ReposApplyPatches, + Loop, InitSetupRepos, FinishSetupRepos, + SetupReposStep) +from kas.plugins import kasplugin __license__ = 'MIT' __copyright__ = 'Copyright (c) Siemens AG, 2017-2018' diff --git a/kas/shell.py b/kas/plugins/shell.py similarity index 89% rename from kas/shell.py rename to kas/plugins/shell.py index 5bd0618..b60a01e 100644 --- a/kas/shell.py +++ b/kas/plugins/shell.py @@ -28,14 +28,14 @@ import logging import os import subprocess import sys -from .libkas import kasplugin -from .context import create_global_context -from .config import Config -from .libcmds import (Macro, Command, SetupDir, SetupEnviron, - WriteBBConfig, SetupHome, ReposApplyPatches, - CleanupSSHAgent, SetupSSHAgent, - Loop, InitSetupRepos, FinishSetupRepos, - SetupReposStep) +from kas.context import create_global_context +from kas.config import Config +from kas.libcmds import (Macro, Command, SetupDir, SetupEnviron, + WriteBBConfig, SetupHome, ReposApplyPatches, + CleanupSSHAgent, SetupSSHAgent, + Loop, InitSetupRepos, FinishSetupRepos, + SetupReposStep) +from kas.plugins import kasplugin __license__ = 'MIT' __copyright__ = 'Copyright (c) Siemens AG, 2017-2018'