|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# |
| 3 | +# slotmachine_oneline.py |
| 4 | +# Copyright (C) 2019 Miguel de Dios Matias |
| 5 | +# |
| 6 | +# This program is free software: you can redistribute it and/or modify |
| 7 | +# it under the terms of the GNU General Public License as published by |
| 8 | +# the Free Software Foundation, either version 3 of the License, or |
| 9 | +# any later version. |
| 10 | +# |
| 11 | +# This program is distributed in the hope that it will be useful, |
| 12 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +# GNU General Public License for more details. |
| 15 | +# |
| 16 | +# You should have received a copy of the GNU General Public License |
| 17 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | + |
| 19 | +import subprocess |
| 20 | + |
| 21 | +def execute(pl, commandLine='', line='{preContent}{output}{err}{postContent}', successCodes=None, failureCode=None, preContent='', postContent='🧰', *args, **kwargs): |
| 22 | + result = subprocess.run(commandLine, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 23 | + |
| 24 | + returncode = result.returncode |
| 25 | + output = result.stdout.decode('utf8') |
| 26 | + err = result.stderr.decode('utf8') |
| 27 | + |
| 28 | + color = ['information:regular'] |
| 29 | + if isinstance(successCodes, list): |
| 30 | + if returncode in successCodes: |
| 31 | + color = ['critical:success'] |
| 32 | + elif isinstance(failureCode, list): |
| 33 | + if returncode in failureCode: |
| 34 | + color = ['critical:failure'] |
| 35 | + |
| 36 | + return [{ |
| 37 | + 'contents': line.format(preContent=preContent, output=output, err=err, postContent=postContent), |
| 38 | + 'highlight_groups': color, |
| 39 | + 'divider_highlight_group': None}] |
| 40 | + |
0 commit comments