34 lines
1 KiB
Python
34 lines
1 KiB
Python
|
#!/usr/bin/env python
|
||
|
|
||
|
import subprocess
|
||
|
from functools import partial
|
||
|
|
||
|
|
||
|
cmd_run = partial(subprocess.Popen, text=True, shell=True)
|
||
|
|
||
|
def cmd_output(cmd):
|
||
|
try:
|
||
|
out = subprocess.check_output(cmd, text=True, shell=True).strip()
|
||
|
except Exception:
|
||
|
out = ''
|
||
|
return out
|
||
|
|
||
|
def execute(cmd):
|
||
|
popen = subprocess.Popen(cmd, stdout=subprocess.PIPE,
|
||
|
universal_newlines=True, text=True, shell=True)
|
||
|
for stdout_line in iter(popen.stdout.readline, ''):
|
||
|
yield stdout_line
|
||
|
popen.stdout.close()
|
||
|
return_code = popen.wait()
|
||
|
if return_code:
|
||
|
raise subprocess.CalledProcessError(return_code, cmd)
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
for event in execute('bspc subscribe node'):
|
||
|
event = event.split()
|
||
|
if event[0] == 'node_remove' or event[0] == 'node_transfer':
|
||
|
if cmd_output('bspc query -D --names -d ' + event[2]) == 'side-view':
|
||
|
if cmd_output('bspc query -N -d side-view') == '':
|
||
|
cmd_run('bspc desktop voip -f')
|
||
|
|