summaryrefslogtreecommitdiff
path: root/src/test/test_amixer.py
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2021-11-27 16:17:05 +0300
committerEvgeny Zinoviev <me@ch1p.io>2022-04-24 01:33:04 +0300
commitc412bf2ee0a3fbf9032fc32a26837d4fbc7585c5 (patch)
tree5cca6bcab79331ad82cab4219c7692b9dd4eea21 /src/test/test_amixer.py
initial public
Diffstat (limited to 'src/test/test_amixer.py')
-rwxr-xr-xsrc/test/test_amixer.py79
1 files changed, 79 insertions, 0 deletions
diff --git a/src/test/test_amixer.py b/src/test/test_amixer.py
new file mode 100755
index 0000000..ac96881
--- /dev/null
+++ b/src/test/test_amixer.py
@@ -0,0 +1,79 @@
+#!/usr/bin/env python3
+import sys, os.path
+sys.path.extend([
+ os.path.realpath(os.path.join(os.path.dirname(os.path.join(__file__)), '..', '..')),
+])
+
+from argparse import ArgumentParser
+from src.home.config import config
+from src.home.sound import amixer
+
+
+def validate_control(input: str):
+ for control in config['amixer']['controls']:
+ if control['name'] == input:
+ return
+ raise ValueError(f'invalid control name: {input}')
+
+
+if __name__ == '__main__':
+ parser = ArgumentParser()
+ parser.add_argument('--get-all', action='store_true')
+ parser.add_argument('--mute', type=str)
+ parser.add_argument('--unmute', type=str)
+ parser.add_argument('--cap', type=str)
+ parser.add_argument('--nocap', type=str)
+ parser.add_argument('--get', type=str)
+ parser.add_argument('--incr', type=str)
+ parser.add_argument('--decr', type=str)
+ # parser.add_argument('--dump-config', action='store_true')
+
+ args = config.load('test_amixer', parser=parser)
+
+ # if args.dump_config:
+ # print(config.data)
+ # sys.exit()
+
+ if args.get_all:
+ for control in amixer.get_all():
+ print(f'control = {control["name"]}')
+ for line in control['info'].split('\n'):
+ print(f' {line}')
+ print()
+ sys.exit()
+
+ if args.get:
+ info = amixer.get(args.get)
+ print(info)
+ sys.exit()
+
+ for action in ['incr', 'decr']:
+ if hasattr(args, action):
+ control = getattr(args, action)
+ if control is None:
+ continue
+
+ print(f'attempting to {action} {control}')
+ validate_control(control)
+ func = getattr(amixer, action)
+ try:
+ func(control, step=5)
+ except amixer.AmixerError as e:
+ print('error: ' + str(e))
+ sys.exit()
+
+ for action in ['mute', 'unmute', 'cap', 'nocap']:
+ if hasattr(args, action):
+ control = getattr(args, action)
+ if control is None:
+ continue
+
+ print(f"attempting to {action} {control}")
+
+ validate_control(control)
+ func = getattr(amixer, action)
+ try:
+ func(control)
+ except amixer.AmixerError as e:
+ print('error: ' + str(e))
+ sys.exit()