Esempio n. 1
0
    def loadConfiguration(self):
        logger.info("Loading configuration from:" +
                    ClientURISettings.CONFIG_FILE)
        if not (os.path.exists(ClientURISettings.CONFIG_FILE)
                and os.path.isfile(ClientURISettings.CONFIG_FILE)):
            outf = open(ClientURISettings.CONFIG_FILE, "w")
            outf.write(self.getDefaultConfiguration())
            outf.close()

        try:
            xmlContent = SystemWriter.readFileToString(
                ClientURISettings.CONFIG_FILE)

            if (xmlContent.strip() == ""):
                logger.error(
                    "Client config was empty, putting device into limbo with default config"
                )
                os.remove(ClientURISettings.CONFIG_FILE)
                outf = open(ClientURISettings.CONFIG_FILE, "w")
                outf.write(self.getDefaultConfiguration())
                outf.close()
                xmlContent = SystemWriter.readFileToString(
                    ClientURISettings.CONFIG_FILE)

            configNode = XMLUtils.stringToElement(xmlContent)
            self.parseNode(configNode)
        except Exception as err:
            logger.error(err)
 def saveCampaigns(self):
     if (self.parsedXml != None):
         stringCurrentXML = XMLUtils.elementToString(self.parsedXml)
         stringSavedXML = SystemWriter.readFileToString(ClientURISettings.CAMPAIGNS_FILE)
         if ((stringCurrentXML != stringSavedXML) and (len(stringCurrentXML) > 0)):
             XMLUtils.writeNodeToFile(ClientURISettings.CAMPAIGNS_FILE, self.parsedXml)
             logger.info("Campaigns updated on file system")
         else:
             logger.info("Campaigns change not needed")
     else:
         logger.error("Cannot save Campaigns: no data available")
 def saveConfiguration(self):
     if ( self.parsedXml != None ):
         self.setMacAddr()
         
         stringCurrentXML = XMLUtils.elementToString(self.parsedXml)
         stringSavedXML = SystemWriter.readFileToString(ClientURISettings.CONFIG_FILE)
         if (( stringCurrentXML != stringSavedXML) and ( len(stringCurrentXML) != len(self.getDefaultConfiguration()))):
             XMLUtils.writeNodeToFile(ClientURISettings.CONFIG_FILE, self.parsedXml)
             logger.info("ClientConfig updated on file system")
         else:
             logger.debug("ClientConfig change not needed")
     else:
         logger.error("Cannot save ClientConfig: no data available")
 def loadConfiguration(self):
     logger.info("Loading configuration from:" + ClientURISettings.CONFIG_FILE)
     if not (os.path.exists(ClientURISettings.CONFIG_FILE) and os.path.isfile(ClientURISettings.CONFIG_FILE)):
         outf = open(ClientURISettings.CONFIG_FILE, "w")
         outf.write(self.getDefaultConfiguration())
         outf.close()
     
     try:
         xmlContent = SystemWriter.readFileToString(ClientURISettings.CONFIG_FILE)
         
         if ( xmlContent.strip() == "" ):
             logger.error("Client config was empty, putting device into limbo with default config")
             os.remove(ClientURISettings.CONFIG_FILE)
             outf = open(ClientURISettings.CONFIG_FILE, "w")
             outf.write(self.getDefaultConfiguration())
             outf.close()
             xmlContent = SystemWriter.readFileToString(ClientURISettings.CONFIG_FILE)
         
         configNode = XMLUtils.stringToElement(xmlContent)
         self.parseNode(configNode)
     except Exception as err:
         logger.error(err)
Esempio n. 5
0
    def saveConfiguration(self):
        if (self.parsedXml != None):
            self.setMacAddr()

            stringCurrentXML = XMLUtils.elementToString(self.parsedXml)
            stringSavedXML = SystemWriter.readFileToString(
                ClientURISettings.CONFIG_FILE)
            if ((stringCurrentXML != stringSavedXML)
                    and (len(stringCurrentXML) != len(
                        self.getDefaultConfiguration()))):
                XMLUtils.writeNodeToFile(ClientURISettings.CONFIG_FILE,
                                         self.parsedXml)
                logger.info("ClientConfig updated on file system")
            else:
                logger.debug("ClientConfig change not needed")
        else:
            logger.error("Cannot save ClientConfig: no data available")
Esempio n. 6
0
 def readNodeFromFile(filepath):
     data = SystemWriter.readFileToString(filepath)
     node = XMLUtils.stringToElement(data)
     return node