Merge ~kissiel/checkbox-support:use-pactl-everywhere into checkbox-support:master

Proposed by Maciej Kisielewski
Status: Merged
Approved by: Sylvain Pineau
Approved revision: e07839e76f77627c0770911cb4eeb685088fffc3
Merged at revision: 30f3175d5f3588f34d074342bc541e619c043bea
Proposed branch: ~kissiel/checkbox-support:use-pactl-everywhere
Merge into: checkbox-support:master
Diff against target: 57 lines (+6/-6)
1 file modified
checkbox_support/scripts/audio_settings.py (+6/-6)
Reviewer Review Type Date Requested Status
Sylvain Pineau (community) Approve
Review via email: mp+312665@code.launchpad.net

Description of the change

Switch to pactl from pacmd required change in invocation of 'list devices'
and because pactl list formats output a bit different, so one regex also got
amended.

audio_settings controls the pulse server, not reconfigures it, so following
manpages, pactl is more suited to do it. Also, in pulseaudio-snappy, there is
only pactl.

This MR also fixes a small bug, where presense of --volume arg was checked by 'if not args.volume', which in case of setting volume to 0 failed.

Testing this is a bit of a pain, as the commands changed here are invoked on calling audio_setting's main with different `action`s in sys.argv.

What I did was:
python3 -c "import audio_settings; audio_settings.main()" store -f settings --verbose
python3 -c "import audio_settings; audio_settings.main()" restore -f settings --verbose
python3 -c "import audio_settings; audio_settings.main()" set (...)

and so on...

To post a comment you must log in.
Revision history for this message
Sylvain Pineau (sylvain-pineau) wrote :

+1, tested on 14.04, the same commands work ok.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/checkbox_support/scripts/audio_settings.py b/checkbox_support/scripts/audio_settings.py
2index a4000b5..f1ea9b7 100644
3--- a/checkbox_support/scripts/audio_settings.py
4+++ b/checkbox_support/scripts/audio_settings.py
5@@ -36,7 +36,7 @@ TYPES = ("source", "sink")
6 DIRECTIONS = {"source": "input", "sink": "output"}
7
8 default_pattern = "(?<=Default %s: ).*"
9-index_regex = re.compile("(?<=index: )[0-9]*")
10+index_regex = re.compile("(?<=Sink Input #)[0-9]*")
11 muted_regex = re.compile("(?<=Mute: ).*")
12 volume_regex = re.compile("Volume: (?:0|front-left):[\s\/0-9]*\s([0-9]*)")
13 name_regex = re.compile("(?<=Name:).*")
14@@ -185,7 +185,7 @@ def restore_profiles_settings(profiles_file):
15
16
17 def move_sinks(name):
18- sink_inputs = check_output(["pacmd", "list-sink-inputs"],
19+ sink_inputs = check_output(["pactl", "list", "sink-inputs"],
20 universal_newlines=True,
21 env=unlocalized_env())
22 input_indexes = index_regex.findall(sink_inputs)
23@@ -193,7 +193,7 @@ def move_sinks(name):
24 for input_index in input_indexes:
25 try:
26 with open(os.devnull, 'wb') as DEVNULL:
27- check_call(["pacmd", "move-sink-input", input_index, name],
28+ check_call(["pactl", "move-sink-input", input_index, name],
29 stdout=DEVNULL)
30 except CalledProcessError:
31 logging.error("Failed to move input %d to sink %d" %
32@@ -252,7 +252,7 @@ def set_audio_settings(device, mute, volume):
33 logging.info("[ Fallback sink ]".center(80, '='))
34 logging.info("Name: {}".format(name))
35 with open(os.devnull, 'wb') as DEVNULL:
36- check_call(["pacmd", "set-default-%s" % type, name],
37+ check_call(["pactl", "set-default-%s" % type, name],
38 stdout=DEVNULL)
39 except CalledProcessError:
40 logging.error("Failed to set default %s" % type)
41@@ -303,7 +303,7 @@ def restore_audio_settings(file):
42
43 try:
44 with open(os.devnull, 'wb') as DEVNULL:
45- check_call(["pacmd", "set-default-%s" % type, name],
46+ check_call(["pactl", "set-default-%s" % type, name],
47 stdout=DEVNULL)
48 except CalledProcessError:
49 logging.error("Failed to restore default %s" % name)
50@@ -370,7 +370,7 @@ def main():
51 if not args.device:
52 logging.error("No device specified to change settings of!")
53 return 1
54- if not args.volume:
55+ if args.volume is None:
56 logging.error("No volume level specified!")
57 return 1
58

Subscribers

People subscribed via source and target branches