Skip to content

Commit

Permalink
Merge pull request #63 from seibert-media/fku-feature-environment-RUN…
Browse files Browse the repository at this point in the history
…NING_INSIDE_AUTOMATIX

command.Command._run_local_command(): add environment variable RUNNING_INSIDE_AUTOMATIX=1
  • Loading branch information
MaZderMind authored Aug 6, 2024
2 parents 893997d + e30a097 commit f9ecef6
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions automatix/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,15 +263,28 @@ def _build_command(self, path: str) -> str:
return f'. {path}/' + f'; . {path}/'.join(self.env.imports) + '; ' + self.get_resolved_value()

def _run_local_command(self, cmd: str) -> int:
self.env.LOG.debug(f'Executing: {cmd}')
process_environment = os.environ.copy()
process_environment['RUNNING_INSIDE_AUTOMATIX'] = '1'
self.env.LOG.debug(f'Executing: {repr(cmd)} with environment {repr(process_environment)}')
if self.assignment_var:
proc = subprocess.run(cmd, shell=True, executable=SHELL_EXECUTABLE, stdout=subprocess.PIPE)
proc = subprocess.run(
cmd,
env=process_environment,
executable=SHELL_EXECUTABLE,
shell=True,
stdout=subprocess.PIPE,
)
output = proc.stdout.decode(self.env.config["encoding"])
self.env.vars[self.assignment_var] = assigned_value = output.rstrip('\r\n')
hint = ' (trailing newline removed)' if (output.endswith('\n') or output.endswith('\r')) else ''
self.env.LOG.info(f'Variable {self.assignment_var} = "{assigned_value}"{hint}')
else:
proc = subprocess.run(cmd, shell=True, executable=SHELL_EXECUTABLE)
proc = subprocess.run(
cmd,
env=process_environment,
executable=SHELL_EXECUTABLE,
shell=True,
)
return proc.returncode

def _remote_action(self) -> int:
Expand Down

0 comments on commit f9ecef6

Please # to comment.