From 86dc584284d340f6fb53c03ed824b5c96e5d3686 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Fri, 24 Aug 2018 19:18:00 +0200 Subject: [PATCH] run_cmd: Default to environment from global context If env is not provided, use the global context environment. Then drop all every passing of that parameter. Signed-off-by: Jan Kiszka --- kas/build.py | 2 +- kas/libkas.py | 3 ++- kas/repos.py | 10 +++------- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/kas/build.py b/kas/build.py index bb9f430..03755f1 100644 --- a/kas/build.py +++ b/kas/build.py @@ -122,4 +122,4 @@ class BuildCommand(Command): bitbake = find_program(ctx.environ['PATH'], 'bitbake') run_cmd(([bitbake, '-k', '-c', ctx.config.get_bitbake_task()] + ctx.config.get_bitbake_targets()), - env=ctx.environ, cwd=ctx.build_dir) + cwd=ctx.build_dir) diff --git a/kas/libkas.py b/kas/libkas.py index df751fb..b651d77 100644 --- a/kas/libkas.py +++ b/kas/libkas.py @@ -31,6 +31,7 @@ import tempfile import asyncio import errno from subprocess import Popen, PIPE +from .context import get_context __license__ = 'MIT' __copyright__ = 'Copyright (c) Siemens AG, 2017' @@ -92,7 +93,7 @@ def run_cmd_async(cmd, cwd, env=None, fail=True, shell=False, liveupdate=True): # https://github.com/PyCQA/pylint/issues/996. # pylint: disable=not-an-iterable - env = env or {} + env = env or get_context().environ cmdstr = cmd if not shell: cmdstr = ' '.join(cmd) diff --git a/kas/repos.py b/kas/repos.py index c00b63d..f4888e9 100644 --- a/kas/repos.py +++ b/kas/repos.py @@ -163,7 +163,6 @@ class RepoImpl(Repo): logging.debug('Looking for repo ref dir in %s', sdir) (retc, _) = yield from run_cmd_async(self.clone_cmd(sdir, ctx), - env=ctx.environ, cwd=ctx.kas_work_dir) if retc == 0: logging.info('Repository %s cloned', self.name) @@ -175,7 +174,6 @@ class RepoImpl(Repo): # Does refspec exist in the current repository? (retc, output) = yield from run_cmd_async(self.contains_refspec_cmd(), - env=ctx.environ, cwd=self.path, fail=False, liveupdate=False) @@ -186,7 +184,6 @@ class RepoImpl(Repo): # No it is missing, try to fetch (retc, output) = yield from run_cmd_async(self.fetch_cmd(), - env=ctx.environ, cwd=self.path, fail=False) if retc: @@ -196,7 +193,7 @@ class RepoImpl(Repo): logging.info('Repository %s updated', self.name) return 0 - def checkout(self, ctx): + def checkout(self, _): """ Checks out the correct revision of the repo. """ @@ -205,7 +202,7 @@ class RepoImpl(Repo): # Check if repos is dirty (_, output) = run_cmd(self.is_dirty_cmd(), - env=ctx.environ, cwd=self.path, + cwd=self.path, fail=False) if output: logging.warning('Repo %s is dirty. no checkout', self.name) @@ -213,7 +210,7 @@ class RepoImpl(Repo): # Check if current HEAD is what in the config file is defined. (_, output) = run_cmd(self.current_rev_cmd(), - env=ctx.environ, cwd=self.path) + cwd=self.path) if output.strip() == self.refspec: logging.info('Repo %s has already checkout out correct ' @@ -258,7 +255,6 @@ class RepoImpl(Repo): continue (retc, output) = yield from run_cmd_async(cmd, - env=ctx.environ, cwd=self.path, fail=False) # pylint: disable=no-else-return