def open(self): with open(self.filepath, 'r') as f: self.content = f.readlines() libxml2.keepBlanksDefault(0) self.doc = libxml2.parseFile(self.filepath) self.ctxt = self.doc.xpathNewContext()
def __init__(self, filename, plural, singular): self.conf = pcmkconfig.Config() self.plural = plural self.singular = singular self.xml_file = '%s/%s' % (self.conf.dbdir, filename) it_exists = os.access(self.xml_file, os.R_OK) libxml2.keepBlanksDefault(False) try: if it_exists: self.doc = libxml2.parseFile(self.xml_file) except: it_exists = False if not it_exists: self.doc = libxml2.newDoc("1.0") self.root_node = self.doc.newChild(None, plural, None) self.root_node.setProp('pcmkc-version', self.conf.version) else: self.root_node = self.doc.getRootElement() _ver = self.root_node.prop('pcmkc-version') if not _ver == self.conf.version: _msg = '*** warning xml and program version mismatch' print '%s \"%s\" != \"%s\"' % (_msg, _ver, self.conf.version) self.all = {} self.load()
def __init__(self, xml): _XMLBase.__init__(self) # Use of gtksourceview in virt-manager changes this libxml # global setting which messes up whitespace after parsing. # We can probably get away with calling this less but it # would take some investigation libxml2.keepBlanksDefault(1) self._doc = libxml2.parseDoc(xml) self._ctx = self._doc.xpathNewContext() self._ctx.setContextNode(self._doc.children) for key, val in self.NAMESPACES.items(): self._ctx.xpathRegisterNs(key, val)
def find(self): libxml2.keepBlanksDefault(0) if not os.path.exists(config.paths['modulesdir']): messages.append('Netopeer modules directory not found.', 'error') return False module_path = os.path.join(config.paths['modulesdir'], 'Netopeer.xml') if not os.path.isfile(module_path): messages_append('Netopeer module configuration not found', 'error') return False module_doc = libxml2.parseFile(module_path) module_ctxt = module_doc.xpathNewContext() xpath_repo_type = module_ctxt.xpathEval('/device/repo/type') if not xpath_repo_type: messages.append( 'Module Netopeer is not valid, repo type is not specified', 'error') return False elif len(xpath_repo_type) != 1: messages.append( 'Module Netopeer is not valid, there are multiple repo types specified', 'error') return False elif xpath_repo_type[0].get_content() != 'file': messages.append( 'Module Netopeer is not valid, the repository is not a file', 'error') return False xpath_repo_path = module_ctxt.xpathEval('/device/repo/path') if not xpath_repo_path: messages.append( 'Module Netopeer is not valid, repo path is not specified', 'error') return False elif len(xpath_repo_path) != 1: messages.append( 'Module Netopeer is not valid, there are multiple repo paths specified', 'error') return False self.netopeer_path = xpath_repo_path[0].get_content() return True
def base_setup(self): """Set up code needed by all tests.""" date = time.localtime(time.time()) libxml2.keepBlanksDefault(0) styledoc = libxml2.parseFile( os.path.join(ROOT_DIR, "../data/gramps_canonicalize.xsl")) self.style = libxslt.parseStylesheetDoc(styledoc) self.basedoc = None self.base_str = """<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE database PUBLIC "-//GRAMPS//DTD GRAMPS XML %s//EN" "http://gramps-project.org/xml/%s/grampsxml.dtd"> <database xmlns="http://gramps-project.org/xml/%s/"> <header> <created date="%04d-%02d-%02d" version="%s"/> <researcher>\n </researcher> </header> """ % (GRAMPS_XML_VERSION, GRAMPS_XML_VERSION, GRAMPS_XML_VERSION, date[0], date[1], date[2], VERSION)
def find(self): libxml2.keepBlanksDefault(0) if not os.path.exists(config.paths['modulesdir']): messages.append('Netopeer modules directory not found.', 'error') return False module_path = os.path.join(config.paths['modulesdir'], 'Netopeer.xml') if not os.path.isfile(module_path): messages_append('Netopeer module configuration not found', 'error') return False module_doc = libxml2.parseFile(module_path) module_ctxt = module_doc.xpathNewContext() xpath_repo_type = module_ctxt.xpathEval('/device/repo/type') if not xpath_repo_type: messages.append('Module Netopeer is not valid, repo type is not specified', 'error') return False elif len(xpath_repo_type) != 1: messages.append('Module Netopeer is not valid, there are multiple repo types specified', 'error') return False elif xpath_repo_type[0].get_content() != 'file': messages.append('Module Netopeer is not valid, the repository is not a file', 'error') return False xpath_repo_path = module_ctxt.xpathEval('/device/repo/path') if not xpath_repo_path: messages.append('Module Netopeer is not valid, repo path is not specified', 'error') return False elif len(xpath_repo_path) != 1: messages.append('Module Netopeer is not valid, there are multiple repo paths specified', 'error') return False self.netopeer_path = xpath_repo_path[0].get_content() return True
def setUp(self): self.testdatadir = os.path.join(os.path.dirname(__file__), "testdata", "air2os") libxml2.keepBlanksDefault(False)
def open(self): libxml2.keepBlanksDefault(0) self.doc = libxml2.parseFile(self.filepath) self.ctxt = self.doc.xpathNewContext()
import sys import os import datetime import marshal from datetime import datetime import libxml2 libxml2.keepBlanksDefault(0) def OpenTraqTemplate(filePath): root = libxml2.parseFile(filePath) return root.xpathEval('/results/test-run')[0] def GetParameter(node, propName): for property in node.properties: if property.type == 'attribute': if property.name == 'propName': return property.content return "" PredefinedProcessor = {"QQQ": "MFLD", "AAAA": "CTP"} def ValidateTargetProcessorType(node): processor = GetParameter(node, "TargetProcessor") if processor in PredefinedProcessor: node.setProp("TargetProcessor", PredefinedProcessor["processor"]) def CreateBenchamrkResultNode(performanceResultItem): node = libxml2.newNode('test') node.setProp("TestName", performanceResultItem[0])
def setUp(self): self.testdatadir = os.path.join(os.path.dirname(__file__),"testdata","air2os") libxml2.keepBlanksDefault(False)