Skip to content

Commit 868a573

Browse files
committed
Upload the python code...but it needs more work.
1 parent b834c35 commit 868a573

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

powerline_swissarmyknife/__init__.py

Whitespace-only changes.

powerline_swissarmyknife/execute.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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

Comments
 (0)