diff --git a/kas/build.py b/kas/build.py index d802c5f..d0b5155 100644 --- a/kas/build.py +++ b/kas/build.py @@ -24,7 +24,7 @@ """ import os -from .context import Context +from .context import create_global_context from .libkas import find_program, run_cmd, kasplugin from .libcmds import (Macro, Command, SetupDir, CleanupSSHAgent, SetupSSHAgent, SetupEnviron, SetupRepos, @@ -71,7 +71,7 @@ class Build: if args.cmd != 'build': return False - ctx = Context(args.config, args.target, args.task) + ctx = create_global_context(args.config, args.target, args.task) macro = Macro() diff --git a/kas/context.py b/kas/context.py index 9168f82..418e756 100644 --- a/kas/context.py +++ b/kas/context.py @@ -48,6 +48,25 @@ except ImportError: # pylint: disable=deprecated-method return platform.dist()[0] +__context__ = None + + +def create_global_context(config_filename, bitbake_target, bitbake_task): + """ + Create global context as singleton. + """ + # pylint: disable=global-statement + global __context__ + __context__ = Context(config_filename, bitbake_target, bitbake_task) + return __context__ + + +def get_context(): + """ + Return singleton global context. + """ + return __context__ + # pylint: disable=too-many-instance-attributes class Context: diff --git a/kas/shell.py b/kas/shell.py index d74d2a5..84261f8 100644 --- a/kas/shell.py +++ b/kas/shell.py @@ -27,7 +27,7 @@ import subprocess import os from .libkas import kasplugin -from .context import Context +from .context import create_global_context from .libcmds import (Macro, Command, SetupDir, SetupEnviron, WriteBBConfig, SetupHome, ReposApplyPatches, CleanupSSHAgent, SetupSSHAgent, SetupRepos) @@ -75,7 +75,7 @@ class Shell: if args.cmd != 'shell': return False - ctx = Context(args.config, args.target, None) + ctx = create_global_context(args.config, args.target, None) macro = Macro()