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
diff --git a/checkbox_support/scripts/audio_settings.py b/checkbox_support/scripts/audio_settings.py
index a4000b5..f1ea9b7 100644
--- a/checkbox_support/scripts/audio_settings.py
+++ b/checkbox_support/scripts/audio_settings.py
@@ -36,7 +36,7 @@ TYPES = ("source", "sink")
36DIRECTIONS = {"source": "input", "sink": "output"}36DIRECTIONS = {"source": "input", "sink": "output"}
3737
38default_pattern = "(?<=Default %s: ).*"38default_pattern = "(?<=Default %s: ).*"
39index_regex = re.compile("(?<=index: )[0-9]*")39index_regex = re.compile("(?<=Sink Input #)[0-9]*")
40muted_regex = re.compile("(?<=Mute: ).*")40muted_regex = re.compile("(?<=Mute: ).*")
41volume_regex = re.compile("Volume: (?:0|front-left):[\s\/0-9]*\s([0-9]*)")41volume_regex = re.compile("Volume: (?:0|front-left):[\s\/0-9]*\s([0-9]*)")
42name_regex = re.compile("(?<=Name:).*")42name_regex = re.compile("(?<=Name:).*")
@@ -185,7 +185,7 @@ def restore_profiles_settings(profiles_file):
185185
186186
187def move_sinks(name):187def move_sinks(name):
188 sink_inputs = check_output(["pacmd", "list-sink-inputs"],188 sink_inputs = check_output(["pactl", "list", "sink-inputs"],
189 universal_newlines=True,189 universal_newlines=True,
190 env=unlocalized_env())190 env=unlocalized_env())
191 input_indexes = index_regex.findall(sink_inputs)191 input_indexes = index_regex.findall(sink_inputs)
@@ -193,7 +193,7 @@ def move_sinks(name):
193 for input_index in input_indexes:193 for input_index in input_indexes:
194 try:194 try:
195 with open(os.devnull, 'wb') as DEVNULL:195 with open(os.devnull, 'wb') as DEVNULL:
196 check_call(["pacmd", "move-sink-input", input_index, name],196 check_call(["pactl", "move-sink-input", input_index, name],
197 stdout=DEVNULL)197 stdout=DEVNULL)
198 except CalledProcessError:198 except CalledProcessError:
199 logging.error("Failed to move input %d to sink %d" %199 logging.error("Failed to move input %d to sink %d" %
@@ -252,7 +252,7 @@ def set_audio_settings(device, mute, volume):
252 logging.info("[ Fallback sink ]".center(80, '='))252 logging.info("[ Fallback sink ]".center(80, '='))
253 logging.info("Name: {}".format(name))253 logging.info("Name: {}".format(name))
254 with open(os.devnull, 'wb') as DEVNULL:254 with open(os.devnull, 'wb') as DEVNULL:
255 check_call(["pacmd", "set-default-%s" % type, name],255 check_call(["pactl", "set-default-%s" % type, name],
256 stdout=DEVNULL)256 stdout=DEVNULL)
257 except CalledProcessError:257 except CalledProcessError:
258 logging.error("Failed to set default %s" % type)258 logging.error("Failed to set default %s" % type)
@@ -303,7 +303,7 @@ def restore_audio_settings(file):
303303
304 try:304 try:
305 with open(os.devnull, 'wb') as DEVNULL:305 with open(os.devnull, 'wb') as DEVNULL:
306 check_call(["pacmd", "set-default-%s" % type, name],306 check_call(["pactl", "set-default-%s" % type, name],
307 stdout=DEVNULL)307 stdout=DEVNULL)
308 except CalledProcessError:308 except CalledProcessError:
309 logging.error("Failed to restore default %s" % name)309 logging.error("Failed to restore default %s" % name)
@@ -370,7 +370,7 @@ def main():
370 if not args.device:370 if not args.device:
371 logging.error("No device specified to change settings of!")371 logging.error("No device specified to change settings of!")
372 return 1372 return 1
373 if not args.volume:373 if args.volume is None:
374 logging.error("No volume level specified!")374 logging.error("No volume level specified!")
375 return 1375 return 1
376376

Subscribers

People subscribed via source and target branches