forked from mk-fg/fgtk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpa_modtoggle
executable file
·36 lines (30 loc) · 1.16 KB
/
pa_modtoggle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python3
from pulsectl import Pulse
import os, sys
def main(args=None):
import argparse
parser = argparse.ArgumentParser(
description='Tool to toggle module loading/unloading with same one command.')
parser.add_argument('module', help='Module name to toggle.')
parser.add_argument('params', nargs='*', help='Module parameters, if any.')
parser.add_argument('-s', '--status', action='store_true',
help='Do not load/unload anything, only show whether module is loaded and exit.')
opts = parser.parse_args(sys.argv[1:] if args is None else args)
with Pulse('pa-modtoggle') as pulse:
loaded = mod = None
for mod in pulse.module_list():
if mod.name == opts.module:
loaded = True
break
else: loaded = False
if opts.status:
print('Module {!r} status: {}'.format(
opts.module, ['disabled', 'enabled'][bool(loaded)] ))
else:
if loaded:
print('Unloaded: [{}] {} {}'.format(mod.index, mod.name, mod.argument))
pulse.module_unload(mod.index)
else:
index = pulse.module_load(opts.module, opts.params)
print('Loaded: [{}] {} {}'.format(index, opts.module, ' '.join(opts.params)))
if __name__ == '__main__': sys.exit(main())