def read_file(my, file_path, cache=True): #my.reader = PyExpat.Reader() #my.doc = my.reader.fromUri(file_path) # the xml library does not like windows style separators try: file_path = file_path.replace("\\", "/") if not cache: my.doc = NonvalidatingReader.parseUri("file://%s" % file_path, my.uri) else: cur_mtime = os.path.getmtime(file_path) cache_mtime = my.XML_FILE_MTIME.get(file_path) if cur_mtime == cache_mtime: my.doc = my.XML_FILE_CACHE.get(file_path) else: my.doc = NonvalidatingReader.parseUri("file://%s" % file_path, my.uri) my.cache_xml(file_path, my.doc, cur_mtime) except Exception, e: #print "Error in xml file: ", file_path raise XmlException(e)
def __init__(self, uri=None, xmlString=None): global doc if uri is not None: doc = NonvalidatingReader.parseUri(uri) elif xmlString is not None: uri = 'file:bogusFile.txt' # Required by Domlette or it issues a warning. doc = NonvalidatingReader.parseString(xmlString, uri)
def get(self, configDatastore): dataFile = C.YENCAP_HOME + '/Modules/VERMONT_Module/' + configDatastore + '.xml' doc = NonvalidatingReader.parseUri("file:" + dataFile) modulereply = ModuleReply(replynode=doc.documentElement) return modulereply
def parseFile(file): """File can be an open handle or filesystem path""" from Ft.Xml.Domlette import NonvalidatingReader if isinstance(file, basestring): dom = NonvalidatingReader.parseUri("file:%s" % self._file) else: dom = NonvalidatingReader.parseStream(file, **kwargs) return McmLogFile(dom)
def __init__(self): """ Creating new modules for Netconf This somewhat define the set of capabilities Building the Module Register Table (MRT) """ self.logFile = C.YENCAP_HOME + "/Modules/LogModule/log.xml" self.doc = NonvalidatingReader.parseUri("file:" + self.logFile)
def __init__(self): """ Creating new modules for Netconf This somewhat define the set of capabilities Building the Module Register Table (MRT) """ self.logFile = C.YENCAP_HOME + "/Modules/LogModule/log.xml" self.doc = NonvalidatingReader.parseUri("file:"+self.logFile)
def getConfig(self, configDatastore): #xmlFile = open(C.YENCAP_HOME + '/Modules/VERMONT_Module/running.xml') #doc = parse(xmlFile) dataFile = C.YENCAP_HOME + '/Modules/VERMONT_Module/' + configDatastore + '.xml' doc = NonvalidatingReader.parseUri("file:" + dataFile) modulereply = ModuleReply(replynode=doc.documentElement) return modulereply
def exchangeCapabilities(self, clientsock): """ Exchange the capabilities with the manager. First sends the agent capabilities. Then waits for the remote manager capabilities. Creates a Netconf session and returns it. @type clientsock: socket @param clientsock: The socket for the current client @rtype: session @return: The session created by the SessionManager. """ # Loading hello element along with static capabilities from hello.xml file helloRoot = NonvalidatingReader.parseUri(C.HELLO_URI) helloNode = helloRoot.documentElement # Finding a unique session-id for that session self.session = sessionManager.getInstance().createSession( clientsock, self.username) sessionId = self.session.getSessionId() LogManager.getInstance().logInfo( "opening Netconf session: (sessionId=%s)" % (self.session.getSessionId())) # Setup the session-id value within session-id node sessionIdNode = helloRoot.createElementNS(C.NETCONF_XMLNS, C.SESSION_ID) helloNode.appendChild(sessionIdNode) sessionIdNode.appendChild(helloRoot.createTextNode(str(sessionId))) # Get the unique instance of the singleton ModuleManager: moduleManager = ModuleManager.getInstance() # Add the capabilities related to the modules to the hello message: for node in helloNode.childNodes: if (node.nodeType == Node.ELEMENT_NODE and node.tagName == C.CAPABILITIES): for module in moduleManager.getModules(): capabNode = helloRoot.createElementNS( C.NETCONF_XMLNS, C.CAPABILITY) capabText = helloRoot.createTextNode(module.namespace) capabNode.appendChild(capabText) node.appendChild(capabNode) # Convert the hello element to String before sending hellostr = util.convertNodeToString(helloNode) # Sending capabilities along with a new session-id self.send(hellostr) # Receiving capabilities of the manager data = self.receive() # Printing Manager capabilities LogManager.getInstance().logInfo( "Manager capabilities received: (sessionId=%s)" % (self.session.getSessionId()))
def Parse(source): """ Convenience function for parsing XML. Use this function with a single argument, which must either be a string (not Unicode object), file-like object (stream), file path or URI. Returns a Domlette node. Only pass strings or streams to this function if the XML is self-contained XML (i.e. not requiring access to any other resource such as external entities or includes). If you get URI resolution errors, do not use this function: use the lower-level APIs instead. As an example, if you want such resolution to use the current working directory as a base, parse as follows for strings: from Ft.Xml.Domlette import NonvalidatingReader from Ft.Lib import Uri XML = "<!DOCTYPE a [ <!ENTITY b "b.xml"> ]><a>&b;</a>" base = Uri.OsPathToUri('') #Turn CWD into a file: URL doc = NonvalidatingReader.parseString(XML, base) # during parsing, the replacement text for &b; # will be obtained from b.xml in the CWD For streams, use "parseStream" rather than "parseString" in the above. """ #do the imports within the function: a tad bit less efficient, but #avoid circular crap from Ft.Xml.Domlette import NonvalidatingReader from Ft.Lib import Uri, Uuid from Ft.Xml.Lib.XmlString import IsXml if hasattr(source, 'read'): #Create dummy Uri to use as base dummy_uri = 'urn:uuid:' + Uuid.UuidAsString(Uuid.GenerateUuid()) return NonvalidatingReader.parseStream(source, dummy_uri) elif IsXml(source): dummy_uri = 'urn:uuid:' + Uuid.UuidAsString(Uuid.GenerateUuid()) return NonvalidatingReader.parseString(source, dummy_uri) elif Uri.IsAbsolute(source): #or not os.path.isfile(source): return NonvalidatingReader.parseUri(source) else: return NonvalidatingReader.parseUri(Uri.OsPathToUri(source))
def __init__(self, uri=None, xmlString=None): global doc self.hierarchy = {} self.levelMap = LevelMap() if uri is not None: doc = NonvalidatingReader.parseUri(uri) self.parse() self.highestLevel = 0 self.createLevelMap() print "levelMap:", self.levelMap
def test15CmpZSIc14n(self): ftDoc=NonvalidatingReader.parseUri('file://'+mkPath('windows-ac.xml')) ftOut = StringIO() CanonicalPrint(ftDoc, ftOut) ftC14n = ftOut.getvalue() reader = PyExpat.Reader() dom = reader.fromStream(open('./windows-ac.xml')) zsiC14n = Canonicalize(dom) self.failUnless(ftC14n == zsiC14n, "ZSI C14N output differs")
def get(self, configDatastore): #status = getVERMONTStatus() #xmlFile = open(C.YENCAP_HOME + '/Modules/VERMONT_Module/running.xml') #doc = parse(xmlFile) dataFile = C.YENCAP_HOME + '/Modules/VERMONT_Module/' + configDatastore + '.xml' doc = NonvalidatingReader.parseUri("file:" + dataFile) modulereply = ModuleReply(replynode=doc.documentElement) return modulereply
def test19ExclC14nWithXPathAndInclusiveNSPfx(self): # Exclusive C14N applied to portions of a SOAP message by extracting # using XPath inputFile = mkPath('soapGetAttCertResponse.xml') from xml.xpath.Context import Context from xml import xpath from xml.dom.ext.reader import PyExpat reader = PyExpat.Reader() dom = reader.fromStream(open(inputFile)) processorNss = \ { 'wsu': ("http://docs.oasis-open.org/wss/2004/01/" "oasis-200401-wss-wssecurity-utility-1.0.xsd"), } ctxt = Context(dom, processorNss=processorNss) zsiRefNodes = xpath.Evaluate('//*[@wsu:Id]', contextNode=dom, context=ctxt) # 4Suite ftDoc=NonvalidatingReader.parseUri('file://'+inputFile) ftOut = StringIO() # Extract nodes for signing xpathExpression = XPath.Compile('//*[@wsu:Id]') ctx = XPath.Context.Context(ftDoc, processorNss=processorNss) ftRefNodes = xpathExpression.evaluate(ctx) nsPfx = ['SOAP-ENV', 'ds'] for zsiRefNode, ftRefNode in zip(zsiRefNodes, ftRefNodes): # Get ref node and all it's children refSubsetList = getChildNodes(zsiRefNode) zsiRefC14n = Canonicalize(dom, None, subset=refSubsetList, unsuppressedPrefixes=nsPfx) print("_"*80) print("4Suite C14N with Prefixes %s:\n", zsiRefNode.nodeName) print(zsiRefC14n) # 4Suite equivalent ftOut = StringIO() CanonicalPrint(ftRefNode, stream=ftOut, exclusive=True, inclusivePrefixes=nsPfx) ftRefC14n = ftOut.getvalue() print("_"*80) print("4Suite Exclusive C14N %s:\n", ftRefNode.nodeName) print(ftRefC14n) self.assertEqual(zsiRefC14n, ftRefC14n)
def get(self, configName): if self.files.has_key(configName): doc = NonvalidatingReader.parseUri("file:" + self.files[configName]) moduleReply = ModuleReply(replynode=doc.documentElement) else: moduleReply = ModuleReply(error_type=ModuleReply.APPLICATION, error_tag=ModuleReply.OPERATION_FAILED, error_severity=ModuleReply.ERROR, error_message="Unknown source: " + configName) return moduleReply
def __init__ (self, sheet='/usr/share/sgml/docbook/stylesheet/xsl/nwalsh/html/docbook.xsl' ): """ By default i use docbook stylesheet. I want to create processor and feed stylesheet before client connection, so i can save response time """ #instantiate processor self.processor=Processor.Processor() # configure stylesheet (like domlette object) sheet_uri = Uri.OsPathToUri(sheet,1) transform = NonvalidatingReader.parseUri(sheet_uri) self.processor.appendStylesheetNode(transform, sheet_uri)
def tostatic(self, file=None): self._exports = {} if file: self._doc = nr.parseUri(file) stripws(self._doc) names = [getname(i) for i in tags(self._doc, psins, rsrc)] classes = [getclass(i) for i in tags(self._doc, psins, rsrc)] self._unexpanded = [i for i in tags(self._doc, psins, rsrc) if getclass(i) in names] self._templates = [i for i in tags(self._doc, psins, rsrc) if getname(i) in classes] self._expandTemplates() self._expandResources() self._exportResources()
def get(self, configName): if self.files.has_key(configName): doc = NonvalidatingReader.parseUri("file:" + self.files[configName]) moduleReply = ModuleReply(replynode=doc.documentElement) else: moduleReply = ModuleReply( error_type=ModuleReply.APPLICATION, error_tag=ModuleReply.OPERATION_FAILED, error_severity=ModuleReply.ERROR, error_message="Unknown source: " + configName) return moduleReply
def test16Cmplxmlc14n(self): ftDoc=NonvalidatingReader.parseUri('file://'+mkPath('windows-ac.xml')) ftOut = StringIO() CanonicalPrint(ftDoc, ftOut) ftC14n = ftOut.getvalue() from lxml import etree as lxmlET lxmlElem = lxmlET.parse('./windows-ac.xml') lxmlETf = StringIO() lxmlElem.write_c14n(lxmlETf) lxmlETC14n = lxmlETf.getvalue() self.failUnless(ftC14n == lxmlETC14n, "lxml C14N output differs")
def exchangeCapabilities(self, clientsock): """ Exchange the capabilities with the manager. First sends the agent capabilities. Then waits for the remote manager capabilities. Creates a Netconf session and returns it. @type clientsock: socket @param clientsock: The socket for the current client @rtype: session @return: The session created by the SessionManager. """ # Loading hello element along with static capabilities from hello.xml file helloRoot = NonvalidatingReader.parseUri(C.HELLO_URI) helloNode = helloRoot.documentElement # Finding a unique session-id for that session self.session = sessionManager.getInstance().createSession(clientsock, self.username) sessionId = self.session.getSessionId() LogManager.getInstance().logInfo("opening Netconf session: (sessionId=%s)" % (self.session.getSessionId())) # Setup the session-id value within session-id node sessionIdNode = helloRoot.createElementNS(C.NETCONF_XMLNS, C.SESSION_ID) helloNode.appendChild(sessionIdNode) sessionIdNode.appendChild(helloRoot.createTextNode(str(sessionId))) # Get the unique instance of the singleton ModuleManager: moduleManager = ModuleManager.getInstance() # Add the capabilities related to the modules to the hello message: for node in helloNode.childNodes: if (node.nodeType== Node.ELEMENT_NODE and node.tagName == C.CAPABILITIES): for module in moduleManager.getModules(): capabNode = helloRoot.createElementNS(C.NETCONF_XMLNS, C.CAPABILITY) capabText = helloRoot.createTextNode(module.namespace) capabNode.appendChild(capabText) node.appendChild(capabNode) # Convert the hello element to String before sending hellostr = util.convertNodeToString(helloNode) # Sending capabilities along with a new session-id self.send(hellostr) # Receiving capabilities of the manager data = self.receive() # Printing Manager capabilities LogManager.getInstance().logInfo("Manager capabilities received: (sessionId=%s)" % (self.session.getSessionId()))
def populate(self): #{ print self.name + ' populate()' for dictionary in self.parent.xpath('.//dictionary'): #{ current_dict = dictionary.getAttributeNS(None, 'n') side = dictionary.getAttributeNS(None, 'side') filename = dictionary.getAttributeNS(None, 'file') filename = self.working + '/cache/' + self.name + '/' + filename print ' % (' + current_dict + ') ' + side + ', ' + filename doc = NonvalidatingReader.parseUri('file:///' + filename) self.dictionary[side] = Dictionary(side, current_dict, filename, doc, self.tags, self.templates) #} self.dictionary['bidix'].hashes_left = self.dictionary['left'].hashes self.dictionary['bidix'].hashes_right = self.dictionary['right'].hashes
def refreshData(self, sourceName): """ This method must be called when the RBAC data has been modified using Netconf for instance. It parses the rbac.xml file and build a DOM document """ self.users = [] self.roles = [] self.permissions = [] sourcefilePath = "%s/%s-%s.xml" % (C.YENCAP_CONF_HOME, "RBAC", sourceName) destfilePath = "%s/%s-%s.xml" % (C.YENCAP_CONF_HOME, "RBAC", C.RUNNING) os.system("cp %s %s" % (sourcefilePath, destfilePath)) self.rbacdoc = NonvalidatingReader.parseUri("file:"+sourcefilePath).documentElement self.buildRbac()
def __init__(self, in_root, options): #-- # Parse the project definition #-- self.options = options self.in_root = in_root.rstrip('/\\') self.out_root = os.path.join(self.in_root, 'out') self.index = '/index.pip' self.stylesheet_fname = '/pipp.xsl' self.state_xml = os.path.join(in_root, 'pipp.xml') self.changed_exports = [] self.new_project = not os.path.exists(self.state_xml) if self.new_project: open(self.state_xml, 'w').write('<page src="%s"><exports><link>%s</link></exports></page>' % (self.index, re.sub('.pip$', '.html', self.index))) self.state_doc = NonvalidatingReader.parseUri(OsPathToUri(self.state_xml)) self._processor = None
def test17InclusiveC14nWithXPath(self): # Inclusive Canonicalization of portions of a SOAP message extracted # using XPath inputFile = mkPath('soapGetAttCertResponse.xml') reader = PyExpat.Reader() dom = reader.fromStream(open(inputFile)) processorNss = \ { 'wsu': ("http://docs.oasis-open.org/wss/2004/01/" "oasis-200401-wss-wssecurity-utility-1.0.xsd"), } ctxt = Context(dom, processorNss=processorNss) zsiRefNodes = xpath.Evaluate('//*[@wsu:Id]', contextNode=dom, context=ctxt) # 4Suite ftDoc=NonvalidatingReader.parseUri('file://'+inputFile) ftOut = StringIO() # Extract nodes for signing xpathExpression = XPath.Compile('//*[@wsu:Id]') ctx = XPath.Context.Context(ftDoc, processorNss=processorNss) ftRefNodes = xpathExpression.evaluate(ctx) for zsiRefNode, ftRefNode in zip(zsiRefNodes, ftRefNodes): # Get ref node and all it's children zsiRefC14n = Canonicalize(zsiRefNode) print("_"*80) print("ZSI Inclusive C14N %s:\n" % zsiRefNode.nodeName) print(zsiRefC14n) ftOut = StringIO() CanonicalPrint(ftRefNode, ftOut) ftRefC14n = ftOut.getvalue() print("_"*80) print("4Suite XML Inclusive C14N %s:\n", ftRefNode.nodeName) print(ftRefC14n) self.assertEqual(zsiRefC14n, ftRefC14n)
def __init__(self, in_root, options): #-- # Parse the project definition #-- self.options = options self.in_root = in_root.rstrip('/\\') self.out_root = os.path.join(self.in_root, 'out') self.index = '/index.pip' self.stylesheet_fname = '/pipp.xsl' self.state_xml = os.path.join(in_root, 'pipp.xml') self.changed_exports = [] self.new_project = not os.path.exists(self.state_xml) if self.new_project: open(self.state_xml, 'w').write( '<page src="%s"><exports><link>%s</link></exports></page>' % (self.index, re.sub('.pip$', '.html', self.index))) self.state_doc = NonvalidatingReader.parseUri( OsPathToUri(self.state_xml)) self._processor = None
def load_templates(self, _file): #{ print 'templates: ' + 'file:///' + self.working_directory + '/' + self.templates_directory + '/' + _file tmpldoc = NonvalidatingReader.parseUri('file:///' + self.working_directory + '/' + self.templates_directory + '/' + _file) matrix = {} for left in Ft.Xml.XPath.Evaluate('.//left', contextNode=tmpldoc): #{ left_hash = left.getAttributeNS(None, 'id') if left_hash not in matrix: #{ matrix[left_hash] = {} #} for right in Ft.Xml.XPath.Evaluate('.//right', contextNode=left): #{ right_hash = right.getAttributeNS(None, 'id') if right_hash not in matrix[left_hash]: #{ matrix[left_hash][right_hash] = '' #} for template in Ft.Xml.XPath.Evaluate('.//template', contextNode=right): #{ buf = cStringIO.StringIO() Ft.Xml.Domlette.Print(template, stream=buf, encoding='utf-8') text = buf.getvalue() buf.close() matrix[left_hash][right_hash] = text.replace( '<template>', '').replace('</template>', '') print 'Added template (' + left_hash + ':' + right_hash + '); length: ' + str( len(text)) #} #} #} return matrix
def Test(tester): tester.startGroup("James Clark's RELAX NG test suites") if SPECTEST_URI is None: tester.warning('Test cases document not found; skipping tests.' ' To enable the tests, download and unpack' ' http://thaiopensource.com/relaxng/testSuite.zip' ' and set the environment variable %s to be the' ' complete file system path of spectest.xml.' % SPECTEST_ENV_VAR) tester.groupDone() return doc = NonvalidatingReader.parseUri(SPECTEST_URI) doc.normalize() tests_by_group = {} groups = doc.xpath('//testSuite') for group in groups: tests = group.xpath('testCase') if tests: tests_by_group[group] = tests process_group(groups[0], tester, tests_by_group) tester.groupDone() return
def Test(tester): tester.startGroup("James Clark's RELAX NG test suites") if SPECTEST_URI is None: tester.warning('Test cases document not found; skipping tests.' ' To enable the tests, download and unpack' ' http://thaiopensource.com/relaxng/testSuite.zip' ' and set the environment variable %s to be the' ' complete file system path of spectest.xml.' % SPECTEST_ENV_VAR) tester.groupDone() return doc = NonvalidatingReader.parseUri(SPECTEST_URI) doc.normalize() tests_by_group = {} groups = doc.xpath('//testSuite') for group in groups: tests = group.xpath('testCase') if tests: tests_by_group[group] = tests process_group(groups[0], tester, tests_by_group) tester.groupDone() return
def __init__(self, name, path, namespace, cacheLifetime, parameters): """ Create an instance and inicialize the structure needed by it. @type parameters: dictionary @param parameters : Should be a dictionary containning the follow keys: - host : the host ip-address where the device is locate. - port : the port number where the Quagga software router is listen at the Telnet Connection. - password and enable\_pass : The passwords to allow a connection to the device and for set root privileges for configurate it, respectibility. - instance : It allows to create more than one instance of the module adding an \textit {instance} attribute with the value specified by it into the root node of the XML BGP Configuration document. If it not specified it will not add anything. - allowxpath : It turn on or off the xpath "Looking into the Values" capability as specified by the value. If it is not specified the default value is false. """ Module.__init__(self, name, path, namespace, cacheLifetime) host = parameters["host"] port = parameters["port"] password = parameters["password"] enable_password = parameters["enable_pass"] self.deviceConnection = VTY_Connection(host, port, password, enable_password) allowxpath = False if( "allowxpath" in parameters): if (parameters["allowxpath"] == "true"): allowxpath = True if( "instance" in parameters): instance = parameters["instance"] else: instance = None structXML = NonvalidatingReader.parseUri("file:"+self.PROTOCOL_STRUCTURE_FILE) self.XMLConstructor = XML_Constructor.XML_Constructor(structXML, self.namespace, instance) self.XMLInterpreter = XML_Interpreter.XML_Interpreter(structXML, self.namespace, allowxpath)
def _makeMathML(self, formula): prefix = os.path.join(self.base_path, "img" + str(self.index) + "_lxir") remove(prefix + ".tex", True) remove(prefix + ".aux", True) remove(prefix + ".log", True) remove(prefix + ".dvi", True) remove(prefix + ".xhtml", True) self.genLaTeXSource(formula, prefix + ".tex", True) self.system(self._getLaTeXCmd() + prefix + ".tex", prefix + ".dvi", True) self.system("lxir " + prefix + ".dvi > " + prefix + ".xhtml", prefix + ".xhtml") doc = NonvalidatingReader.parseUri(prefix + ".xhtml") ctxt = Context(doc, processorNss=NSS) label = self._getLabel(ctxt) nodes = Evaluate("//mm:math", context=ctxt) if len(nodes) == 1: formula = nodes[0] if formula: return formula, label elif len(nodes) == 3 and formula.find('eqnarray'): formula = nodes[0] if formula: return formula, label else: nodes = Evaluate("//xhtml:span[@class='msub' or @class='msup']", context=ctxt) if len(nodes) == 1: formula = nodes[0] if formula: print "Found simple math expression for formula %d" % self.index return formula, label else: print "Generation of MathML for formula %d produced %d output(s)" % ( self.index, len(nodes))
def validate(self, targetName, moduleNode=None): """ Validates the configuration of the targetnode by first calling xmllint to valdidate against the VERMONT-Config-Schema.xsd and then check the datapath of the configuration. @rtype: ModuleReply @return: It should return an error if the configuration does not validate """ outdata = "" if (targetName in [C.URL, C.RUNNING]): xmlreply = ModuleReply( error_type=ModuleReply.APPLICATION, error_tag=ModuleReply.OPERATION_NOT_SUPPORTED, error_severity=ModuleReply.ERROR, error_message="OPERATION-NOT-SUPPORTED") return xmlreply # call xmllint to validate against the schema cmd = "xmllint --schema " + C.YENCAP_HOME + "/Modules/VERMONT_Module/VERMONT-Config-Schema.xsd " + C.YENCAP_HOME + '/Modules/VERMONT_Module/' + targetName + '.xml' xmllintcmd = popen2.Popen3(cmd, 1) xmllintcmd.tochild.close() outfile = xmllintcmd.fromchild outfd = outfile.fileno() errfile = xmllintcmd.childerr errfd = errfile.fileno() errdata = "" outeof = erreof = 0 while 1: ready = select.select([outfd, errfd], [], []) if outfd in ready[0]: outchunk = outfile.read() if outchunk == "": outeof = 1 outdata = outdata + outchunk if errfd in ready[0]: errchunk = errfile.read() if errchunk == "": erreof = 1 errdata = errdata + errchunk if outeof and erreof: break select.select([], [], [], .1) err = xmllintcmd.wait() if err != 0: modulereply = ModuleReply(error_type=ModuleReply.APPLICATION, error_tag=ModuleReply.OPERATION_FAILED, error_severity=ModuleReply.ERROR, error_message="Validation error: " + errdata) return modulereply #Data is valid according to the schema VERMONT-Config-Schema.xsd #Now check for the correct order of the processes if moduleNode == None: dataFile = C.YENCAP_HOME + '/Modules/VERMONT_Module/' + targetName + '.xml' configDoc = NonvalidatingReader.parseUri("file:" + dataFile) moduleNode = configDoc.documentElement #first check the observationPoints process order, if a observationPoint is followed by packetSelection #there has to be a MeteringProcess with packetReporting as well. #first get all meteringProcesses following the observationPoint: nextMeteringProcesses = [] for node in moduleNode.childNodes: if node.nodeType == Node.ELEMENT_NODE: if node.tagName == "observationPoint": for childnode in node.childNodes: if childnode.nodeType == Node.ELEMENT_NODE: if childnode.tagName == "next": for nextChild in childnode.childNodes: if nextChild.nodeType == Node.ELEMENT_NODE: if nextChild.tagName == "meteringProcessId": for textChild in nextChild.childNodes: if textChild.nodeType == Node.TEXT_NODE: nextMeteringProcesses.append( textChild.nodeValue) #Check if the meteringProcess follows a observationPoint and if it has packetSelection. If it does, it may have packetReporting as well. #If not it has to have a following meteringProcess which does. SearchPR = "false" for node in moduleNode.childNodes: if node.nodeType == Node.ELEMENT_NODE: if node.tagName == "meteringProcess": meteringProcessId = node.getAttributeNS( EMPTY_NAMESPACE, "id") if meteringProcessId in nextMeteringProcesses: for childnode in node.childNodes: if childnode.nodeType == Node.ELEMENT_NODE: if childnode.tagName == "packetSelection": SearchPR = "true" if SearchPR == "true": for childnode in node.childNodes: if childnode.nodeType == Node.ELEMENT_NODE: if childnode.tagName == "packetReporting": SearchPR = "false" #if there is not packetReporting in the same meteringProcess, check the next process. Therefore get the processId. if SearchPR == "true": for childnode in node.childNodes: if childnode.nodeType == Node.ELEMENT_NODE: if childnode.tagName == "next": for nextChild in childnode.childNodes: if nextChild.nodeType == Node.ELEMENT_NODE: if nextChild.tagName == "meteringProcessId": for textChild in nextChild.childNodes: if textChild.nodeType == Node.TEXT_NODE: followUpMeteringProcessId = textChild.nodeValue print "followUpMeteringProcessId: " print followUpMeteringProcessId #Is there such a meteringProcess with packetReporting: for node in moduleNode.childNodes: if node.nodeType == Node.ELEMENT_NODE: if node.tagName == "meteringProcess": meteringProcessId = node.getAttributeNS( EMPTY_NAMESPACE, "id") if meteringProcessId == followUpMeteringProcessId: for childnode in node.childNodes: if childnode.nodeType == Node.ELEMENT_NODE: if childnode.tagName == "packetReporting": SearchPR = "false" #If there is no packetReporting, that is an error. if SearchPR == "true": modulereply = ModuleReply( error_type=ModuleReply.APPLICATION, error_tag=ModuleReply.OPERATION_FAILED, error_severity=ModuleReply.ERROR, error_message= "Validation error: No packetReporting following a packetSelection." ) return modulereply #A collectingProcess can only be followed by a MeteringProcess with flowMetering, so get the following meteringProcesses to check. nextMeteringProcesses = [] for node in moduleNode.childNodes: if node.nodeType == Node.ELEMENT_NODE: if node.tagName == "collectingProcess": for childnode in node.childNodes: if childnode.nodeType == Node.ELEMENT_NODE: if childnode.tagName == "next": for nextChild in childnode.childNodes: if nextChild.nodeType == Node.ELEMENT_NODE: if nextChild.tagName == "meteringProcessId": for textChild in nextChild.childNodes: if textChild.nodeType == Node.TEXT_NODE: nextMeteringProcesses.append( textChild.nodeValue) #Check all following meteringProcess, if they have packetSelection or packetReporting, which will raise an error. for node in moduleNode.childNodes: if node.nodeType == Node.ELEMENT_NODE: if node.tagName == "meteringProcess": meteringProcessId = node.getAttributeNS( EMPTY_NAMESPACE, "id") if meteringProcessId in nextMeteringProcesses: for childnode in node.childNodes: if childnode.nodeType == Node.ELEMENT_NODE: if node.tagName in [ "packetSelection", "packetReporting" ]: modulereply = ModuleReply( error_type=ModuleReply.APPLICATION, error_tag=ModuleReply.OPERATION_FAILED, error_severity=ModuleReply.ERROR, error_message= "Validation error: packetSelection or packetReporting follows collectingProcess" ) return modulereply #If everything is correct, just return a ok. modulereply = ModuleReply() return modulereply
def editConfig(self, defaultoperation, testoption, erroroption, target, confignode, targetnode=None): """ Apply the request specified in confignode to the targetnode. @type defaultoperation: MERGE_OPERATION | REPLACE_OPERATION | NONE_OPERATION @param defaultoperation : as specified in NETCONF protocol @type testoption : SET | TEST_AND_SET @param testoption : as specified in NETCONF protocol @type erroroption : STOP_ON_ERROR | IGNORE_ERROR | ROLL_BACK_ON_ERROR @param erroroption : as specified in NETCONF protocol @type target : RUNNING_TARGET | CANDIDATE_TARGET | STARTUP_TARGET @param target : as specified in NETCONF protocol @type targetnode : string @param targetnode : if the target is RUNNING_TARGET or STARTUP_TARGET it will be ignored otherwise should be the node of the CANDIDATE_TARGET that this module should process @rtype: ModuleReply @return: It should return a success or error message. ** Relates to the netconf edit-config operation """ error = None if (target in [C.URL, C.RUNNING]): xmlreply = ModuleReply( error_type=ModuleReply.APPLICATION, error_tag=ModuleReply.OPERATION_NOT_SUPPORTED, error_severity=ModuleReply.ERROR, error_message="OPERATION-NOT-SUPPORTED") return xmlreply if defaultoperation == "replace": f = open( C.YENCAP_HOME + '/Modules/VERMONT_Module/' + target + '.xml', 'w') PrettyPrint(confignode, f) f.close() return ModuleReply() # draft-ietf-netconf-prot-11 says: "the default value for the default-operation is merge" # in this datamodel merge will replace all nodes with the same type and id it finds in configNodeRoot # and adds all it can't find elif defaultoperation == "merge": if not os.path.exists(C.YENCAP_HOME + '/Modules/VERMONT_Module/' + target + '.xml'): ipfixConfigBase = '<ipfixConfig xmlns="urn:ietf:params:xml:ns:ipfix-config"></ipfixConfig>' xmlfile = file( C.YENCAP_HOME + '/Modules/VERMONT_Module/' + target + '.xml', 'w') xmlfile.write(ipfixConfigBase) xmlfile.close() dataFile = C.YENCAP_HOME + '/Modules/VERMONT_Module/' + target + '.xml' configDoc = NonvalidatingReader.parseUri("file:" + dataFile) configNodeRoot = configDoc.documentElement for newProcess in confignode.documentElement.childNodes: if newProcess.nodeType == Node.ELEMENT_NODE: processName = newProcess.localName processId = newProcess.getAttributeNS( EMPTY_NAMESPACE, "id") isNew = True for oldProcess in configDoc.documentElement.childNodes: if oldProcess.nodeType == Node.ELEMENT_NODE: if oldProcess.tagName == processName: #oldProcessId = oldProcess.attributes[(None, u'id')].value oldProcessId = oldProcess.getAttributeNS( EMPTY_NAMESPACE, "id") print "Old ProcessId:" + oldProcessId if oldProcessId == processId: isNew = False configNodeRoot.replaceChild( newProcess, oldProcess) if isNew: print "appending" configNodeRoot.appendChild(newProcess) #otherwise, every node has its own operation, create, delete, replace or merge #the data model ipfix-config-data-model has to treat merge just as replace, as detailed #editing of some parts of the data are impossible, due to possible ambiguities. else: if not os.path.exists(C.YENCAP_HOME + '/Modules/VERMONT_Module/' + target + '.xml'): ipfixConfigBase = '<ipfixConfig xmlns="urn:ietf:params:xml:ns:ipfix-config"></ipfixConfig>' xmlfile = file( C.YENCAP_HOME + '/Modules/VERMONT_Module/' + target + '.xml', 'w') xmlfile.write(ipfixConfigBase) xmlfile.close() dataFile = C.YENCAP_HOME + '/Modules/VERMONT_Module/' + target + '.xml' configDoc = NonvalidatingReader.parseUri("file:" + dataFile) for newProcess in confignode.documentElement.childNodes: if newProcess.nodeType == Node.ELEMENT_NODE: processName = newProcess.localName operation = newProcess.getAttributeNS( 'ietf:params:xml:ns:netconf:base:1.0', "operation") processId = newProcess.getAttributeNS( EMPTY_NAMESPACE, "id") print processName print operation print processId if processName == "ipfixConfig": continue if processId == None: error = "Config data to add has errors!" moduleReply = ModuleReply( error_type=ModuleReply.APPLICATION, error_tag=ModuleReply.OPERATION_FAILED, error_severity=ModuleReply.ERROR, error_message=error) return moduleReply if operation == None: error == "If no defaultoperation is chosen, every process has to have its own operation!" moduleReply = ModuleReply( error_type=ModuleReply.APPLICATION, error_tag=ModuleReply.OPERATION_FAILED, error_severity=ModuleReply.ERROR, error_message=error) return moduleReply if operation == "create": configDoc.documentElement.appendChild(newProcess) else: error = processName + " " + "not found!" for oldProcess in configDoc.documentElement.childNodes: if oldProcess.nodeType == Node.ELEMENT_NODE: if oldProcess.tagName == processName: #oldProcessId = oldProcess.attributes[(None, u'id')].value oldProcessId = oldProcess.getAttributeNS( EMPTY_NAMESPACE, "id") if oldProcessId == processId: if operation == "delete": configDoc.documentElement.removeChild( oldProcess) error = None elif operation == "replace" or operation == "merge": configDoc.documentElement.replaceChild( newProcess, oldProcess) error = None if error != None: if erroroption == "stop-on-error": modulereply = ModuleReply( error_type=ModuleReply. APPLICATION, error_tag=ModuleReply. OPERATION_FAILED, error_severity=ModuleReply. ERROR, error_message=error) return modulereply xmlFile = open( C.YENCAP_HOME + '/Modules/VERMONT_Module/' + target + '.xml', 'w') PrettyPrint(configDoc, xmlFile) xmlFile.close() if error == None: modulereply = ModuleReply() else: modulereply = ModuleReply(error_type=ModuleReply.APPLICATION, error_tag=ModuleReply.OPERATION_FAILED, error_severity=ModuleReply.ERROR, error_message=error) return modulereply return modulereply
def insert_math_images(file): file = os.path.abspath(file) doc = NonvalidatingReader.parseUri(file) ctxt = Context(doc, processorNss=NSS) # Check that verbatim math is used for node in Evaluate("//xhtml:span[@class='verbatimmath']/@lxir:value", context=ctxt): verbatimmath = node.value assert verbatimmath == u'true', "Need verbatim math mode for math conversion" # Check that the document class is known latexClass = None symbols = [] for node in Evaluate( "//xhtml:span[@class='ClassOrPackageUsed']/@lxir:name", context=ctxt): if latexClasses.has_key(node.value): latexClass = latexClasses[node.value] elif node.value in symbolPackages: symbols.append(node.value[:-4]) assert latexClass, "Unknown document class used" # Get All macro text macros = [] for node in Evaluate("//xhtml:span[@class='macro']//text()", context=ctxt): macros.append(node.nodeValue) gen = ImageGenerator(file, latexClass, macros, symbols) # Convert All math images for node in Evaluate("//xhtml:span[@class='formule']", context=ctxt): c = Context(node, processorNss=NSS) formula = "" for t in Evaluate("xhtml:span[@class='text']/text()", context=c): formula += t.nodeValue formula = formula.strip() if not len(formula): print "empty formula found in document" image, mathml, label = None, None, None else: if formula[0] != "$": p = node.parentNode env = p.getAttributeNS(None, 'class') assert env, "No env found for equation" if env[-5:] == "-star": env = env[:-5] + "*" formula = "\\begin{" + env + "}\n" + formula + "\n\\end{" + env + "}" image, mathml, label = gen.makeImage(formula) # remove the empty text node(s) for t in Evaluate("xhtml:span[@class='text']", context=c): t.parentNode.removeChild(t) if image: img = node.ownerDocument.createElementNS(XHTML_NAMESPACE, "img") img.setAttributeNS(XHTML_NAMESPACE, "src", image) img.setAttributeNS(XHTML_NAMESPACE, "alt", formula) node.appendChild(img) if mathml: if mathml.tagName != 'math': # here, we have the case : a$_b$ # mathml is: <span class='msub'><span class='mi'/><span>b</span></span> # original xml is : ... <span>a</span><span class="formula"> ...</span> # and node is the formula # p is <span>a</span> p = get_prev_span_node(node) newNode = node.parentNode.insertBefore(mathml.cloneNode(True), node) newNode.firstChild.appendChild(p) node.parentNode.removeChild(node) print "Formula '%s' replaced by simple form (%s)." % ( formula, newNode.tagName + '.' + newNode.getAttributeNS(None, u'class')) else: node.appendChild(node.ownerDocument.importNode(mathml, True)) if label: node.appendChild(node.ownerDocument.importNode(label, True)) base, ext = os.path.splitext(file) output = base + "_images" + ext o = open(output, "w") Print(doc, stream=o) o.close()
def editConfig(self, defaultoperation, testoption, erroroption, target, confignode, targetnode=None): """ Apply the request specified in confignode to the targetnode. @type defaultoperation: MERGE_OPERATION | REPLACE_OPERATION | NONE_OPERATION @param defaultoperation : as specified in NETCONF protocol @type testoption : SET | TEST_AND_SET @param testoption : as specified in NETCONF protocol @type erroroption : STOP_ON_ERROR | IGNORE_ERROR | ROLL_BACK_ON_ERROR @param erroroption : as specified in NETCONF protocol @type target : RUNNING_TARGET | CANDIDATE_TARGET | STARTUP_TARGET @param target : as specified in NETCONF protocol @type targetnode : string @param targetnode : if the target is RUNNING_TARGET or STARTUP_TARGET it will be ignored otherwise should be the node of the CANDIDATE_TARGET that this module should process @rtype: ModuleReply @return: It should return a success or error message. ** Relates to the netconf edit-config operation """ error = None if (target in [C.URL, C.RUNNING]): xmlreply = ModuleReply( error_type=ModuleReply.APPLICATION, error_tag=ModuleReply.OPERATION_NOT_SUPPORTED, error_severity=ModuleReply.ERROR, error_message="OPERATION-NOT-SUPPORTED") return xmlreply #PrettyPrint(configNodeRoot) #if replace is the defaultoperation, edit-config works just like copy-config with inline configuration data. if defaultoperation == "replace": f = open(C.YENCAP_HOME + '/Modules/VERMONT_Module/' + target + '.xml','w') PrettyPrint(confignode, f) f.close() return ModuleReply() # draft-ietf-netconf-prot-11 says: "the default value for the default-operation is merge" # in this datamodel merge will replace all nodes with the same type and id it finds in configNodeRoot # and adds all it can't find elif defaultoperation == "merge": if not os.path.exists(C.YENCAP_HOME + '/Modules/VERMONT_Module/' + target + '.xml'): ipfixConfigBase = '<ipfixConfig xmlns="urn:ietf:params:xml:ns:ipfix-config"></ipfixConfig>' xmlfile = file(C.YENCAP_HOME + '/Modules/VERMONT_Module/' + target + '.xml','w') xmlfile.write(ipfixConfigBase) xmlfile.close() dataFile = C.YENCAP_HOME + '/Modules/VERMONT_Module/' + target + '.xml' configDoc = NonvalidatingReader.parseUri("file:" + dataFile) configNodeRoot = configDoc.documentElement for newProcess in confignode.childNodes: if newProcess.nodeType == Node.ELEMENT_NODE: processName = newProcess.localName processId = newProcess.getAttributeNS(EMPTY_NAMESPACE, "id") isNew = True for oldProcess in configDoc.documentElement.childNodes: if oldProcess.nodeType == Node.ELEMENT_NODE: if oldProcess.tagName == processName: #oldProcessId = oldProcess.attributes[(None, u'id')].value oldProcessId = oldProcess.getAttributeNS(EMPTY_NAMESPACE, "id") print "Old ProcessId:" + oldProcessId if oldProcessId == processId: isNew = False configNodeRoot.replaceChild(newProcess, oldProcess) if isNew: print "appending" configNodeRoot.appendChild(newProcess) #otherwise, every node has its own operation, create, delete, replace or merge #the data model ipfix-config-data-model has to treat merge just as replace, as detailed #editing of some parts of the data are impossible, due to possible ambiguities. else: if not os.path.exists(C.YENCAP_HOME + '/Modules/VERMONT_Module/' + target + '.xml'): ipfixConfigBase = '<ipfixConfig xmlns="urn:ietf:params:xml:ns:ipfix-config"></ipfixConfig>' xmlfile = file(C.YENCAP_HOME + '/Modules/VERMONT_Module/' + target + '.xml','w') xmlfile.write(ipfixConfigBase) xmlfile.close() dataFile = C.YENCAP_HOME + '/Modules/VERMONT_Module/' + target + '.xml' configDoc = NonvalidatingReader.parseUri("file:" + dataFile) for newProcess in confignode.childNodes: if newProcess.nodeType == Node.ELEMENT_NODE: processName = newProcess.localName operation = newProcess.getAttributeNS('ietf:params:xml:ns:netconf:base:1.0', "operation") processId = newProcess.getAttributeNS(EMPTY_NAMESPACE, "id") print processName print operation print processId if processName == "ipfixConfig": continue if processId == None: error = "Config data to add has errors!" moduleReply = ModuleReply( error_type = ModuleReply.APPLICATION, error_tag = ModuleReply.OPERATION_FAILED, error_severity = ModuleReply.ERROR, error_message = error) return moduleReply if operation == None: error == "If no defaultoperation is chosen, every process has to have its own operation!" moduleReply = ModuleReply( error_type = ModuleReply.APPLICATION, error_tag = ModuleReply.OPERATION_FAILED, error_severity = ModuleReply.ERROR, error_message = error) return moduleReply if operation == "create": configDoc.documentElement.appendChild(newProcess) else: error = processName + " " + "not found!" for oldProcess in configDoc.documentElement.childNodes: if oldProcess.nodeType == Node.ELEMENT_NODE: if oldProcess.tagName == processName: #oldProcessId = oldProcess.attributes[(None, u'id')].value oldProcessId = oldProcess.getAttributeNS(EMPTY_NAMESPACE, "id") if oldProcessId == processId: if operation == "delete": configDoc.documentElement.removeChild(oldProcess) error = None elif operation == "replace" or operation == "merge": configDoc.documentElement.replaceChild(newProcess, oldProcess) error = None if error != None: if erroroption == "stop-on-error": modulereply = ModuleReply(error_type=ModuleReply.APPLICATION, error_tag=ModuleReply.OPERATION_FAILED, error_severity=ModuleReply.ERROR, error_message=error) return modulereply xmlFile = open(C.YENCAP_HOME + '/Modules/VERMONT_Module/' + target + '.xml','w') PrettyPrint(configDoc, xmlFile) xmlFile.close() if error == None: modulereply = ModuleReply() else: modulereply = ModuleReply(error_type=ModuleReply.APPLICATION, error_tag=ModuleReply.OPERATION_FAILED, error_severity=ModuleReply.ERROR, error_message=error) return modulereply return modulereply
# write the alerts in a file in XML format # translated in HTML with XSL for display in the WEB interface import os, time, math, tempfile, sys from Ft.Xml.Domlette import implementation, NonvalidatingReader, PrettyPrint, Print from Ft.Xml.XPath import Evaluate from Ft.Xml import EMPTY_NAMESPACE from xml.dom import Node # The file in which we will write the alerts alerts = "/var/local/ndpmon/alerts.xml" # The alert itself piped from NDPmon to this script lines = sys.stdin.readlines() doc = NonvalidatingReader.parseUri("file:%s" % alerts) # The fields to complete reason = "" mac = "" vendor = "" ipv6 = "" for line in lines: # Separate the fields of each line tmp = line.strip().split(": ") # Initialize the fields if tmp[0] == "Reason": reason = tmp[1].strip() elif tmp[0] == "MAC":
def read(self, file): self._doc = nr.parseUri(file)
class SessionNetconf(Thread): # instance of RequestFactory reqFactory = RequestFactory.getInstance() def __init__(self, agent, user): Thread.__init__(self) self.agent = agent self.user = user self.msg_id = 0 if self.agent.getProtocol() == 'ssh': self.client = sessionSSH(self.agent, self.user) elif self.agent.getProtocol() == 'beep': print 'NOT IMPLEMENTED' connected = C.FAILED try: # Connect to the Netconf agent: connected = self.client.connect() except Exception, exp: print str(exp) if connected: # Build a Hello node containing capabilities, also checking that it is well-formed. doc = NonvalidatingReader.parseUri('file:%s' % (C.HELLO_URI)) # Serialize the Hello XML document to a string req = convertNodeToString(doc.documentElement) # Send the string capabilities, and receive agent capabilities agentCapabilities = self.client.send(req) # Store agent capabilities self.agent.setCapabilities(agentCapabilities) # YANG 17/6/9 if self.agent.hasYangModule(): yms = ("-p",C.YENCAP_MAN_YANG_HOME) for ym in self.agent.yangmodules: s = C.YENCAP_MAN_YANG_HOME + "/" + ym + ".yang" yms = yms + (s ,) cmdline = ("java", "-jar", "YangTreeNodeGenerator.jar", str(agent.ip)) + yms #cmdline = ("java", "-cp", ".:../../Parser/yang:../../yang-manager/bin", "YangSchemaTreeGenerator", str(agent.ip), str(ins)) #cmdline = cmdline + nsp + (str(iyms),) + yms + yxp print cmdline err = Popen(cmdline, stderr=PIPE).stderr errors = "" for eachline in err.readlines(): errors = errors + "<tr><td>" + eachline + "</tr></td>" self.agent.setYangErrMesg(errors) # YANG else: raise Exception('Not Connected')
def execute(self): """ Execute the copy-config operation. """ if self.operationReply.isError(): return self.operationReply if self.target == self.source: if (self.target in [C.CANDIDATE, C.STARTUP, C.RUNNING] or (self.target == C.URL and self.urlSource == self.urlTarget)): moduleReply = ModuleReply( error_type = ModuleReply.PROTOCOL, error_tag = ModuleReply.INVALID_VALUE, error_severity = ModuleReply.ERROR, error_message = "Source and target are equals.") self.operationReply.setError() self.operationReply.setNode(moduleReply.getXMLNodeReply()) return self.operationReply sessionId = sessionManager.getInstance().getLockOwnerSessionId(self.target) if sessionId >= 0 and sessionId != self.session.getSessionId(): # Somebody else locked the target. moduleReply = ModuleReply( error_type = ModuleReply.PROTOCOL, error_tag = ModuleReply.LOCK_DENIED, error_severity = ModuleReply.ERROR, error_message = "Access to the requested lock is denied because the lock is currently held by another entity") moduleReply.addErrorInfo("session-id",sessionId) self.operationReply.setError() self.operationReply.setNode(moduleReply.getXMLNodeReply()) return self.operationReply # Check access here if self.rbacManager.isActive(): operation_allowed = self.rbacManager.checkAccessCopyConfig(self.session) if (not operation_allowed): moduleReply = ModuleReply( error_type = ModuleReply.PROTOCOL, error_tag = ModuleReply.ACCESS_DENIED, error_severity = ModuleReply.ERROR, error_message = "Access denied.") self.operationReply.setError() self.operationReply.setNode(moduleReply.getXMLNodeReply()) return self.operationReply sourceDoc = None if self.source == C.URL: sourceUri = self.urlSource try: # get the DOM tree of the candidate configuration sourceDoc = NonvalidatingReader.parseUri(sourceUri).documentElement except Exception, exp: moduleReply = ModuleReply( error_type = ModuleReply.APPLICATION, error_tag = ModuleReply.DATA_MISSING, error_severity = ModuleReply.ERROR, error_message = self.source + " is not well-formed.") self.operationReply.setError() self.operationReply.setNode(moduleReply.getXMLNodeReply()) return self.operationReply
import re import miscfun def divider(string): print "==== %s" % string def snumconvert(string): m=re.match('[(]*(\d+)[).]*',string) return int(m.group(1)) name='ukpga%s.xml' % sys.argv[1] #name='ukpga1997c2.xml' file_uri=Uri.OsPathToUri("acts/xml/%s" % name) doc=NonvalidatingReader.parseUri(file_uri) from xml.dom.minidom import parse, parseString leaves=doc.xpath('//legis/content/leaf') #for l in leaves: # section=l.xpath('@s') # print section[0].nodeValue # sections=doc.xpath('//legis/content/leaf') id=doc.xpath('//legis/@id') divider(id[0].nodeValue)
xbel1_top_level = \ [ n for n in xbel1.documentElement.childNodes \ if n.nodeType == Node.ELEMENT_NODE ] xbel1_top_level_folders = \ [ n for n in xbel1_top_level if n.nodeName == 'folder' ] xbel1_top_level_bookmarks = \ [ n for n in xbel1_top_level if n.nodeName == 'bookmark' ] xbel2_top_level = \ [ n for n in xbel2.documentElement.childNodes \ if n.nodeType == Node.ELEMENT_NODE ] for elem in xbel2_top_level: if elem.nodeName == 'folder': title = get_title(elem) for a_folder in xbel1_top_level_folders: if title == get_title(a_folder): merge_folders(a_folder, elem) break else: xbel1.documentElement.appendChild(elem) elif elem.nodeName == 'bookmark': xbel1.documentElement.appendChild(elem) return xbel1 if __name__ == "__main__": import sys xbel1 = NonvalidatingReader.parseUri(sys.argv[1]) xbel2 = NonvalidatingReader.parseUri(sys.argv[2]) new_xbel = xbel_merge(xbel1, xbel2) PrettyPrint(new_xbel)
def execute(self): """ Execute the copy-config operation. """ if self.operationReply.isError(): return self.operationReply if self.target == self.source: if (self.target in [C.CANDIDATE, C.STARTUP, C.RUNNING] or (self.target == C.URL and self.urlSource == self.urlTarget)): moduleReply = ModuleReply( error_type=ModuleReply.PROTOCOL, error_tag=ModuleReply.INVALID_VALUE, error_severity=ModuleReply.ERROR, error_message="Source and target are equals.") self.operationReply.setError() self.operationReply.setNode(moduleReply.getXMLNodeReply()) return self.operationReply sessionId = sessionManager.getInstance().getLockOwnerSessionId( self.target) if sessionId >= 0 and sessionId != self.session.getSessionId(): # Somebody else locked the target. moduleReply = ModuleReply( error_type=ModuleReply.PROTOCOL, error_tag=ModuleReply.LOCK_DENIED, error_severity=ModuleReply.ERROR, error_message= "Access to the requested lock is denied because the lock is currently held by another entity" ) moduleReply.addErrorInfo("session-id", sessionId) self.operationReply.setError() self.operationReply.setNode(moduleReply.getXMLNodeReply()) return self.operationReply # Check access here if self.rbacManager.isActive(): operation_allowed = self.rbacManager.checkAccessCopyConfig( self.session) if (not operation_allowed): moduleReply = ModuleReply(error_type=ModuleReply.PROTOCOL, error_tag=ModuleReply.ACCESS_DENIED, error_severity=ModuleReply.ERROR, error_message="Access denied.") self.operationReply.setError() self.operationReply.setNode(moduleReply.getXMLNodeReply()) return self.operationReply sourceDoc = None if self.source == C.URL: sourceUri = self.urlSource try: # get the DOM tree of the candidate configuration sourceDoc = NonvalidatingReader.parseUri( sourceUri).documentElement except Exception, exp: moduleReply = ModuleReply(error_type=ModuleReply.APPLICATION, error_tag=ModuleReply.DATA_MISSING, error_severity=ModuleReply.ERROR, error_message=self.source + " is not well-formed.") self.operationReply.setError() self.operationReply.setNode(moduleReply.getXMLNodeReply()) return self.operationReply
def __init__(self, index_key): self.dom = NonvalidatingReader.parseUri(settings.ADDITIONAL_DATA_INDEX) self.dom_node = self.dom.documentElement self.index_key = index_key
def validate(self, targetName, moduleNode=None): """ Validates the configuration of the targetnode by first calling xmllint to valdidate against the VERMONT-Config-Schema.xsd and then check the datapath of the configuration. @rtype: ModuleReply @return: It should return an error if the configuration does not validate """ outdata = "" if (targetName in [C.URL, C.RUNNING]): xmlreply = ModuleReply( error_type=ModuleReply.APPLICATION, error_tag=ModuleReply.OPERATION_NOT_SUPPORTED, error_severity=ModuleReply.ERROR, error_message="OPERATION-NOT-SUPPORTED") return xmlreply # call xmllint to validate against the schema cmd = "xmllint --schema " + C.YENCAP_HOME + "/Modules/VERMONT_Module/VERMONT-Config-Schema.xsd " + C.YENCAP_HOME + '/Modules/VERMONT_Module/' + targetName + '.xml' #cmd = 'xmllint --schema VERMONT-Config-Schema.xsd ' + targetName + '.xml' p = subprocess.Popen(cmd, shell=True, bufsize=1, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True) (child_stdin, child_stdout, child_stderr) = (p.stdin, p.stdout, p.stderr) child_stdin.close() err = child_stderr.readlines() child_stdout.close() child_stderr.close() errdata = err[0] errdataparts = string.split(errdata) if errdataparts[1] != "validates": modulereply = ModuleReply(error_type=ModuleReply.APPLICATION, error_tag=ModuleReply.OPERATION_FAILED, error_severity=ModuleReply.ERROR, error_message=errdata) return modulereply #Data is valid according to the schema VERMONT-Config-Schema.xsd #Now check for the correct order of the processes if moduleNode == None: dataFile = C.YENCAP_HOME + '/Modules/VERMONT_Module/' + targetName + '.xml' #dataFile = targetName + '.xml' configDoc = NonvalidatingReader.parseUri("file:" + dataFile) #PrettyPrint(configDoc) moduleNode = configDoc.documentElement #first check the observationPoints process order, if a observationPoint is followed by packetSelection #there has to be a MeteringProcess with packetReporting as well. #first get all meteringProcesses following the observationPoint: nextMeteringProcesses = [] for node in moduleNode.childNodes: if node.nodeType == Node.ELEMENT_NODE: if node.tagName == "observationPoint": #print "Found observationPoint, checking next process" for childnode in node.childNodes: if childnode.nodeType == Node.ELEMENT_NODE: if childnode.tagName == "next": for nextChild in childnode.childNodes: if nextChild.nodeType == Node.ELEMENT_NODE: if nextChild.tagName == "meteringProcessId": #print "Found next-meteringProcessId" for textChild in nextChild.childNodes: if textChild.nodeType == Node.TEXT_NODE: #print textChild.nodeValue nextMeteringProcesses.append( textChild.nodeValue) #Check if the meteringProcess follows a observationPoint and if it has packetSelection. If it does, it may have packetReporting as well. #If not it has to have a following meteringProcess which does. SearchPR = False for node in moduleNode.childNodes: if node.nodeType == Node.ELEMENT_NODE: if node.tagName == "meteringProcess": meteringProcessId = node.getAttributeNS( EMPTY_NAMESPACE, "id") print "Found Metering Process " print meteringProcessId if meteringProcessId in nextMeteringProcesses: #print "The meteringprocess is next for a OP" for childnode in node.childNodes: if childnode.nodeType == Node.ELEMENT_NODE: if childnode.tagName == "packetSelection": print "It has packetSelection" SearchPR = True if SearchPR: for childnode in node.childNodes: if childnode.nodeType == Node.ELEMENT_NODE: if childnode.tagName == "packetReporting": print "It also has packetReporting -> ok" SearchPR = False #if there is not packetReporting in the same meteringProcess, check the next process. Therefore get the processId. if SearchPR: print "It doesn't have packetReporting, checking next meteringProcess" for childnode in node.childNodes: if childnode.nodeType == Node.ELEMENT_NODE: if childnode.tagName == "next": for nextChild in childnode.childNodes: if nextChild.nodeType == Node.ELEMENT_NODE: if nextChild.tagName == "meteringProcessId": for textChild in nextChild.childNodes: if textChild.nodeType == Node.TEXT_NODE: followUpMeteringProcessId = textChild.nodeValue print "followUp MeteringProcessId: " print followUpMeteringProcessId #Is there such a meteringProcess with packetReporting: for node in moduleNode.childNodes: if node.nodeType == Node.ELEMENT_NODE: if node.tagName == "meteringProcess": #print "Checking meteringprocess: " meteringProcessId = node.getAttributeNS( EMPTY_NAMESPACE, "id") print meteringProcessId if meteringProcessId == followUpMeteringProcessId: #print "MeteringProcess is the follow up process" for childnode in node.childNodes: if childnode.nodeType == Node.ELEMENT_NODE: if childnode.tagName == "packetReporting": print "Found the follow up process with packetreporting" SearchPR = False #If there is no packetReporting, that is an error. if SearchPR: modulereply = ModuleReply( error_type=ModuleReply.APPLICATION, error_tag=ModuleReply.OPERATION_FAILED, error_severity=ModuleReply.ERROR, error_message= "Validation error: No packetReporting following a packetSelection." ) return modulereply #A collectingProcess can only be followed by a MeteringProcess with flowMetering, so get the following meteringProcesses to check. nextMeteringProcesses = [] for node in moduleNode.childNodes: if node.nodeType == Node.ELEMENT_NODE: if node.tagName == "collectingProcess": for childnode in node.childNodes: if childnode.nodeType == Node.ELEMENT_NODE: if childnode.tagName == "next": for nextChild in childnode.childNodes: if nextChild.nodeType == Node.ELEMENT_NODE: if nextChild.tagName == "meteringProcessId": for textChild in nextChild.childNodes: if textChild.nodeType == Node.TEXT_NODE: nextMeteringProcesses.append( textChild.nodeValue) #Check all following meteringProcess, if they have packetSelection or packetReporting, which will raise an error. for node in moduleNode.childNodes: if node.nodeType == Node.ELEMENT_NODE: if node.tagName == "meteringProcess": meteringProcessId = node.getAttributeNS( EMPTY_NAMESPACE, "id") if meteringProcessId in nextMeteringProcesses: for childnode in node.childNodes: if childnode.nodeType == Node.ELEMENT_NODE: print childnode.tagName if childnode.tagName in [ "packetSelection", "packetReporting" ]: modulereply = ModuleReply( error_type=ModuleReply.APPLICATION, error_tag=ModuleReply.OPERATION_FAILED, error_severity=ModuleReply.ERROR, error_message= "Validation error: packetSelection or packetReporting follows collectingProcess" ) return modulereply #If everything is correct, just return a ok. modulereply = ModuleReply() return modulereply
def validate(self, targetName, moduleNode = None): """ Validates the configuration of the targetnode by first calling xmllint to valdidate against the VERMONT-Config-Schema.xsd and then check the datapath of the configuration. @rtype: ModuleReply @return: It should return an error if the configuration does not validate """ outdata = "" if (targetName in [C.URL, C.RUNNING]): xmlreply = ModuleReply( error_type=ModuleReply.APPLICATION, error_tag=ModuleReply.OPERATION_NOT_SUPPORTED, error_severity=ModuleReply.ERROR, error_message="OPERATION-NOT-SUPPORTED") return xmlreply # call xmllint to validate against the schema cmd = "xmllint --schema " + C.YENCAP_HOME + "/Modules/VERMONT_Module/VERMONT-Config-Schema.xsd " + C.YENCAP_HOME + '/Modules/VERMONT_Module/' + targetName + '.xml' #cmd = 'xmllint --schema VERMONT-Config-Schema.xsd ' + targetName + '.xml' p = subprocess.Popen(cmd, shell=True, bufsize=1, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True) (child_stdin, child_stdout, child_stderr) = (p.stdin, p.stdout, p.stderr) child_stdin.close() err = child_stderr.readlines() child_stdout.close() child_stderr.close() errdata = err[0] errdataparts = string.split(errdata) if errdataparts[1] != "validates": modulereply = ModuleReply( error_type=ModuleReply.APPLICATION, error_tag=ModuleReply.OPERATION_FAILED, error_severity=ModuleReply.ERROR, error_message= errdata) return modulereply #Data is valid according to the schema VERMONT-Config-Schema.xsd #Now check for the correct order of the processes if moduleNode == None: dataFile = C.YENCAP_HOME + '/Modules/VERMONT_Module/' + targetName + '.xml' #dataFile = targetName + '.xml' configDoc = NonvalidatingReader.parseUri("file:" + dataFile) #PrettyPrint(configDoc) moduleNode = configDoc.documentElement #first check the observationPoints process order, if a observationPoint is followed by packetSelection #there has to be a MeteringProcess with packetReporting as well. #first get all meteringProcesses following the observationPoint: nextMeteringProcesses = [] for node in moduleNode.childNodes: if node.nodeType == Node.ELEMENT_NODE: if node.tagName == "observationPoint": #print "Found observationPoint, checking next process" for childnode in node.childNodes: if childnode.nodeType == Node.ELEMENT_NODE: if childnode.tagName == "next": for nextChild in childnode.childNodes: if nextChild.nodeType == Node.ELEMENT_NODE: if nextChild.tagName == "meteringProcessId": #print "Found next-meteringProcessId" for textChild in nextChild.childNodes: if textChild.nodeType == Node.TEXT_NODE: #print textChild.nodeValue nextMeteringProcesses.append(textChild.nodeValue) #Check if the meteringProcess follows a observationPoint and if it has packetSelection. If it does, it may have packetReporting as well. #If not it has to have a following meteringProcess which does. SearchPR = False for node in moduleNode.childNodes: if node.nodeType == Node.ELEMENT_NODE: if node.tagName == "meteringProcess": meteringProcessId = node.getAttributeNS(EMPTY_NAMESPACE, "id") print "Found Metering Process " print meteringProcessId if meteringProcessId in nextMeteringProcesses: #print "The meteringprocess is next for a OP" for childnode in node.childNodes: if childnode.nodeType == Node.ELEMENT_NODE: if childnode.tagName == "packetSelection": print "It has packetSelection" SearchPR = True if SearchPR: for childnode in node.childNodes: if childnode.nodeType == Node.ELEMENT_NODE: if childnode.tagName == "packetReporting": print "It also has packetReporting -> ok" SearchPR = False #if there is not packetReporting in the same meteringProcess, check the next process. Therefore get the processId. if SearchPR: print "It doesn't have packetReporting, checking next meteringProcess" for childnode in node.childNodes: if childnode.nodeType == Node.ELEMENT_NODE: if childnode.tagName == "next": for nextChild in childnode.childNodes: if nextChild.nodeType == Node.ELEMENT_NODE: if nextChild.tagName == "meteringProcessId": for textChild in nextChild.childNodes: if textChild.nodeType == Node.TEXT_NODE: followUpMeteringProcessId = textChild.nodeValue print "followUp MeteringProcessId: " print followUpMeteringProcessId #Is there such a meteringProcess with packetReporting: for node in moduleNode.childNodes: if node.nodeType == Node.ELEMENT_NODE: if node.tagName == "meteringProcess": #print "Checking meteringprocess: " meteringProcessId = node.getAttributeNS(EMPTY_NAMESPACE, "id") print meteringProcessId if meteringProcessId == followUpMeteringProcessId: #print "MeteringProcess is the follow up process" for childnode in node.childNodes: if childnode.nodeType == Node.ELEMENT_NODE: if childnode.tagName == "packetReporting": print "Found the follow up process with packetreporting" SearchPR = False #If there is no packetReporting, that is an error. if SearchPR: modulereply = ModuleReply( error_type=ModuleReply.APPLICATION, error_tag=ModuleReply.OPERATION_FAILED, error_severity=ModuleReply.ERROR, error_message="Validation error: No packetReporting following a packetSelection.") return modulereply #A collectingProcess can only be followed by a MeteringProcess with flowMetering, so get the following meteringProcesses to check. nextMeteringProcesses = [] for node in moduleNode.childNodes: if node.nodeType == Node.ELEMENT_NODE: if node.tagName == "collectingProcess": for childnode in node.childNodes: if childnode.nodeType == Node.ELEMENT_NODE: if childnode.tagName == "next": for nextChild in childnode.childNodes: if nextChild.nodeType == Node.ELEMENT_NODE: if nextChild.tagName == "meteringProcessId": for textChild in nextChild.childNodes: if textChild.nodeType == Node.TEXT_NODE: nextMeteringProcesses.append(textChild.nodeValue) #Check all following meteringProcess, if they have packetSelection or packetReporting, which will raise an error. for node in moduleNode.childNodes: if node.nodeType == Node.ELEMENT_NODE: if node.tagName == "meteringProcess": meteringProcessId = node.getAttributeNS(EMPTY_NAMESPACE, "id") if meteringProcessId in nextMeteringProcesses: for childnode in node.childNodes: if childnode.nodeType == Node.ELEMENT_NODE: print childnode.tagName if childnode.tagName in ["packetSelection", "packetReporting"]: modulereply = ModuleReply( error_type=ModuleReply.APPLICATION, error_tag=ModuleReply.OPERATION_FAILED, error_severity=ModuleReply.ERROR, error_message="Validation error: packetSelection or packetReporting follows collectingProcess") return modulereply #If everything is correct, just return a ok. modulereply = ModuleReply() return modulereply
xbel1_top_level = \ [ n for n in xbel1.documentElement.childNodes \ if n.nodeType == Node.ELEMENT_NODE ] xbel1_top_level_folders = \ [ n for n in xbel1_top_level if n.nodeName == 'folder' ] xbel1_top_level_bookmarks = \ [ n for n in xbel1_top_level if n.nodeName == 'bookmark' ] xbel2_top_level = \ [ n for n in xbel2.documentElement.childNodes \ if n.nodeType == Node.ELEMENT_NODE ] for elem in xbel2_top_level: if elem.nodeName == 'folder': title = get_title(elem) for a_folder in xbel1_top_level_folders: if title == get_title(a_folder): merge_folders(a_folder, elem) break else: xbel1.documentElement.appendChild(elem) elif elem.nodeName == 'bookmark': xbel1.documentElement.appendChild(elem) return xbel1 if __name__ == "__main__": import sys xbel1 = NonvalidatingReader.parseUri(sys.argv[1]) xbel2 = NonvalidatingReader.parseUri(sys.argv[2]) new_xbel = xbel_merge(xbel1, xbel2) PrettyPrint(new_xbel)
#! /usr/bin/env python2.4 # vim:sw=4:ts=4:et:nowrap # Loads data from BBC election flash applet, and produces XML in the # same format as all-members.xml import sys import os import urllib from Ft.Xml.Domlette import NonvalidatingReader import xml.sax.saxutils # Load in our constituency names consdoc = NonvalidatingReader.parseUri("file:constituencies.xml") cons = {} mainname = {} for consnode in consdoc.xpath('//constituency'): fromdate = consnode.xpath('string(@fromdate)') todate = consnode.xpath('string(@todate)') if fromdate <= "2005-05-05" and "2005-05-05" <= todate: done = False for name in consnode.xpath('./name'): id = name.xpath('string(../@id)') strname = name.xpath('string(@text)') cons[strname] = id if not done: mainname[id] = strname done = True # Load in BBC identifiers and constituency names bbc_ids = {}
sys.stdout = codecs.getwriter('utf-8')(sys.stdout); sys.stderr = codecs.getwriter('utf-8')(sys.stderr); categories = ['n', 'adj', 'np']; if len(sys.argv) < 4: #{ print 'Usage: python generate-bidix-templates.py <left monodix> <bidix> <right monodix>'; sys.exit(-1); #} left_file = sys.argv[1]; bidix_file = sys.argv[2]; right_file = sys.argv[3]; left = NonvalidatingReader.parseUri('file://' + left_file); bidix = NonvalidatingReader.parseUri('file://' + bidix_file); right = NonvalidatingReader.parseUri('file://' + right_file); def generate_monodix_hash(context): #{ path = '/dictionary/pardefs/pardef'; paradigms = {}; for paradigm in Ft.Xml.XPath.Evaluate(path, contextNode=context): #{ current_paradigm = paradigm.getAttributeNS(None, 'n'); current_category = ''; ignoring = 1; for tag in categories: #{ needle = '.*__' + tag + '$'; patron = re.compile(needle); if(patron.match(current_paradigm)): #{ current_category = tag;
def __init__(self, filename): #{ self.config = NonvalidatingReader.parseUri('file:///' + filename) self.log_file = '' self.pairs = {} self.working_directory = None self.templates_directory = None
# A hash of all the paradigms and their constituent suffixes and symbols # # Example: # # paradigms['isk/ola__n_f'] = [(u'ola', u'.n.f.sg'), (u'ejjel', u'.n.f.pl')] # paradigms = {}; # Load the dictionary dictionary = sys.argv[2]; if dictionary == os.path.basename(dictionary): #{ dictionary = os.getcwd() + '/' + dictionary; #} doc = NonvalidatingReader.parseUri('file:///' + dictionary); path = '/dictionary/pardefs/pardef'; # Populate paradigm structure for node in Ft.Xml.XPath.Evaluate(path, contextNode=doc): #{ pardef = node.getAttributeNS(None, 'n'); if pardef.count('__n') < 1 or pardef.count('__np') > 0 or pardef.count('__num') > 0: #{ continue; #} if pardef not in paradigms: #{ paradigms[pardef] = []; #} for child in Ft.Xml.XPath.Evaluate('.//e', contextNode=node): #{
f.close() # Move the new directory to "Modules" directory # ------------------- os.popen4("mv " + dirName + " ../Modules") print "The module (" + name + ") was successfully created in \"server/Modules\" directory." # Update modules.xml # ------------------- path = "file:../conf/modules.xml" doc = NonvalidatingReader.parseUri(path) moduleNode = doc.createElementNS(None,'module') doc.documentElement.appendChild(moduleNode) moduleNode.appendChild(createNode(doc, 'name', name)) moduleNode.appendChild(createNode(doc, 'mainFileName', mainFileName)) moduleNode.appendChild(createNode(doc, 'className', className)) moduleNode.appendChild(createNode(doc, 'xpath', xpathExpression)) moduleNode.appendChild(createNode(doc, 'xsdfile', moduleName+".xsd")) # Print modules document to modules.conf # ------------------- f = open("../conf/modules.xml",'w')
if len(sys.argv) < 2: #{ print 'python paradigm-chopper.py <dix file> [-1|-1line]'; sys.exit(-1); #} if len(sys.argv) == 3: #{ if sys.argv[2] == '-1line' or sys.argv[2] == '-1': #{ format = '1line'; #} #} if dictionary == os.path.basename(dictionary): #{ dictionary = os.getcwd() + '/' + dictionary; #} doc = NonvalidatingReader.parseUri('file:///' + dictionary); path = '/dictionary/pardefs/pardef'; paradigms = {}; def return_symlist(symlist): #{ if len(symlist) < 1: #{ return ''; #} if symlist[0] == '.': #{ symlist = symlist[1:]; #} symlist = symlist.replace(':', '.'); output = ''; for symbol in symlist.split('.'): #{
def load_xml_file(filename): return NonvalidatingReader.parseUri('file://' + os.path.realpath(filename))
import sys, codecs, copy, Ft, os; from Ft.Xml.Domlette import NonvalidatingReader; from Ft.Xml.XPath import Evaluate; sys.stdin = codecs.getreader('utf-8')(sys.stdin); sys.stdout = codecs.getwriter('utf-8')(sys.stdout); sys.stderr = codecs.getwriter('utf-8')(sys.stderr); # Load the rulez (NO RULEZ!!!) rulez = sys.argv[1]; if rulez == os.path.basename(rulez): #{ rulez = os.getcwd() + '/' + rulez; #} doc = NonvalidatingReader.parseUri('file:///' + rulez); path = '/transfer/section-rules/rule'; i = 0; cats = {}; rule_pattern = []; for node in Ft.Xml.XPath.Evaluate('/transfer/section-def-cats/def-cat', contextNode=doc): #{ name = node.getAttributeNS(None, 'n'); print name ; if name not in cats: #{ cats[name] = []; #} for child in Ft.Xml.XPath.Evaluate('.//cat-item', contextNode=node): #{
#! /usr/bin/env python2.4 # vim:sw=4:ts=4:et:nowrap import sys import os import urllib from Ft.Xml.Domlette import NonvalidatingReader import xml.sax.saxutils import re import string # Load in our constituency names consdoc = NonvalidatingReader.parseUri("file:constituencies.xml") allcons = {} mainname = {} for consnode in consdoc.xpath('//constituency'): fromdate = consnode.xpath('string(@fromdate)') todate = consnode.xpath('string(@todate)') if fromdate <= "2005-05-05" and "2005-05-05" <= todate: done = False for name in consnode.xpath('./name'): id = name.xpath('string(../@id)') strname = name.xpath('string(@text)') allcons[strname] = id if not done: mainname[id] = strname done = True # Load in our MP names memberdoc = NonvalidatingReader.parseUri("file:all-members.xml") memberbyconsid = {}
f.write(" \n ") f.close() # Move the new directory to "Modules" directory # ------------------- os.popen4("mv " + dirName + " ../Modules") print "The module (" + name + ") was successfully created in \"server/Modules\" directory." # Update modules.xml # ------------------- path = "file:../conf/modules.xml" doc = NonvalidatingReader.parseUri(path) moduleNode = doc.createElementNS(None, 'module') doc.documentElement.appendChild(moduleNode) moduleNode.appendChild(createNode(doc, 'name', name)) moduleNode.appendChild(createNode(doc, 'mainFileName', mainFileName)) moduleNode.appendChild(createNode(doc, 'className', className)) moduleNode.appendChild(createNode(doc, 'xpath', xpathExpression)) moduleNode.appendChild(createNode(doc, 'xsdfile', moduleName + ".xsd")) # Print modules document to modules.conf # ------------------- f = open("../conf/modules.xml", 'w') PrettyPrint(doc, f)