def __init__(self, type, number): self.device = '%s%s' % (type, number) self.configured = True # create config group self.config = Group(desc='%s card %s' % (type.upper(), number), schema =[ Var(name='priority', default=5, desc='priority of the card'), Var(name='activate', default=True, desc='Set activate to False if the card should not be used') ])
class DeviceInterface(object): """ Base class for tv cards. """ suffix = 'unknown' def __init__(self, type, number): self.device = '%s%s' % (type, number) self.configured = True # create config group self.config = Group(desc='%s card %s' % (type.upper(), number), schema =[ Var(name='priority', default=5, desc='priority of the card'), Var(name='activate', default=True, desc='Set activate to False if the card should not be used') ]) def _cfg_set_default(self, key, value): """ Set new default value. """ return self.config._cfg_get(key)._cfg_set(value, default=True) def _cfg_add(self, var): """ Add a new variable or group to the config. The parameter 'var' can also be a list of variables to add. """ if isinstance(var, (list, tuple)): for v in var: self.config.add_variable(v._name, v) return return self.config.add_variable(var._name, var) def __getattr__(self, attr): """ Get an attribute. If the attribute is in the config variable return this, it not use instance object. """ return getattr(self.config, attr) def __setattr__(self, attr, value): """ Set an attribute. If the attribute is in the config variable set this, it not use instance object. """ if not attr.startswith('_') and hasattr(self, 'config') and \ hasattr(self.config, attr): return setattr(self.config, attr, value) super(DeviceInterface, self).__setattr__(attr, value) def __str__(self): """ Return a string with some basic information about the card. """ s = 'Priority: %s\n' % self.priority if self.activate: return s + 'Status: ready to use\n' elif not self.configured: return s + 'Status: needs configuration\n' else: return s + 'Status: deactivated\n'
# -*- coding: iso-8859-1 -*- from kaa.config import Var, Group, Dict, List, Config def config_change_cb(name, oldval, newval): print "******* CFG ITEM CHANGE", name, oldval, newval config = Config(desc='basic config group', schema=[ Var(name='foo', desc='some text', default=5), Var(name='bar', default=u'bar', desc='more text\ndescription has two lines'), # group defined inside the basic schema Group(name='inline', desc='this is a subgroup', schema=[ Var(name='x', desc='desc_x', default=7 ), Var(name='y', type=range(0,5), desc='desc_y', default=3 ) ]) ]) # create extra group and add it to the schema subgroup = Group(desc='this is a subgroup', schema=[ Var(name='x', desc=u'desc_x with non ascii ü', default=7 ), # the next variable allows numbers from 0-4 Var(name='y', type=range(0,5), desc='desc_y', default=3 ) ]) config.add_variable('subgroup', subgroup) # create a group again deeper in the tree subsubgroup = Group(desc='desrc of subsubgroup', schema=[ Var(name='a', desc='desc a', default=3 ) ]) subgroup.add_variable('z', subsubgroup)
from kaa.config import Var, Group, Dict, Config config = Config(desc='mplayer configuration', schema=[ Var(name='activate', desc='activate backend', default=True), Dict(name='dict', schema=Var(default=''), defaults={ 'x': 'foo', 'y': 'yyy' }), Dict(name='dictgroup', schema=Group(schema=[ Var(name='x', default=True), Var(name='y', default=True) ])), Dict(name='dictdict', schema=Dict(name='foo', schema=Var(default=''))) ]) config.dict['f'] = 'd' config.dict['z'] = 'j' config.dictdict['a']['f'] = 'd' config.dictdict['b']['z'] = 'j' config.dictgroup['c'].x = False config.dictgroup['d'].y = 'j' print config.dictdict['a']['f']
import kaa from kaa.config import Config, Group, Var # tvdev imports from device import DVBCard # get logging object log = logging.getLogger('tvdev') # config object config = Config(schema=[]) rpcgroup = Group( desc='Remote access to the server', schema=[ Var(name='address', default='127.0.0.1:7600', desc='IP address and port to use for inter-process communication'), Var(name='password', default='', desc='Password to secure the communication') ]) config.add_variable(name='rpc', value=rpcgroup) config.add_variable(name='directory', value=Var(default=os.path.expanduser('~/Videos'), desc='Default recording directory')) # list of detected cards log.info('Detecting DVB cards.') info = [] for i in range(10): if os.path.isdir('/dev/dvb/adapter%s' % i): try: