execute the command in the shell
(self, templater=None, debug=False)
| 60 | return args |
| 61 | |
| 62 | def execute(self, templater=None, debug=False): |
| 63 | """execute the command in the shell""" |
| 64 | ret = 1 |
| 65 | action = self.action |
| 66 | if templater: |
| 67 | action = self._get_action(templater, debug) |
| 68 | args = self._get_args(templater) |
| 69 | if debug and args: |
| 70 | self.log.dbg('action args:') |
| 71 | for cnt, arg in enumerate(args): |
| 72 | self.log.dbg(f'\targs[{cnt}]: {arg}') |
| 73 | try: |
| 74 | cmd = action.format(*args) |
| 75 | except IndexError as exc: |
| 76 | err = f'index error for {self.descr}: \"{action}\"' |
| 77 | err += f' with \"{args}\"' |
| 78 | err += f': {exc}' |
| 79 | self.log.warn(err) |
| 80 | return False |
| 81 | except KeyError as exc: |
| 82 | err = f'key error for {self.descr}: \"{action}\": {exc}' |
| 83 | err += f' with \"{args}\"' |
| 84 | self.log.warn(err) |
| 85 | return False |
| 86 | if self.silent: |
| 87 | self.log.sub(f'executing silent action \"{self.key}\"') |
| 88 | if debug: |
| 89 | self.log.dbg('action cmd silenced') |
| 90 | else: |
| 91 | if debug: |
| 92 | self.log.dbg(f'action cmd: \"{cmd}\"') |
| 93 | self.log.sub(f'executing \"{cmd}\"') |
| 94 | try: |
| 95 | shellexec = os.environ.get("SHELL", "/bin/sh") |
| 96 | ret = subprocess.call(cmd, shell=True, executable=shellexec) |
| 97 | except KeyboardInterrupt: |
| 98 | self.log.warn(f'{self.descr} interrupted') |
| 99 | if ret != 0: |
| 100 | self.log.warn(f'{self.descr} returned code {ret}') |
| 101 | return ret == 0 |
| 102 | |
| 103 | @classmethod |
| 104 | def _adjust_yaml_keys(cls, value): |