def makeCommand(self,issuenode,structnode,commandName,absolutepathdefault=False,recursiondefault=True): """ Generates the appropiate device commands according to the protocol XML Meta Translation Languag eStructure @type issuenode: cDomelette @param issuenode: is a the xml node that we want to make the commands of @type structnode : cDomelette @param structnode: is the parent in the device's XML Configuration of the equivalent node of issuenode in the XML structure @type commandName: COMMAND_ITEM | EXITCOMMAND_ITEM | CREATINGCOMMAND_ITEM | DELETINGCOMMAND_ITEM | FOLLOWCOMMAND_ITEM @param commandName: is the kind of command that should be look for. @type absolutepathdefault: boolean @param absolutepathdefault: When creates the commands it ignore the followcommand. @type recursiondefault: boolean @param recursiondefault: The recursion default value for the type of command @rtype: CommandList @return: the list of command generated for this issuenode. """ commands = None for structoption in structnode.xpath(commandName): if (commands == None) : commands =[] condition = structoption.xpath(self.CONDITION_ITEM) if (condition != []): conditionvalue = XML_Condition.getConditionValue(issuenode,condition[0]) else: conditionvalue = True if (conditionvalue): command = Command(absolutepath=absolutepathdefault,recursion=recursiondefault) textlist = structoption.xpath("text()") strcommand = "" for text in textlist: strcommand = strcommand + text.nodeValue.strip() tempvalue = structoption.getAttributeNS(EMPTY_NAMESPACE,self.NEGATION_TAG) if (tempvalue == "true"): command.setNegate() tempvalue = structoption.getAttributeNS(EMPTY_NAMESPACE,self.ABSOLUTECOMM_TAG) if (tempvalue == "true"): command.setAbsolutePath() elif (tempvalue == "false"): command.setAbsolutePath(False) tempvalue = structoption.getAttributeNS(EMPTY_NAMESPACE,self.RECURSION_TAG) if (tempvalue == "true"): command.setRecursion(True) elif (tempvalue == "false"): command.setRecursion(False) values = [] for structoption in structoption.xpath(self.VALUE_ITEM): condition = structoption.xpath(self.CONDITION_ITEM) if (condition != []): conditionvalue = XML_Condition.getConditionValue(issuenode,condition[0]) else : conditionvalue = True value = "" if (conditionvalue): for item in structoption.childNodes: if (item.nodeName == TEXT_NODE_NAME): if (item.nodeValue.strip() != ""): for xpathvalue in issuenode.xpath(item.nodeValue.strip()): if (xpathvalue.nodeName == TEXT_NODE_NAME): value = value + " " + xpathvalue.nodeValue else : value = value + " " + xpathvalue.nodeName elif (item.nodeName == self.VALUE_STRING): value = value + " " + item.firstChild.nodeValue values.append(value.strip()) if (strcommand != ""): strcommand = strcommand % tuple(values) command.setCommand(strcommand) commands.append(command) return commands
def getParserStructure(self,structnode,parsestruct,dinamicdata, modifyDefaultPath = True,listpos=None): """ It reads from the Meta Translation Language the <parser> nodes, which condition validate to True, of the current structnode. @type structnode: cDomelette @param structnode: It is the current node in the Meta Translation Language @type parsestruct: ParseStruct @param parsestruct: Specify the current offset of the typeData structure. @type dinamicdata: dictionary @param dinamicdata: It is used for the "setvalue" tag, it contains all, in the scope, the values specified for the XML Translation Language. @type modifyDefaultPath: boolean @param modifyDefaultPath: Used when parser specified to not change the offset. @type listpos: number @param listpos: If the parent is a "list" typevalue, this node should be the current element of the list. @rtype: [ParseValue] @return: It is the list of the <parser> nodes that validate the condition to true. """ parseitems = [] iterator = 0 condition = True structnodelist = structnode.xpath(self.PARSE_ITEM) childstruct = parsestruct.clone() for structoption in structnodelist: scantime = structoption.getAttributeNS(EMPTY_NAMESPACE,self.SCANTIME_TAG) if (scantime == ""): scantime = None else: scantime = int(scantime) valuetype = structoption.getAttributeNS(EMPTY_NAMESPACE,self.VALUETYPE_TAG) if (valuetype == ""): if (structoption.xpath("childs") != []): valuetype = self.DICT_TYPE else: valuetype = self.STRING_TYPE allowempty = structoption.getAttributeNS(EMPTY_NAMESPACE,self.ALLOW_EMPTY_TAG) if (allowempty == "true"): allowempty = True else: allowempty = False showdefault = structoption.getAttributeNS(EMPTY_NAMESPACE,self.SHOWDEFAULT_TAG) if (showdefault == "true"): showdefault = True else: showdefault = False reprintparent = structoption.getAttributeNS(EMPTY_NAMESPACE,self.REPRINTPARENT_TAG) if (reprintparent == "true"): reprintparent = True else: reprintparent = False fieldValues = {} condition = True for childoption in structoption.childNodes: if (childoption != TEXT_NODE_NAME): if (childoption.nodeName == self.CONDITION_ITEM): condition = XML_Condition.getConditionValue(childstruct,childoption) if (not condition): childstruct.copyOffset(parsestruct) break elif(childoption.nodeName == self.PATH_ITEM): path = childoption.xpath("text()") if (path != [] ): listpath = (path[-1]).nodeValue.split('/') childstruct.setOffset(listpath) modifyDefaultPath = False elif(childoption.nodeName == self.SETVALUE_ITEM): field = childoption.getAttributeNS(EMPTY_NAMESPACE,self.FIELD_TAG) value = childoption.xpath("text()") if (value != []): value = value[0].nodeValue else : value = "" fieldValues[field] = value if(modifyDefaultPath): if (childstruct.has_key([structnode.nodeName])): childstruct.setOffset([structnode.nodeName]) else: condition = False if (condition): parseitem = ParseValue(childstruct,valuetype,allowempty,fieldValues,scantime,showdefault,reprintparent) parseitem.addFieldValues(dinamicdata) parseitems.append(parseitem) childstruct = parsestruct.clone() if(structnodelist == []): if (not modifyDefaultPath): parseitem = ParseValue(pathstruct=childstruct,fieldValues=dinamicdata) parseitems.append(parseitem) elif (childstruct.has_key([structnode.nodeName])): childstruct.setOffset([structnode.nodeName]) parseitem = ParseValue(pathstruct=childstruct,fieldValues=dinamicdata) parseitems.append(parseitem) elif (dinamicdata.has_key(structnode.nodeName)): parseitem = ParseValue(fieldValues={structnode.nodeName: dinamicdata[structnode.nodeName]}) parseitems.append(parseitem) return parseitems
def makeCommand(self, issuenode, structnode, commandName, absolutepathdefault=False, recursiondefault=True): """ Generates the appropiate device commands according to the protocol XML Meta Translation Languag eStructure @type issuenode: cDomelette @param issuenode: is a the xml node that we want to make the commands of @type structnode : cDomelette @param structnode: is the parent in the device's XML Configuration of the equivalent node of issuenode in the XML structure @type commandName: COMMAND_ITEM | EXITCOMMAND_ITEM | CREATINGCOMMAND_ITEM | DELETINGCOMMAND_ITEM | FOLLOWCOMMAND_ITEM @param commandName: is the kind of command that should be look for. @type absolutepathdefault: boolean @param absolutepathdefault: When creates the commands it ignore the followcommand. @type recursiondefault: boolean @param recursiondefault: The recursion default value for the type of command @rtype: CommandList @return: the list of command generated for this issuenode. """ commands = None for structoption in structnode.xpath(commandName): if (commands == None): commands = [] condition = structoption.xpath(self.CONDITION_ITEM) if (condition != []): conditionvalue = XML_Condition.getConditionValue( issuenode, condition[0]) else: conditionvalue = True if (conditionvalue): command = Command(absolutepath=absolutepathdefault, recursion=recursiondefault) textlist = structoption.xpath("text()") strcommand = "" for text in textlist: strcommand = strcommand + text.nodeValue.strip() tempvalue = structoption.getAttributeNS( EMPTY_NAMESPACE, self.NEGATION_TAG) if (tempvalue == "true"): command.setNegate() tempvalue = structoption.getAttributeNS( EMPTY_NAMESPACE, self.ABSOLUTECOMM_TAG) if (tempvalue == "true"): command.setAbsolutePath() elif (tempvalue == "false"): command.setAbsolutePath(False) tempvalue = structoption.getAttributeNS( EMPTY_NAMESPACE, self.RECURSION_TAG) if (tempvalue == "true"): command.setRecursion(True) elif (tempvalue == "false"): command.setRecursion(False) values = [] for structoption in structoption.xpath(self.VALUE_ITEM): condition = structoption.xpath(self.CONDITION_ITEM) if (condition != []): conditionvalue = XML_Condition.getConditionValue( issuenode, condition[0]) else: conditionvalue = True value = "" if (conditionvalue): for item in structoption.childNodes: if (item.nodeName == TEXT_NODE_NAME): if (item.nodeValue.strip() != ""): for xpathvalue in issuenode.xpath( item.nodeValue.strip()): if (xpathvalue.nodeName == TEXT_NODE_NAME): value = value + " " + xpathvalue.nodeValue else: value = value + " " + xpathvalue.nodeName elif (item.nodeName == self.VALUE_STRING): value = value + " " + item.firstChild.nodeValue values.append(value.strip()) if (strcommand != ""): strcommand = strcommand % tuple(values) command.setCommand(strcommand) commands.append(command) return commands