cras_utils: Fix pylint errors and blank lines
Fix the blank lines and some pylint errors.
BUG=None
TEST=run pylint on cras_utils.py
Change-Id: I8a39b234fe9a508d86fe788a683d19e805e66fe7
Reviewed-on: https://chromium-review.googlesource.com/257943
Reviewed-by: Kalin Stoyanov <kalin@chromium.org>
Commit-Queue: Cheng-Yi Chiang <cychiang@chromium.org>
Tested-by: Cheng-Yi Chiang <cychiang@chromium.org>
diff --git a/client/cros/audio/cras_utils.py b/client/cros/audio/cras_utils.py
index e53e11d..0f4b801 100644
--- a/client/cros/audio/cras_utils.py
+++ b/client/cros/audio/cras_utils.py
@@ -2,10 +2,11 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+"""This module provides cras audio utilities."""
+
import logging
import re
-from autotest_lib.client.bin import utils
from autotest_lib.client.cros.audio import cmd_utils
_CRAS_TEST_CLIENT = '/usr/bin/cras_test_client'
@@ -17,10 +18,12 @@
"""A helper function to execute the playback_cmd."""
cmd_utils.execute(playback_cmd(*args, **kargs))
+
def capture(*args, **kargs):
"""A helper function to execute the capture_cmd."""
cmd_utils.execute(capture_cmd(*args, **kargs))
+
def playback_cmd(playback_file, block_size=None, duration=None,
channels=2, rate=48000):
"""Gets a command to playback a file with given settings.
@@ -30,6 +33,7 @@
@param block_size: the number of frames per callback(dictates latency).
@param duration: seconds to playback
@param rate: the sampling rate
+
"""
args = [_CRAS_TEST_CLIENT]
args += ['--playback_file', playback_file]
@@ -41,6 +45,7 @@
args += ['--rate', str(rate)]
return args
+
def capture_cmd(
capture_file, block_size=None, duration=10, channels=1, rate=48000):
"""Gets a command to capture the audio into the file with given settings.
@@ -51,6 +56,7 @@
and command will keep capturing audio until it is
terminated.
@param rate: the sampling rate.
+
"""
args = [_CRAS_TEST_CLIENT]
args += ['--capture_file', capture_file]
@@ -75,6 +81,7 @@
@param channels: The number of channels of the recorded audio.
@param duration: seconds to record.
@param rate: the sampling rate.
+
"""
args = [_CRAS_TEST_CLIENT]
args += ['--loopback_file', output_file]
@@ -88,34 +95,42 @@
"""Set the system volume.
@param volume: the system output vlume to be set(0 - 100).
+
"""
args = [_CRAS_TEST_CLIENT]
args += ['--volume', str(volume)]
cmd_utils.execute(args)
+
def set_node_volume(node_id, volume):
"""Set the volume of the given output node.
@param node_id: the id of the output node to be set the volume.
@param volume: the volume to be set(0-100).
+
"""
args = [_CRAS_TEST_CLIENT]
args += ['--set_node_volume', '%s:%d' % (node_id, volume)]
cmd_utils.execute(args)
+
def set_capture_gain(gain):
"""Set the system capture gain.
+
@param gain the capture gain in db*100 (100 = 1dB)
+
"""
args = [_CRAS_TEST_CLIENT]
args += ['--capture_gain', str(gain)]
cmd_utils.execute(args)
+
def dump_server_info():
"""Gets the CRAS's server information."""
args = [_CRAS_TEST_CLIENT, '--dump_server_info']
return cmd_utils.execute(args, stdout=cmd_utils.PIPE)
+
def get_selected_nodes():
"""Returns the pair of active output node and input node."""
server_info = dump_server_info()
@@ -132,6 +147,7 @@
"""Sets the selected output node volume.
@param volume: the volume to be set (0-100).
+
"""
selected_output_node_id, _ = get_selected_nodes()
set_node_volume(selected_output_node_id, volume)
@@ -143,7 +159,7 @@
match = _RE_NUM_ACTIVE_STREAM.search(server_info)
if not match:
logging.error(server_info)
- raise RuntimeException('Cannot find matched pattern')
+ raise RuntimeError('Cannot find matched pattern')
return int(match.group(1))
@@ -151,6 +167,7 @@
"""Sets the system mute switch.
@param is_mute: Set True to mute the system playback.
+
"""
args = [_CRAS_TEST_CLIENT, '--mute', '1' if is_mute else '0']
cmd_utils.execute(args)
@@ -160,6 +177,7 @@
"""Sets the capture mute switch.
@param is_mute: Set True to mute the capture.
+
"""
args = [_CRAS_TEST_CLIENT, '--capture_mute', '1' if is_mute else '0']
cmd_utils.execute(args)
@@ -188,6 +206,7 @@
@returns: True if there is any node of node_type plugged. False otherwise.
@raises: ValueError: if cras server info format is not as expected.
+
"""
# The label line
# ID Vol Plugged L/R swapped Time Type Name