Beispiel #1
0
    def check_config(self):
        """
		Checks to see if the config has the required XMPP fields filled out accordingly.
		Then, it evaluates the config file to make sure that all fields exist, at least corresponding to the
		example config file.
		"""
        conf = self.configuration

        if conf.has_section('xmpp'):
            if all(
                    conf.has_option('xmpp', k) and conf.get('xmpp', k)
                    for k in MANDATORY_XMPP_OPTIONS):
                self.xmpp_config_ok = True

        def_conf = ConfigParser()
        def_conf.read(DEFAULT_CONFIG_PATH)

        for section in def_conf.sections():
            if conf.has_section(section):
                for option in def_conf.options(section):
                    if not conf.has_option(section, option) or conf.get(
                            section, option) is None:
                        conf.set(section, option,
                                 def_conf.get(section, option))
            else:
                conf.add_section(section)
                for option in def_conf.options(section):
                    conf.set(section, option, def_conf.get(section, option))

        self.configuration = conf
        self.configuration.write()
Beispiel #2
0
def GetCharacterIni(configname):
    config = ConfigParser()
    config.read("./characters/"+configname)
    dictionary = {}
    for section in config.sections():
        dictionary[section] = {}
        for option in config.options(section):
            dictionary[section][option] = config.get(section, option)
    return dictionary
Beispiel #3
0
def exec_legacy(arg):
    try:
        tmp = arg.split(":")
        if len(tmp) < 2:
            raise AssertionError("Error: incorrect service path: " + arg)
        app_name = tmp[0]
        app_path = tmp[1]

        # print "Service: app_name=",app_name," app_path=",app_path
        setup_logger(app_name)

        t = threading.Thread(target=alive_worker, args=(30.0, ))
        t.start()

        app_dir = os.path.join(mi2app_utils.get_files_dir(), "app")
        # add this dir to module search path
        sys.path.append(os.path.join(app_dir, app_path))
        app_file = os.path.join(app_dir, app_path, "main.mi2app")
        Logger.info("Phone model: " + mi2app_utils.get_phone_model())
        Logger.info("Running app: " + app_file)
        # print arg,app_dir,os.path.join(app_dir, arg)

        namespace = {"service_context": mi2app_utils.get_service_context()}

        # Load configurations as global variables
        config = ConfigParser()
        config.read('/sdcard/.mobileinsight.ini')

        ii = arg.rfind('/')
        section_name = arg[ii + 1:]

        plugin_config = {}
        if section_name in config.sections():
            config_options = config.options(section_name)
            for item in config_options:
                plugin_config[item] = config.get(section_name, item)

        namespace["plugin_config"] = plugin_config

        gps_provider = GpsListener(on_gps)
        gps_provider.start()

        execfile(app_file, namespace)

        # print app_name, "stops normally"

    except Exception as e:
        # Print traceback logs to analysis
        tb_exc = traceback.format_exc()
        Logger.error(tb_exc)
        l = logging.getLogger("mobileinsight_logger")
        l.error(tb_exc)
        sys.exit(tb_exc)
Beispiel #4
0
    def load_config(self):
        '''(internal) This function is used for returning a ConfigParser with
        the application configuration. It's doing 3 things:

            #. Creating an instance of a ConfigParser
            #. Loading the default configuration by calling
               :meth:`build_config`, then
            #. If it exists, it loads the application configuration file,
               otherwise it creates one.

        :return:
            :class:`~kivy.config.ConfigParser` instance
        '''
        try:
            config = ConfigParser.get_configparser('app')
        except KeyError:
            config = None
        if config is None:
            config = ConfigParser(name='app')
        self.config = config
        self.build_config(config)
        # if no sections are created, that's mean the user don't have
        # configuration.
        if len(config.sections()) == 0:
            return
        # ok, the user have some sections, read the default file if exist
        # or write it !
        filename = self.get_application_config()
        if filename is None:
            return config
        Logger.debug('App: Loading configuration <{0}>'.format(filename))
        if exists(filename):
            try:
                config.read(filename)
            except:
                Logger.error('App: Corrupted config file, ignored.')
                config.name = ''
                try:
                    config = ConfigParser.get_configparser('app')
                except KeyError:
                    config = None
                if config is None:
                    config = ConfigParser(name='app')
                self.config = config
                self.build_config(config)
                pass
        else:
            Logger.debug('App: First configuration, create <{0}>'.format(
                filename))
            config.filename = filename
            config.write()
        return config
Beispiel #5
0
    def load_config(self):
        '''(internal) This function is used for returning a ConfigParser with
        the application configuration. It's doing 3 things:

            #. Creating an instance of a ConfigParser
            #. Loading the default configuration by calling
               :meth:`build_config`, then
            #. If it exists, it loads the application configuration file,
               otherwise it creates one.

        :return:
            :class:`~kivy.config.ConfigParser` instance
        '''
        try:
            config = ConfigParser.get_configparser('app')
        except KeyError:
            config = None
        if config is None:
            config = ConfigParser(name='app')
        self.config = config
        self.build_config(config)
        # if no sections are created, that's mean the user don't have
        # configuration.
        if len(config.sections()) == 0:
            return
        # ok, the user have some sections, read the default file if exist
        # or write it !
        filename = self.get_application_config()
        if filename is None:
            return config
        Logger.debug('App: Loading configuration <{0}>'.format(filename))
        if exists(filename):
            try:
                config.read(filename)
            except:
                Logger.error('App: Corrupted config file, ignored.')
                config.name = ''
                try:
                    config = ConfigParser.get_configparser('app')
                except KeyError:
                    config = None
                if config is None:
                    config = ConfigParser(name='app')
                self.config = config
                self.build_config(config)
                pass
        else:
            Logger.debug('App: First configuration, create <{0}>'.format(
                filename))
            config.filename = filename
            config.write()
        return config
Beispiel #6
0
 def loadFromFile(self, file):
     if file[-3:] != 'ini':
         self.root.notification('Load', 'wrong file extension')
         return
     commands = ConfigParser()
     commands.read(file)
     try:
         for section in commands.sections():
             for values in commands.items(section):
                 self.commands.set(section, values[0], values[1])
                 if section in self.updateSettings.keys():
                     self.updateSettings[section].update({values[0]:values[1]})
                 else:
                     self.updateSettings.update({section:{values[0]:values[1]}})
         self.root.notification('Load', 'load successful')
         App.get_running_app().root.ids.settingsLayout.ids.option.setOptions()
     except:
         self.root.notification('Load', 'wrong file')
Beispiel #7
0
 def load_config(self):
     try:
         config = ConfigParser.get_configparser('app')
     except KeyError:
         config = None
     if config is None:
         config = ConfigParser(name='app')
     self.config = config
     self.build_config(config)
     # if no sections are created, that's mean the user don't have
     # configuration.
     if len(config.sections()) == 0:
         return
     # ok, the user have some sections, read the default file if exist
     # or write it !
     filename = self.get_application_config()
     if filename is None:
         return config
     Logger.debug('FlexApp: Loading configuration <{0}>'.format(filename))
     if exists(filename):
         try:
             config.read(filename)
         except:
             Logger.error('FlexApp: Corrupted config file, ignored.')
             config.name = ''
             try:
                 config = ConfigParser.get_configparser('app')
             except KeyError:
                 config = None
             if config is None:
                 config = ConfigParser(name='app')
             self.config = config
             self.build_config(config)
             pass
     else:
         Logger.debug('FlexApp: First configuration, create <{0}>'.format(
             filename))
         config.filename = filename
         config.write()
     return config
Beispiel #8
0
        app_file = os.path.join(app_dir, app_path, "main.mi2app")
        print "Phone model: " + mi2app_utils.get_phone_model()
        print "Running app: " + app_file
        # print arg,app_dir,os.path.join(app_dir, arg)

        namespace = {"service_context": mi2app_utils.get_service_context()}

        # Load configurations as global variables
        config = ConfigParser()
        config.read('/sdcard/.mobileinsight.ini')

        ii = arg.rfind('/')
        section_name = arg[ii + 1:]

        plugin_config = {}
        if section_name in config.sections():
            config_options = config.options(section_name)
            for item in config_options:
                plugin_config[item] = config.get(section_name, item)

        namespace["plugin_config"] = plugin_config
        #
        gps_provider = GpsListener(on_gps)
        gps_provider.start()

        execfile(app_file, namespace)

        # print app_name, "stops normally"

    except Exception as e:
        # print "Exceptions!!!"
Beispiel #9
0
class cScriptConfig(object):
    """ Class to manage the initialisation/configuration and access the the settings of an Script settings objects

    """
    def __init__(self, oScript):
        self.oScript = oScript
        self.oConfigParser = KivyConfigParser()
        self.oFnConfig = None
        self.uCurrentSection = None
        self.uDefaultConfigName = u'SCRIPTDEFAULT'
        self.aDiscoverScriptList = None
        self.oInputKeyboard = None
        self.dDefaultSettings = {
            "SettingTitle": {
                "active": "enabled",
                "order": 0,
                "type": "title",
                "title": "$lvar(560)"
            },
            "TimeOut": {
                "active": "disabled",
                "order": 1,
                "type": "numericfloat",
                "title": "$lvar(6019)",
                "desc": "$lvar(6020)",
                "section": "$var(ScriptConfigSection)",
                "key": "TimeOut",
                "default": "1.0"
            },
            "Host": {
                "active": "disabled",
                "order": 5,
                "type": "string",
                "title": "$lvar(6004)",
                "desc": "$lvar(6005)",
                "section": "$var(ScriptConfigSection)",
                "key": "Host",
                "default": "192.168.1.2"
            },
            "Port": {
                "active": "disabled",
                "order": 6,
                "type": "string",
                "title": "$lvar(6002)",
                "desc": "$lvar(6003)",
                "section": "$var(ScriptConfigSection)",
                "key": "Port",
                "default": "80"
            },
            "User": {
                "active": "disabled",
                "order": 7,
                "type": "string",
                "title": "$lvar(6006)",
                "desc": "$lvar(6007)",
                "section": "$var(ScriptConfigSection)",
                "key": "User",
                "default": ""
            },
            "Password": {
                "active": "disabled",
                "order": 8,
                "type": "string",
                "title": "$lvar(6008)",
                "desc": "$lvar(6009)",
                "section": "$var(ScriptConfigSection)",
                "key": "Password",
                "default": ""
            },
            "ConfigChangeButtons": {
                "active":
                "disabled",
                "order":
                999,
                "type":
                "buttons",
                "title":
                "$lvar(565)",
                "desc":
                "$lvar(566)",
                "section":
                "$var(ScriptConfigSection)",
                "key":
                "configchangebuttons",
                "buttons": [{
                    "title": "$lvar(569)",
                    "id": "button_add"
                }, {
                    "title": "$lvar(570)",
                    "id": "button_delete"
                }, {
                    "title": "$lvar(571)",
                    "id": "button_rename"
                }]
            },
        }

        self.dSettingsCombined = {}

    def Init(self):
        """ Init function, sets the configuration file name and add the default sections """

        self.oFnConfig = cFileName(self.oScript.oPathMy) + u'config.ini'
        if not self.oFnConfig.Exists():
            self.oConfigParser.filename = self.oFnConfig.string
            self.CreateSection(uSectionName=self.uDefaultConfigName)

    def LoadConfig(self):
        """ Loads the config file (only once) """

        try:
            self.oConfigParser.filename = self.oFnConfig.string
            if len(self.oConfigParser._sections) == 0:
                if self.oFnConfig.Exists():
                    self.oScript.ShowDebug(u'Reading Config File')
                    self.oConfigParser.read(self.oFnConfig.string)
        except Exception as e:
            self.oScript.ShowError(
                u"can\'t load config file: %s" % self.oFnConfig.string, None,
                e)

    def CreateSection(self, uSectionName):
        """
        Adds a new section to the config parser

        :param string uSectionName: The name of the section to create
        """
        self.oScript.ShowDebug('Adding new section [%s]' % (uSectionName))
        self.oConfigParser.add_section(uSectionName)
        self.oConfigParser.write()

    def GetSettingParFromIni(self, uSectionName, uVarName):
        """
        Returns a setting for the configuration ini file
        If the entry does not exist, it tries to puls the value from the  aInterFaceIniSettings dict of already predifined settings
        If not exist there as well, an error will be logged

        :rtype: string|None
        :param string uSectionName: The name of the section
        :param uVarName: The name of the parameter/setting in the section
        :return: The value of the setting, empty string if not found
         """

        oSetting = self.oScript.GetSettingObjectForConfigName(uSectionName)
        uResult = Config_GetDefault_Str(self.oConfigParser, uSectionName,
                                        uVarName, None)
        if uResult is None:
            uResult = str(oSetting.aScriptIniSettings.queryget(uVarName))
        if uResult is None:
            uResult = ''
            self.oScript.ShowError(u'can\'t find script setting: %s:%s' %
                                   (uSectionName, uVarName))
        else:
            self.oScript.ShowDebug(u'Returning script setting: %s from %s:%s' %
                                   (uResult, uSectionName, uVarName))
        return uResult

    def WriteDefinitionConfigPar(self,
                                 uSectionName,
                                 uVarName,
                                 uVarValue,
                                 bNowrite=False,
                                 bForce=False):
        """ Writes a variable to the config file
        :param string uSectionName: The name of the section
        :param string uVarName: The name of the parameter/setting in the section
        :param string uVarValue: The value for the setting
        :param bool bNowrite: Flag, if we should not immidiatly write the the setting
        :param bool bForce: Flag to force write, even if parameter exists in config
        """
        self.LoadConfig()
        if not self.oConfigParser.has_section(uSectionName):
            self.CreateSection(uSectionName=uSectionName)

        if self.oConfigParser.has_option(uSectionName, uVarName):
            if not bForce:
                return

        self.oConfigParser.set(uSectionName, uVarName, uVarValue)
        if not bNowrite:
            self.oConfigParser.write()

        for uSettingName in self.oScript.aSettings:
            oSetting = self.oScript.aSettings[uSettingName]
            if oSetting.uConfigName == uSectionName:
                oSetting.aScriptIniSettings[uVarName] = uVarValue
                break

    def WriteDefinitionConfig(self, uSectionName, dSettings):
        """
        writes all vars given in a dictionary to the config file

        :param string uSectionName: The name of the section
        :param dict dSettings: A dict of all settings to write
        """

        for uKey in dSettings:
            self.WriteDefinitionConfigPar(uSectionName=uSectionName,
                                          uVarName=uKey,
                                          uVarValue=dSettings[uKey],
                                          bNowrite=True)
        self.oConfigParser.write()

    def ConfigureKivySettings(self, oKivySetting):
        """
        Create the JSON string for all sections and applies it to a kivy settings object
        Discover settings are excluded

        :param setting oKivySetting:
        :return: The KivySetting object
        """
        RegisterSettingTypes(oKivySetting)
        aSections = self.oConfigParser.sections()
        if len(aSections) == 0:
            self.CreateSection(uSectionName=self.uDefaultConfigName)

        for uSection in aSections:
            # the Section list should be applied as a orca var
            SetVar(uVarName=u'ScriptConfigSection', oVarValue=uSection)
            # Let create a new temporary cSetting object to not harm the existing ones
            oSetting = self.oScript.cScriptSettings(self.oScript)
            # Read the ini file for this section
            oSetting.ReadConfigFromIniFile(uSection)
            # Create the setting string
            dSettingsJSON = self.CreateSettingJsonCombined(oSetting=oSetting)
            uSettingsJSON = SettingDictToString(dSettingsJSON)
            uSettingsJSON = ReplaceVars(uSettingsJSON)
            oSetting = None

            # if there is nothing to configure, then return
            if uSettingsJSON == u'{}':
                Globals.oNotifications.SendNotification('closesetting_script')
                return False

            # add the jSon to the Kivy Setting
            oKivySetting.add_json_panel(uSection,
                                        self.oConfigParser,
                                        data=uSettingsJSON)

        # Adds the action handler
        oKivySetting.bind(on_config_change=self.On_ConfigChange)
        return oKivySetting

    def On_ConfigChange(self, oSettings, oConfig, uSection, uKey, uValue):
        """ reacts, if user changes a setting """
        if uKey == u'configchangebuttons':
            self.uCurrentSection = uSection
            if uValue == u'button_add':
                SetVar(uVarName=u'SCRIPTINPUT', oVarValue=u'DEVICE_dummy')
                self.oInputKeyboard = ShowKeyBoard(u'SCRIPTINPUT',
                                                   self.On_InputAdd)
            if uValue == u'button_delete':
                ShowQuestionPopUp(
                    uTitle=u'$lvar(5003)',
                    uMessage=u'Do you really want to delete this setting?',
                    fktYes=self.On_InputDel,
                    uStringYes=u'$lvar(5001)',
                    uStringNo=u'$lvar(5002)')
            if uValue == u'button_rename':
                SetVar(uVarName=u'SCRIPTINPUT', oVarValue=uSection)
                self.oInputKeyboard = ShowKeyBoard(u'SCRIPTINPUT',
                                                   self.On_InputRen)
        else:
            oSetting = self.oScript.GetSettingObjectForConfigName(
                uConfigName=uSection)
            oSetting.aScriptIniSettings[uKey] = uValue

    def On_InputAdd(self, uInput):
        """ User pressed the add configuration button """
        if uInput == u'':
            return
        if self.oConfigParser.has_section(uInput):
            return
        self.oConfigParser.add_section(uInput)
        # self.InitializeSection(uInput)
        self.oConfigParser.write()
        Globals.oTheScreen.AddActionToQueue([{
            'string': 'updatewidget',
            'widgetname': 'Scriptsettings'
        }])
        self.ShowSettings()

    def On_InputDel(self):
        """ User pressed the del configuration button """
        self.oConfigParser.remove_section(self.uCurrentSection)
        self.oConfigParser.write()
        self.ShowSettings()

    def On_InputRen(self, uInput):
        """ User pressed the rename configuration button """
        if uInput == u'':
            return
        if self.oConfigParser.has_section(uInput):
            return
        self.oConfigParser._sections[uInput] = self.oConfigParser._sections[
            self.uCurrentSection]
        self.oConfigParser._sections.pop(self.uCurrentSection)
        self.oConfigParser.write()
        self.ShowSettings()

    def ShowSettings(self):
        """ Shows the settings page """
        Globals.oTheScreen.AddActionToQueue([{
            'string': 'updatewidget',
            'widgetname': 'Scriptsettings'
        }])

    def GetSettingParFromVar2(self, uScriptName, uConfigName, uSettingParName):
        """
        Gets a Value for a setting parameter from the orca vars
        The Orca vars fpr the parameter are automatically set in the cInterfaceMonitoredSettings class

        :rtype: string
        :param uScriptName: The name of script to use
        :param uConfigName: The nemae of the Config
        :param uSettingParName: The name of the parameter
        :return: The value of the parameter
        """

        return GetVar(uVarName="CONFIG_" + uSettingParName.upper(),
                      uContext=uScriptName + u'/' + uConfigName)

    def CreateSettingJsonCombined(self, oSetting):
        """
        Creates a json dict which holds all the setting defintions of
        the core interface plus the settinmgs from the discover script (if requested)

        :rtype: dict
        :param cBaseInterFaceSettings oSetting: an IterFaceSettins Object
        :return: a dict of combined settings
        """

        if len(self.dSettingsCombined) != 0:
            return self.dSettingsCombined
        dRet = {}

        for uKey in self.dDefaultSettings:
            if self.dDefaultSettings[uKey]["active"] != "disabled":
                dRet[uKey] = self.dDefaultSettings[uKey]

        dScriptJSON = self.oScript.GetConfigJSON()
        for uKey in dScriptJSON:
            dLine = dScriptJSON[uKey]
            iOrder = dLine['order']
            for uKey2 in dRet:
                if dRet[uKey2]['order'] >= iOrder:
                    dRet[uKey2]['order'] += 1
            dRet[uKey] = dLine

        self.dSettingsCombined = dRet
        return dRet
Beispiel #10
0
# ===========================
#   Control The Backlight 
# ===========================
def Backlight_Control(light_status):
   subproces.call('echo 0 > Light.SATUS')


# ========================
#    Load the Defaults
# ========================
config = ConfigParser()
config.read('doorbell.ini')

CODES = ConfigParser()
CODES.read('codes.ini')
CODES_DICT = {s:dict(CODES.items(s)) for s in CODES.sections()}

NUMBERS = ConfigParser()
NUMBERS.read('numbers.ini')
NUMBERS_DICT = {s:dict(NUMBERS.items(s)) for s in NUMBERS.sections()}

LANGUAGES = ConfigParser()
LANGUAGES.read('languages.ini')
LANGUAGES_DICT = {s:dict(LANGUAGES.items(s)) for s in LANGUAGES.sections()}


# ===========================
#   Load the Sound Effects
# ===========================

Sound_Click = SoundLoader.load(config.get('Sounds','Sound_Click')) 
Beispiel #11
0
class cInterFaceConfig(object):
    """ Class to manage the initialisation/configuration and access toe the settings of an Interface settings objects

    """
    def __init__(self, oInterFace):
        self.oInterFace = oInterFace
        self.oConfigParser = KivyConfigParser()
        self.oFnConfig = None
        self.uCurrentSection = None
        self.uDefaultConfigName = u'DEVICE_DEFAULT'
        self.aDiscoverScriptList = None
        self.oInputKeyboard = None
        self.dDefaultSettings = {
            "SettingTitle": {
                "active": "enabled",
                "order": 0,
                "type": "title",
                "title": "$lvar(560)"
            },
            "Host": {
                "active": "disabled",
                "order": 1,
                "type": "string",
                "title": "$lvar(6004)",
                "desc": "$lvar(6005)",
                "section": "$var(InterfaceConfigSection)",
                "key": "Host",
                "default": "192.168.1.2"
            },
            "Port": {
                "active": "disabled",
                "order": 2,
                "type": "string",
                "title": "$lvar(6002)",
                "desc": "$lvar(6003)",
                "section": "$var(InterfaceConfigSection)",
                "key": "Port",
                "default": "80"
            },
            "User": {
                "active": "disabled",
                "order": 3,
                "type": "string",
                "title": "$lvar(6006)",
                "desc": "$lvar(6007)",
                "section": "$var(InterfaceConfigSection)",
                "key": "User",
                "default": "root"
            },
            "Password": {
                "active": "disabled",
                "order": 4,
                "type": "string",
                "title": "$lvar(6008)",
                "desc": "$lvar(6009)",
                "section": "$var(InterfaceConfigSection)",
                "key": "Password",
                "default": ""
            },
            "FNCodeset": {
                "active": "disabled",
                "order": 5,
                "type": "scrolloptions",
                "title": "$lvar(6000)",
                "desc": "$lvar(6001)",
                "section": "$var(InterfaceConfigSection)",
                "key": "FNCodeset",
                "default": "Select",
                "options": ["$var(InterfaceCodesetList)"]
            },
            "ParseResult": {
                "active": "disabled",
                "order": 6,
                "type": "scrolloptions",
                "title": "$lvar(6027)",
                "desc": "$lvar(6028)",
                "section": "$var(InterfaceConfigSection)",
                "key": "ParseResult",
                "default": "store",
                "options": ["no", "tokenize", "store", "json", "dict", "xml"]
            },
            "TokenizeString": {
                "active": "disabled",
                "order": 7,
                "type": "string",
                "title": "$lvar(6029)",
                "desc": "$lvar(6030)",
                "section": "$var(InterfaceConfigSection)",
                "key": "TokenizeString",
                "default": ":"
            },
            "TimeOut": {
                "active": "disabled",
                "order": 8,
                "type": "numericfloat",
                "title": "$lvar(6019)",
                "desc": "$lvar(6020)",
                "section": "$var(InterfaceConfigSection)",
                "key": "TimeOut",
                "default": "1.0"
            },
            "TimeToClose": {
                "active": "disabled",
                "order": 9,
                "type": "numeric",
                "title": "$lvar(6010)",
                "desc": "$lvar(6011)",
                "section": "$var(InterfaceConfigSection)",
                "key": "TimeToClose",
                "default": "10"
            },
            "DisableInterFaceOnError": {
                "active": "disabled",
                "order": 10,
                "type": "bool",
                "title": "$lvar(529)",
                "desc": "$lvar(530)",
                "section": "$var(InterfaceConfigSection)",
                "key": "DisableInterFaceOnError",
                "default": "0"
            },
            "DisconnectInterFaceOnSleep": {
                "active": "disabled",
                "order": 11,
                "type": "bool",
                "title": "$lvar(533)",
                "desc": "$lvar(534)",
                "section": "$var(InterfaceConfigSection)",
                "key": "DisconnectInterFaceOnSleep",
                "default": "1"
            },
            "DiscoverSettingButton": {
                "active":
                "disabled",
                "order":
                12,
                "type":
                "buttons",
                "title":
                "$lvar(6033)",
                "desc":
                "$lvar(6034)",
                "section":
                "$var(InterfaceConfigSection)",
                "key":
                "DiscoverSettings",
                "buttons": [{
                    "title": "Discover Settings",
                    "id": "button_discover"
                }]
            },
            "ConfigChangeButtons": {
                "active":
                "enabled",
                "order":
                999,
                "type":
                "buttons",
                "title":
                "$lvar(565)",
                "desc":
                "$lvar(566)",
                "section":
                "$var(InterfaceConfigSection)",
                "key":
                "configchangebuttons",
                "buttons": [{
                    "title": "$lvar(569)",
                    "id": "button_add"
                }, {
                    "title": "$lvar(570)",
                    "id": "button_delete"
                }, {
                    "title": "$lvar(571)",
                    "id": "button_rename"
                }]
            }
        }

        self.dGenericDiscoverSettings = {
            "DiscoverScriptName": {
                "active": "hidden",
                "order": 100,
                "scriptsection": "$lvar(539)",
                "type": "scrolloptions",
                "title": "$lvar(6035)",
                "desc": "$lvar(6036)",
                "section": "$var(InterfaceConfigSection)",
                "key": "DiscoverScriptName",
                "default": "",
                "options": ["$var(DISCOVERSCRIPTLIST)"]
            },
            "SaveDiscoveredIP": {
                "active": "hidden",
                "order": 101,
                "scriptsection": "$lvar(539)",
                "type": "bool",
                "title": "$lvar(6031)",
                "desc": "$lvar(6032)",
                "section": "$var(InterfaceConfigSection)",
                "key": "SaveDiscoveredIP",
                "default": "1"
            },
            "OldDiscoveredIP": {
                "active": "hidden",
                "order": 102,
                "scriptsection": "$lvar(539)",
                "type": "string",
                "title": "$lvar(6021)",
                "desc": "$lvar(6022)",
                "section": "$var(InterfaceConfigSection)",
                "key": "OldDiscoveredIP",
                "default": ""
            },
            "CheckDiscoverButton": {
                "active":
                "disabled",
                "order":
                103,
                "scriptsection":
                "$lvar(539)",
                "type":
                "buttons",
                "title":
                "Check Discover",
                "desc":
                "$lvar(6034)",
                "section":
                "$var(InterfaceConfigSection)",
                "key":
                "CheckDiscover",
                "buttons": [{
                    "title": "Check Discover",
                    "id": "button_checkdiscover"
                }]
            },
        }
        self.dSettingsCombined = {}

    def Init(self):
        """ Init function, sets the configuration file name and add the default sections """

        self.oFnConfig = cFileName(self.oInterFace.oPathMy) + u'config.ini'
        if not self.oFnConfig.Exists():
            self.CreateSection(uSectionName=self.uDefaultConfigName)

    def LoadConfig(self):
        """ Loads the config file (only once) """

        try:
            self.oConfigParser.filename = self.oFnConfig.string
            if len(self.oConfigParser._sections) == 0:
                if self.oFnConfig.Exists():
                    self.oInterFace.ShowDebug(u'Reading Config File')
                    self.oConfigParser.read(self.oFnConfig.string)
            else:
                if not self.oFnConfig.Exists():
                    self.oConfigParser.write()
        except Exception as e:
            self.oInterFace.ShowError(
                u"can\'t load config file: %s" % self.oFnConfig.string, None,
                e)

    def CreateSection(self, uSectionName):
        """
        Adds a new section to the config parser

        :param string uSectionName: The name of the section to create
        """

        self.oInterFace.ShowDebug('Adding new section [%s]' % (uSectionName))
        self.oConfigParser.add_section(uSectionName)
        self.oConfigParser.write()

    def GetSettingParFromIni(self, uSectionName, uVarName):
        """
        Returns a setting for the configuration ini file
        If the entry does not exist, it tries to puls the value from the  aInterFaceIniSettings dict of already predifined settings
        If not exist there as well, an error will be logged

        :rtype: string|None
        :param string uSectionName: The name of the section
        :param uVarName: The name of the parameter/setting in the section
        :return: The value of the setting, empty string if not found
         """

        oSetting = self.oInterFace.GetSettingObjectForConfigName(uSectionName)
        uResult = Config_GetDefault_Str(self.oConfigParser, uSectionName,
                                        uVarName, None)
        if uResult is None:
            uResult = str(oSetting.aInterFaceIniSettings.queryget(uVarName))
        if uResult is None:
            uResult = ''
            self.oInterFace.ShowError(u'can\'t find interface setting: %s:%s' %
                                      (uSectionName, uVarName))
        else:
            self.oInterFace.ShowDebug(
                u'Returning interface setting: %s from %s:%s' %
                (uResult, uSectionName, uVarName))
        return uResult

    def WriteDefinitionConfigPar(self,
                                 uSectionName,
                                 uVarName,
                                 uVarValue,
                                 bNowrite=False,
                                 bForce=False):
        """ Writes a variable to the config file
        :param string uSectionName: The name of the section
        :param string uVarName: The name of the parameter/setting in the section
        :param string uVarValue: The value for the setting
        :param bool bNowrite: Flag, if we should not immidiatly write the the setting
        :param bool bForce: Flag to force write, even if parameter exists in config
        """
        self.LoadConfig()
        if not self.oConfigParser.has_section(uSectionName):
            self.CreateSection(uSectionName=uSectionName)

        if self.oConfigParser.has_option(uSectionName, uVarName):
            if not bForce:
                return

        self.oConfigParser.set(uSectionName, uVarName, uVarValue)
        if not bNowrite:
            self.oConfigParser.write()

        for uSettingName in self.oInterFace.aSettings:
            oSetting = self.oInterFace.aSettings[uSettingName]
            if oSetting.uConfigName == uSectionName:
                oSetting.aInterFaceIniSettings[uVarName] = uVarValue
                break

    def WriteDefinitionConfig(self, uSectionName, dSettings):
        """
        writes all vars given in a dictionary to the config file

        :param string uSectionName: The name of the section
        :param dict dSettings: A dict of all settings to write
        """

        for uKey in dSettings:
            self.WriteDefinitionConfigPar(uSectionName=uSectionName,
                                          uVarName=uKey,
                                          uVarValue=dSettings[uKey],
                                          bNowrite=True)
        self.oConfigParser.write()

    def ConfigureKivySettings(self, oKivySetting):
        """
        Create the JSON string for all sections and applies it to a kivy settings object
        Discover settings are excluded

        :param setting oKivySetting:
        :return: The KivySetting object
        """
        RegisterSettingTypes(oKivySetting)
        aSections = self.oConfigParser.sections()
        if len(aSections) == 0:
            self.CreateSection(uSectionName=self.uDefaultConfigName)

        # The Codeset List could be applied as a orca var, so set it to the list
        SetVar(uVarName=u'InterfaceCodesetList',
               oVarValue=self.oInterFace.CreateCodsetListJSONString())

        for uSection in aSections:
            # the Section list should be applied as a orca var
            SetVar(uVarName=u'InterfaceConfigSection', oVarValue=uSection)
            # Let create a new temporary cSetting object to not harm the existing ones
            oSetting = self.oInterFace.cInterFaceSettings(self.oInterFace)
            # Read the ini file for this section
            oSetting.ReadConfigFromIniFile(uSection)
            # Create the setting string
            dSettingsJSON = self.CreateSettingJsonCombined(
                oSetting=oSetting, bIncludeDiscoverSettings=False)
            uSettingsJSON = SettingDictToString(dSettingsJSON)
            uSettingsJSON = ReplaceVars(uSettingsJSON)
            oSetting = None

            # if there is nothing to configure, then return
            if uSettingsJSON == u'{}':
                Globals.oNotifications.SendNotification(
                    'closesetting_interface')
                return False

            # add the jSon to the Kivy Setting
            oKivySetting.add_json_panel(uSection,
                                        self.oConfigParser,
                                        data=uSettingsJSON)

        # Adds the action handler
        oKivySetting.bind(on_config_change=self.On_ConfigChange)
        return oKivySetting

    def On_ConfigChange(self, oSettings, oConfig, uSection, uKey, uValue):
        """
        reacts, if user changes a setting

        :param setting oSettings: The kivy settings object
        :param ConfigParser oConfig: The Kivy config parser
        :param string uSection: The section of the change
        :param string uKey: The key name
        :param string uValue: The value
        """
        if uKey == u'configchangebuttons':
            self.uCurrentSection = uSection
            if uValue == u'button_add':
                SetVar(uVarName=u'INTERFACEINPUT', oVarValue=u'DEVICE_dummy')
                self.oInputKeyboard = ShowKeyBoard(u'INTERFACEINPUT',
                                                   self.On_InputAdd)
            if uValue == u'button_delete':
                ShowQuestionPopUp(
                    uTitle=u'$lvar(5003)',
                    uMessage=u'Do you really want to delete this setting?',
                    fktYes=self.On_InputDel,
                    uStringYes=u'$lvar(5001)',
                    uStringNo=u'$lvar(5002)')
            if uValue == u'button_rename':
                SetVar(uVarName=u'INTERFACEINPUT', oVarValue=uSection)
                self.oInputKeyboard = ShowKeyBoard(u'INTERFACEINPUT',
                                                   self.On_InputRen)
        elif uKey == u'DiscoverSettings':
            Globals.oTheScreen.uConfigToConfig = uSection
            Globals.oTheScreen.AddActionShowPageToQueue(
                uPageName=u'Page_InterfaceSettingsDiscover')
        elif uKey == u'FNCodeset':
            oSetting = self.oInterFace.GetSettingObjectForConfigName(
                uConfigName=uSection)
            oSetting.aInterFaceIniSettings[uKey] = uValue
            oSetting.ReadCodeset()
        else:
            oSetting = self.oInterFace.GetSettingObjectForConfigName(
                uConfigName=uSection)
            oSetting.aInterFaceIniSettings[uKey] = uValue
            # ShowMessagePopUp(uMessage=u'$lvar(5011)')
            if uKey == u'FNCodeset':
                oSetting.ReadCodeset()

    def On_InputAdd(self, uInput):
        """
        User pressed the add configuration button

        :param string uInput: The Name of the section
        :return:
        """
        if uInput == u'':
            return
        if self.oConfigParser.has_section(uInput):
            return
        self.oConfigParser.add_section(uInput)
        self.oConfigParser.write()
        Globals.oTheScreen.AddActionToQueue([{
            'string': 'updatewidget',
            'widgetname': 'Interfacesettings'
        }])
        self.ShowSettings()

    def On_InputDel(self):
        """ User pressed the del configuration button """
        self.oConfigParser.remove_section(self.uCurrentSection)
        self.oConfigParser.write()
        self.ShowSettings()

    def On_InputRen(self, uInput):
        """ User pressed the rename configuration button """
        if uInput == u'':
            return
        if self.oConfigParser.has_section(uInput):
            return
        self.oConfigParser._sections[uInput] = self.oConfigParser._sections[
            self.uCurrentSection]
        self.oConfigParser._sections.pop(self.uCurrentSection)
        self.oConfigParser.write()
        self.ShowSettings()

    def ShowSettings(self):
        """ Shows the settings page """
        Globals.oTheScreen.AddActionToQueue([{
            'string': 'updatewidget',
            'widgetname': 'Interfacesettings'
        }])

    def GetSettingParFromVar2(self, uInterFaceName, uConfigName,
                              uSettingParName):
        """
        Gets a Value for a setting parameter from the orca vars
        The Orca vars fpr the parameter are automatically set in the cInterfaceMonitoredSettings class

        :rtype: string
        :param uInterFaceName: The name of interface to use
        :param uConfigName: The nemae of the Config
        :param uSettingParName: The name of the parameter
        :return: The value of the parameter
        """

        return GetVar(uVarName="CONFIG_" + uSettingParName.upper(),
                      uContext=uInterFaceName + u'/' + uConfigName)

    def GetSettingParFromVar(self, uLink):
        """
        Returns a setting var of a an other interface or config
        The Interfca emust already be initalized
        syntax should be: linked:interfacename:configname:varname

        :rtype: string
        :param string uLink: The link: syntax should be: linked:interfacename:configname:varname
        :return: The Value of the linked setting, empty string, if not found
        """

        aLinks = uLink.split(':')
        if len(aLinks) == 4:
            uInterFaceName = aLinks[1]
            uConfigName = aLinks[2]
            uSettingParName = aLinks[3]
            Globals.oInterFaces.LoadInterface(uInterFaceName)
            oInterface = Globals.oInterFaces.GetInterface(uInterFaceName)
            oSetting = oInterface.GetSettingObjectForConfigName(
                uConfigName=uConfigName)
            oSetting.Discover()
            return self.GetSettingParFromVar2(uInterFaceName=uInterFaceName,
                                              uConfigName=uConfigName,
                                              uSettingParName=uSettingParName)
        return ""

    def CreateSettingJsonCombined(self,
                                  oSetting,
                                  bIncludeDiscoverSettings=True):
        """
        Creates a json dict which holds all the setting defintions of
        the core interface plus the settings from the discover script (if requested)

        :rtype: dict
        :param cBaseInterFaceSettings oSetting: an IterFaceSettins Object
        :param bool bIncludeDiscoverSettings: If we want to include the discover settings
        :return: a dict of combined settings
        """

        if len(self.dSettingsCombined) != 0:
            return self.dSettingsCombined
        dRet = {}

        for uKey in self.dDefaultSettings:
            if self.dDefaultSettings[uKey]["active"] != "disabled":
                dRet[uKey] = self.dDefaultSettings[uKey]

        dInterFaceJSON = self.oInterFace.GetConfigJSON()
        for uKey in dInterFaceJSON:
            dLine = dInterFaceJSON[uKey]
            iOrder = dLine['order']
            for uKey2 in dRet:
                if dRet[uKey2]['order'] >= iOrder:
                    dRet[uKey2]['order'] += 1
            dRet[uKey] = dLine

        if 'DiscoverSettingButton' in dRet and bIncludeDiscoverSettings:
            dRet.update(self.dGenericDiscoverSettings)
            if self.aDiscoverScriptList is None:
                self.aDiscoverScriptList = Globals.oScripts.GetScriptListForScriptType(
                    "DEVICE_DISCOVER")
            iLastOrder = 200
            for uDiscoverScriptName in self.aDiscoverScriptList:
                oScript = Globals.oScripts.LoadScript(uDiscoverScriptName)
                dScriptJSONSettings = oScript.cScript.GetConfigJSONforParameters(
                    oSetting.aInterFaceIniSettings)
                iMax = 0
                for uKey in dScriptJSONSettings:
                    uTempKey = uDiscoverScriptName + "_" + uKey
                    dRet[uTempKey] = dScriptJSONSettings[uKey]
                    dRet[uTempKey]['key'] = uDiscoverScriptName.upper(
                    ) + "_" + dScriptJSONSettings[uKey]['key']
                    dRet[uTempKey]['scriptsection'] = uDiscoverScriptName
                    dRet[uTempKey]['active'] = 'hidden'
                    iOrder = dRet[uTempKey]['order']
                    iMax = max(iMax, iOrder)
                    dRet[uTempKey]['order'] = iOrder + iLastOrder

                iLastOrder += iMax
        self.dSettingsCombined = dRet
        return dRet