Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWalter Bender <walter.bender@gmail.com>2012-06-25 15:06:39 (GMT)
committer Walter Bender <walter.bender@gmail.com>2012-06-25 15:06:39 (GMT)
commit887d33729b936c620a9fa6baff7c936d75844ea0 (patch)
treeb343bea305e50caf28c8805fee76eeda928dd323
parent328df5f39546f88a1887a7fb7fde9fd6dbf0cbae (diff)
added support for commands in situations where subprocesss.check_output is not available (old systems)
-rw-r--r--audiograb.py129
1 files changed, 67 insertions, 62 deletions
diff --git a/audiograb.py b/audiograb.py
index 6f349ea..5f72543 100644
--- a/audiograb.py
+++ b/audiograb.py
@@ -585,17 +585,13 @@ class AudioGrab():
def amixer_set(self, control, state):
''' Direct call to amixer for old systems. '''
if state:
- try:
- output = subprocess.check_output(
- ['amixer', 'set', "%s" % (control), 'unmute'])
- except subprocess.CalledProcessError:
- log.warning('Problem with amixer set "%s" unmute' % (control))
+ output = check_output(
+ ['amixer', 'set', "%s" % (control), 'unmute'],
+ 'Problem with amixer set "%s" unmute' % (control))
else:
- try:
- output = subprocess.check_output(
- ['amixer', 'set', "%s" % (control), 'mute'])
- except subprocess.CalledProcessError:
- log.warning('Problem with amixer set "%s" mute' % (control))
+ output = check_output(
+ ['amixer', 'set', "%s" % (control), 'mute'],
+ 'Problem with amixer set "%s" mute' % (control))
def mute_master(self):
'''Mutes the Master Control'''
@@ -618,11 +614,9 @@ class AudioGrab():
if self._labels_available:
self._set_volume(self._master_control, 'Master', master_val)
else:
- try:
- output = subprocess.check_output(
- ['amixer', 'set', 'Master', "%d%s" % (master_val, '%')])
- except subprocess.CalledProcessError:
- log.warning('Problem with amixer set Master')
+ output = check_output(
+ ['amixer', 'set', 'Master', "%d%s" % (master_val, '%')],
+ 'Problem with amixer set Master')
def get_master(self):
'''Gets the MIC gain slider settings. The value returned is an
@@ -631,15 +625,15 @@ class AudioGrab():
if self._labels_available:
return self._get_volume(self._master_control, 'master')
else:
- try:
- output = subprocess.check_output(['amixer', 'get', 'Master'])
+ output = check_output(['amixer', 'get', 'Master'],
+ 'amixer: Could not get Master volume')
+ if output is None:
+ return 100
+ else:
output = output[find(output, 'Front Left:'):]
output = output[find(output, '[') + 1:]
output = output[:find(output, '%]')]
return int(output)
- except subprocess.CalledProcessError:
- log.warning('amixer: Could not get Master volume')
- return 100
def set_bias(self, bias_state=False):
'''Enables / disables bias voltage.'''
@@ -686,18 +680,17 @@ class AudioGrab():
return False
return True
else:
- try:
- output = subprocess.check_output(['amixer', 'get',
- "V_REFOUT Enable"])
+ output = check_output(['amixer', 'get', "V_REFOUT Enable"],
+ 'amixer: Could not get mic bias voltage')
+ if output is None:
+ return False
+ else:
output = output[find(output, 'Mono:'):]
output = output[find(output, '[') + 1:]
output = output[:find(output, ']')]
if output == 'on':
return True
return False
- except subprocess.CalledProcessError:
- log.warning('amixer: Could not get mic bias voltage')
- return False
def set_dc_mode(self, dc_mode=False):
'''Sets the DC Mode Enable control
@@ -717,18 +710,17 @@ class AudioGrab():
else:
return False
else:
- try:
- output = subprocess.check_output(['amixer', 'get',
- "DC Mode Enable"])
+ output = check_output(['amixer', 'get', "DC Mode Enable"],
+ 'amixer: Could not get DC Mode')
+ if output is None:
+ return False
+ else:
output = output[find(output, 'Mono:'):]
output = output[find(output, '[') + 1:]
output = output[:find(output, ']')]
if output == 'on':
return True
return False
- except subprocess.CalledProcessError:
- log.warning('amixer: Could not get DC Mode')
- return False
def set_mic_boost(self, mic_boost=False):
'''Set Mic Boost.
@@ -774,18 +766,17 @@ class AudioGrab():
return True
return False
else:
- try:
- output = subprocess.check_output(['amixer', 'get',
- "Mic Boost (+20dB)"])
+ output = check_output(['amixer', 'get', "Mic Boost (+20dB)"],
+ 'amixer: Could not get mic boost')
+ if output is None:
+ return False
+ else:
output = output[find(output, 'Mono:'):]
output = output[find(output, '[') + 1:]
output = output[:find(output, ']')]
if output == 'on':
return True
return False
- except subprocess.CalledProcessError:
- log.warning('amixer: Could not get mic boost')
- return False
def set_capture_gain(self, capture_val):
'''Sets the Capture gain slider settings capture_val must be
@@ -795,11 +786,9 @@ class AudioGrab():
if self._capture_control is not None:
self._set_volume(self._capture_control, 'Capture', capture_val)
else:
- try:
- output = subprocess.check_output(
- ['amixer', 'set', 'Capture', "%d%s" % (capture_val, '%')])
- except subprocess.CalledProcessError:
- log.warning('Problem with amixer set Capture')
+ output = check_output(
+ ['amixer', 'set', 'Capture', "%d%s" % (capture_val, '%')],
+ 'Problem with amixer set Capture')
def get_capture_gain(self):
'''Gets the Capture gain slider settings. The value returned
@@ -811,17 +800,15 @@ class AudioGrab():
else:
return 0
else:
- try:
- output = subprocess.check_output(['amixer', 'get', 'Capture'])
+ output = check_output(['amixer', 'get', 'Capture'],
+ 'amixer: Could not get Capture level')
+ if output is None:
+ return 100
+ else:
output = output[find(output, 'Front Left:'):]
output = output[find(output, '[') + 1:]
output = output[:find(output, '%]')]
return int(output)
- except subprocess.CalledProcessError:
- debug_output('amixer: Could not get Capture level',
- self.parent.running_sugar)
- log.warning('amixer: Could not get Capture level')
- return 100
def set_mic_gain(self, mic_val):
'''Sets the MIC gain slider settings mic_val must be given as
@@ -830,11 +817,9 @@ class AudioGrab():
if self._labels_available and self.activity.hw != XO1:
self._set_volume(self._mic_gain_control, 'Mic', mic_val)
else:
- try:
- output = subprocess.check_output(
- ['amixer', 'set', 'Mic', "%d%s" % (mic_val, '%')])
- except subprocess.CalledProcessError:
- log.warning('Problem with amixer set Mic')
+ output = check_output(
+ ['amixer', 'set', 'Mic', "%d%s" % (mic_val, '%')],
+ 'Problem with amixer set Mic')
def get_mic_gain(self):
'''Gets the MIC gain slider settings. The value returned is an
@@ -843,17 +828,15 @@ class AudioGrab():
if self._labels_available:
return self._get_volume(self._mic_gain_control, 'Mic')
else:
- try:
- output = subprocess.check_output(['amixer', 'get', 'Mic'])
+ output = check_output(['amixer', 'get', 'Mic'],
+ 'amixer: Could not get mic gain level')
+ if output is None:
+ return 100
+ else:
output = output[find(output, 'Mono:'):]
output = output[find(output, '[') + 1:]
output = output[:find(output, '%]')]
return int(output)
- except subprocess.CalledProcessError:
- debug_output('amixer: Could not get Mic level',
- self.parent.running_sugar)
- log.warning('amixer: Could not get mic gain level')
- return 100
def set_sensor_type(self, sensor_type=SENSOR_AC_BIAS):
'''Set the type of sensor you want to use. Set sensor_type according
@@ -970,3 +953,25 @@ class AudioGrab_Unknown(AudioGrab):
log.debug('Set Sensor Type to %s' % (str(sensor_type)))
mode, bias, gain, boost = PARAMETERS[sensor_type]
self._set_sensor_type(mode, bias, gain, boost)
+
+
+def check_output(command, warning):
+ ''' Workaround for old systems without subprocess.check_output'''
+ if hasattr(subprocess, 'check_output'):
+ try:
+ output = subprocess.check_output(command)
+ except subprocess.CalledProcessError:
+ log.warning(warning)
+ return None
+ else:
+ import commands
+
+ cmd = ''
+ for c in command:
+ cmd += c
+ cmd += ' '
+ (status, output) = commands.getstatusoutput(cmd)
+ if status != 0:
+ log.warning(warning)
+ return None
+ return output