From a7717db9cc25e7fdbfb3370238db123e9176e10d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A5=D0=B8=D1=80=D0=B5=D1=86=D0=BA=D0=B8=D0=B9=20=D0=9C?= =?UTF-8?q?=D0=B8=D1=85=D0=B0=D0=B8=D0=BB?= Date: Thu, 11 Apr 2013 12:06:39 +0400 Subject: [PATCH] Add audio variable --- install/variables/system.py | 61 ++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/install/variables/system.py b/install/variables/system.py index 184f651..7e3c498 100644 --- a/install/variables/system.py +++ b/install/variables/system.py @@ -19,7 +19,8 @@ import sys import re from os import path from calculate.lib.datavars import Variable,VariableError,ReadonlyVariable, \ - TableVariable,PasswordError + TableVariable,PasswordError, \ + ReadonlyTableVariable,FieldValue from calculate.install.fs_manager import FileSystemManager from calculate.lib.utils.files import (readFile,getProgPath,process, readLinesFile) @@ -650,3 +651,61 @@ class VariableOsInstallGrubTerminal(Variable): def choice(self): return ['gfxterm','console'] + +class VariableOsAudioData(ReadonlyTableVariable): + """ + Information about audio cards + """ + source = ['os_audio_id', + 'os_audio_name'] + + def get(self,hr=False): + """LVM hash""" + aplay = getProgPath('/usr/bin/aplay') + if not aplay: + return [[]] + entry = re.compile('^card (\d+): ([^,]+)') + return tuple(map(lambda x:x.groups(), + filter(None,map(entry.search, + process(aplay,'-l'))))) + + setValue = Variable.setValue + +class VariableOsAudioId(FieldValue,ReadonlyVariable): + """ + Order Id of audio card + """ + type = "list" + source_variable = "os_audio_data" + column = 0 + +class VariableOsAudioName(FieldValue,ReadonlyVariable): + """ + Name of audio card + """ + type = "list" + source_variable = "os_audio_data" + column = 1 + +class VariableOsAudioDefault(Variable): + """ + Current default audio card + """ + type = "choice" + opt = ['--audio'] + + def init(self): + self.label = _("Default audio card") + self.help = _("set default audio card") + + def get(self): + defaultCardRe = re.compile('defaults.ctl.card\s+(\d+)') + entry = defaultCardRe.search(readFile('/etc/asound.conf')) + if entry and entry in self.Get('os_audio_id'): + return entry.groups()[0] + res = self.Select('os_audio_id',where='os_audio_name', + notlike='HDMI',limit=1) + return res or '0' + + def choice(self): + return self.Get('os_audio_data')