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 __init__(self, parsedNode): self.id = XMLUtils.getAttributeSafe(parsedNode, "id") self.name = XMLUtils.getAttributeSafe(parsedNode, "name") h = hashlib.new('ripemd160') h.update(XMLUtils.elementToString(parsedNode)) self.checksum = h.hexdigest() self.active = XMLUtils.getAttributeSafe(parsedNode, "active") # THIS SHOULD NOT EXIST AT THE CAMPAIGN LEVEL AND AT THE WIFI/BT LEVEL TOO self.days_of_week = TimeConstants.getDaysOfWeek( XMLUtils.getAttributeSafe(parsedNode, "days_of_week")) self.start_date = TimeConstants.dateParseUTC( XMLUtils.getAttributeSafe(parsedNode, "start_date")) self.end_date = TimeConstants.dateParseUTC( XMLUtils.getAttributeSafe(parsedNode, "end_date")) self.start_time = XMLUtils.getAttributeSafe(parsedNode, "start_time") self.end_time = XMLUtils.getAttributeSafe(parsedNode, "end_time") self.wifiNode = parsedNode.find("wifi_campaign") self.btNode = parsedNode.find("bluetooth_campaign") self.pubNubNode = parsedNode.find("pubNubKey") self.type = [] self.wifiCampaign = None self.bluetoothCampaign = None self.pubNubKey = None if (self.wifiNode != None): self.type.append(ClientURISettings.MESSAGE_WIFI) self.wifiCampaign = WifiCampaign(self.wifiNode) if (self.btNode != None): self.type.append(ClientURISettings.MESSAGE_BLUETOOTH) self.bluetoothCampaign = BluetoothCampaign(self.btNode) if (self.pubNubNode != None): self.pubNubKey = PubNubKey(self.pubNubNode) # this exists to allow you to dynamically get the content by type self.content = {} self.content[ ClientURISettings.MESSAGE_BLUETOOTH] = self.bluetoothCampaign self.content[ClientURISettings.MESSAGE_WIFI] = self.wifiCampaign self.last_modified = TimeConstants.dateParseUTC( XMLUtils.getAttributeSafe(parsedNode, "last_modified"))
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 __init__(self, parsedNode): self.id = XMLUtils.getAttributeSafe(parsedNode, "id") self.name = XMLUtils.getAttributeSafe(parsedNode, "name") h = hashlib.new('ripemd160') h.update(XMLUtils.elementToString(parsedNode)) self.checksum = h.hexdigest() self.active = XMLUtils.getAttributeSafe(parsedNode, "active") # THIS SHOULD NOT EXIST AT THE CAMPAIGN LEVEL AND AT THE WIFI/BT LEVEL TOO self.days_of_week = TimeConstants.getDaysOfWeek( XMLUtils.getAttributeSafe(parsedNode, "days_of_week") ) self.start_date = TimeConstants.dateParseUTC( XMLUtils.getAttributeSafe(parsedNode, "start_date") ) self.end_date = TimeConstants.dateParseUTC( XMLUtils.getAttributeSafe(parsedNode, "end_date") ) self.start_time = XMLUtils.getAttributeSafe(parsedNode, "start_time") self.end_time = XMLUtils.getAttributeSafe(parsedNode, "end_time") self.wifiNode = parsedNode.find("wifi_campaign") self.btNode = parsedNode.find("bluetooth_campaign") self.pubNubNode = parsedNode.find("pubNubKey") self.type = [] self.wifiCampaign = None self.bluetoothCampaign = None self.pubNubKey = None if ( self.wifiNode != None ): self.type.append(ClientURISettings.MESSAGE_WIFI) self.wifiCampaign = WifiCampaign(self.wifiNode) if ( self.btNode != None ): self.type.append(ClientURISettings.MESSAGE_BLUETOOTH) self.bluetoothCampaign = BluetoothCampaign(self.btNode) if ( self.pubNubNode != None ): self.pubNubKey = PubNubKey(self.pubNubNode) # this exists to allow you to dynamically get the content by type self.content = {} self.content[ClientURISettings.MESSAGE_BLUETOOTH] = self.bluetoothCampaign self.content[ClientURISettings.MESSAGE_WIFI] = self.wifiCampaign self.last_modified = TimeConstants.dateParseUTC( XMLUtils.getAttributeSafe(parsedNode, "last_modified") )
def getConfigurationXml(self): return XMLUtils.elementToString(self.parsedXml)