context: Provide global instance
This will avoid the increasingly ugly pushing around of a context instance as parameter to various methods/functions. Everyone can now simply call get_context() after build or shell called create_global_context(). Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
This commit is contained in:
parent
3fccd1ad3e
commit
594fa97692
@ -24,7 +24,7 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from .context import Context
|
from .context import create_global_context
|
||||||
from .libkas import find_program, run_cmd, kasplugin
|
from .libkas import find_program, run_cmd, kasplugin
|
||||||
from .libcmds import (Macro, Command, SetupDir, CleanupSSHAgent,
|
from .libcmds import (Macro, Command, SetupDir, CleanupSSHAgent,
|
||||||
SetupSSHAgent, SetupEnviron, SetupRepos,
|
SetupSSHAgent, SetupEnviron, SetupRepos,
|
||||||
@ -71,7 +71,7 @@ class Build:
|
|||||||
if args.cmd != 'build':
|
if args.cmd != 'build':
|
||||||
return False
|
return False
|
||||||
|
|
||||||
ctx = Context(args.config, args.target, args.task)
|
ctx = create_global_context(args.config, args.target, args.task)
|
||||||
|
|
||||||
macro = Macro()
|
macro = Macro()
|
||||||
|
|
||||||
|
@ -48,6 +48,25 @@ except ImportError:
|
|||||||
# pylint: disable=deprecated-method
|
# pylint: disable=deprecated-method
|
||||||
return platform.dist()[0]
|
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
|
# pylint: disable=too-many-instance-attributes
|
||||||
class Context:
|
class Context:
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
import subprocess
|
import subprocess
|
||||||
import os
|
import os
|
||||||
from .libkas import kasplugin
|
from .libkas import kasplugin
|
||||||
from .context import Context
|
from .context import create_global_context
|
||||||
from .libcmds import (Macro, Command, SetupDir, SetupEnviron,
|
from .libcmds import (Macro, Command, SetupDir, SetupEnviron,
|
||||||
WriteBBConfig, SetupHome, ReposApplyPatches,
|
WriteBBConfig, SetupHome, ReposApplyPatches,
|
||||||
CleanupSSHAgent, SetupSSHAgent, SetupRepos)
|
CleanupSSHAgent, SetupSSHAgent, SetupRepos)
|
||||||
@ -75,7 +75,7 @@ class Shell:
|
|||||||
if args.cmd != 'shell':
|
if args.cmd != 'shell':
|
||||||
return False
|
return False
|
||||||
|
|
||||||
ctx = Context(args.config, args.target, None)
|
ctx = create_global_context(args.config, args.target, None)
|
||||||
|
|
||||||
macro = Macro()
|
macro = Macro()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user