2015-06-04 18:42:08 +02:00
|
|
|
import csv
|
|
|
|
import ConfigParser
|
2017-04-16 17:40:53 +02:00
|
|
|
import apparatinterface
|
2015-06-04 18:42:08 +02:00
|
|
|
import phoneinterface
|
2017-04-27 21:19:26 +02:00
|
|
|
import statemachine
|
2015-06-04 18:42:08 +02:00
|
|
|
|
|
|
|
class ConfigurationReader(object):
|
2017-04-27 00:47:53 +02:00
|
|
|
DEFAULTS = {
|
|
|
|
'gpio_numbering': 'BOARD',
|
|
|
|
'pin_nsa': '11',
|
|
|
|
'pin_nsi': '13',
|
|
|
|
'pin_gabelschalter': '15',
|
|
|
|
'pin_schauzeichen': '12',
|
|
|
|
'pin_wecker_enable': '16',
|
|
|
|
'pin_wecker_a': '18',
|
|
|
|
'pin_wecker_b': '19',
|
|
|
|
'invert_gs' : 'false',
|
|
|
|
|
|
|
|
'default_proxy': ''
|
|
|
|
}
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.__cp = ConfigParser.ConfigParser(defaults=ConfigurationReader.DEFAULTS)
|
2017-04-28 18:48:22 +02:00
|
|
|
self.pinconfig = None
|
|
|
|
self.dialconfig = None
|
|
|
|
self.phoneconfig = None
|
2017-04-27 00:47:53 +02:00
|
|
|
|
|
|
|
def __get_global_val(self, option):
|
|
|
|
return self.__cp.get('fetapd', option)
|
|
|
|
|
|
|
|
def __get_global_val_int(self, option):
|
|
|
|
return int(self.__cp.get('fetapd', option))
|
|
|
|
|
|
|
|
def __get_global_val_bool(self, option):
|
|
|
|
return self.__cp.get('fetapd', option).lower() in ['true', 'yes', '1']
|
|
|
|
|
|
|
|
def __get_proxy_val(self, proxyname, option):
|
|
|
|
return self.__cp.get('proxy_'+proxyname, option)
|
|
|
|
|
|
|
|
def __get_proxy_val_int(self, proxyname, option):
|
|
|
|
return self.__cp.getint('proxy_'+proxyname, option)
|
|
|
|
|
|
|
|
def __read_shortcuts(self):
|
|
|
|
fname = self.__get_global_val('shortcuts_file')
|
|
|
|
shortcuts = {}
|
|
|
|
with open(fname, 'r') as csvfile:
|
|
|
|
for row in csv.DictReader(csvfile):
|
|
|
|
print 'row', row
|
|
|
|
shortcuts[row['shortcut']] = row['number']
|
|
|
|
print 'shortcuts:', shortcuts
|
|
|
|
return shortcuts
|
|
|
|
|
|
|
|
def __read_blacklist(self):
|
|
|
|
fname = self.__get_global_val('blacklist_file')
|
|
|
|
blacklist = []
|
|
|
|
with open(fname, 'r') as csvfile:
|
|
|
|
for row in csv.DictReader(csvfile):
|
|
|
|
blacklist.append(row['number'])
|
|
|
|
return blacklist
|
|
|
|
|
|
|
|
def read(self, f):
|
|
|
|
self.__cp.read(f)
|
|
|
|
|
|
|
|
print 'pin_nsa:', self.__get_global_val_int('pin_nsa'),
|
2017-04-28 18:48:22 +02:00
|
|
|
self.pinconfig = apparatinterface.FeApPinConfiguration(
|
2017-04-27 00:47:53 +02:00
|
|
|
gpio_numbering = self.__get_global_val('gpio_numbering'),
|
|
|
|
pin_nsa = self.__get_global_val_int('pin_nsa'),
|
|
|
|
pin_nsi = self.__get_global_val_int('pin_nsi'),
|
|
|
|
pin_gabelschalter = self.__get_global_val_int('pin_gabelschalter'),
|
|
|
|
pin_schauzeichen = self.__get_global_val_int('pin_schauzeichen'),
|
|
|
|
pin_wecker_enable = self.__get_global_val_int('pin_wecker_enable'),
|
|
|
|
pin_wecker_a = self.__get_global_val_int('pin_wecker_a'),
|
|
|
|
pin_wecker_b = self.__get_global_val_int('pin_wecker_b'),
|
|
|
|
invert_gs = self.__get_global_val_bool('invert_gs'),
|
|
|
|
)
|
|
|
|
|
2017-04-28 18:48:22 +02:00
|
|
|
self.dialconfig = statemachine.DialConfiguration(
|
2017-04-27 00:47:53 +02:00
|
|
|
self.__get_global_val_int('dial_timeout'),
|
|
|
|
self.__read_shortcuts(),
|
|
|
|
self.__read_blacklist(),
|
|
|
|
)
|
|
|
|
|
|
|
|
proxyconfigs = []
|
|
|
|
for secname in self.__cp.sections():
|
|
|
|
if secname.startswith('proxy_'):
|
|
|
|
proxyname = secname[6:]
|
|
|
|
proxyconfig = phoneinterface.PhoneProxyConfiguration(
|
|
|
|
name = proxyname,
|
|
|
|
proxy = self.__get_proxy_val(proxyname, 'proxy'),
|
|
|
|
identity = self.__get_proxy_val(proxyname, 'identity'),
|
|
|
|
username = self.__get_proxy_val(proxyname, 'username'),
|
|
|
|
password = self.__get_proxy_val(proxyname, 'password'),
|
|
|
|
realm = self.__get_proxy_val(proxyname, 'realm'),
|
|
|
|
prefix = self.__get_proxy_val(proxyname, 'prefix')
|
|
|
|
)
|
|
|
|
proxyconfigs.append(proxyconfig)
|
|
|
|
|
2017-04-28 18:48:22 +02:00
|
|
|
self.phoneconfig = phoneinterface.PhoneConfiguration(
|
2017-04-27 00:47:53 +02:00
|
|
|
sound_device = self.__get_global_val('sound_device'),
|
|
|
|
incoming_timeout = self.__get_global_val_int('incoming_timeout'),
|
|
|
|
linphone_config = self.__get_global_val('linphone_config'),
|
|
|
|
default_proxy = self.__get_global_val('default_proxy'),
|
|
|
|
stun_server = self.__get_global_val('stun_server'),
|
|
|
|
proxies = proxyconfigs
|
|
|
|
)
|
|
|
|
|