Пример #1
0
 def __init__(self, restrict=None, exclude=None):
     if restrict: self.restrict = set(restrict)
     if exclude: self.exclude = set(exclude)
     self.parser = libxml2.newParserCtxt()             
     self.opener = urllib2.build_opener()
     self.opener.addheaders = [('User-agent', "Homme's Web Tester (v%s)" % str(__version__))] # User Agent string
     self.visited = set()
Пример #2
0
 def __init__(self, restrict=None, exclude=None):
     if restrict: self.restrict = set(restrict)
     if exclude: self.exclude = set(exclude)
     self.parser = libxml2.newParserCtxt()
     self.opener = urllib2.build_opener()
     self.opener.addheaders = [
         ('User-agent', "Homme's Web Tester (v%s)" % str(__version__))
     ]  # User Agent string
     self.visited = set()
Пример #3
0
    def processInstance(self, filePath, schema):
        global msgInstanceNotValidButShould, msgInstanceValidButShouldNot

        instance = None
        self.debugMsg("loading instance: %s" % filePath)
        instance_parserCtxt = libxml2.newParserCtxt()
        if (instance_parserCtxt is None):
            # TODO: Is this one necessary, or will an exception
            # be already raised?
            raise Exception("Could not create the instance parser context.")
        try:
            try:
                instance = instance_parserCtxt.ctxtReadFile(
                    filePath, None, libxml2.XML_PARSE_NOWARNING)
            except:
                # Suppress exceptions.
                pass
        finally:
            del instance_parserCtxt
        self.debugMsg("after loading instance")
        if instance is None:
            self.debugMsg("instance is None")
            self.failCritical(
                "Failed to parse the instance for unknown reasons.")
            return
        else:
            try:
                #
                # Validate the instance.
                #

                validation_Ctxt = schema.schemaNewValidCtxt()
                #validation_Ctxt = libxml2.schemaNewValidCtxt(None)
                if (validation_Ctxt is None):
                    self.failCritical(
                        "Could not create the validation context.")
                    return
                try:
                    self.debugMsg("validating instance")
                    instance_Err = validation_Ctxt.schemaValidateDoc(instance)
                    self.debugMsg("after instance validation")
                    self.debugMsg("instance-err: %d" % instance_Err)
                    if (instance_Err != 0 and self.instance_Val == 1) or (
                            instance_Err == 0 and self.instance_Val == 0):
                        self.debugMsg("instance result is BAD")
                        if (instance_Err != 0):
                            self.fail(msgInstanceNotValidButShould)
                        else:
                            self.fail(msgInstanceValidButShouldNot)

                    else:
                        self.debugMsg("instance result is OK")
                finally:
                    del validation_Ctxt
            finally:
                instance.freeDoc()
Пример #4
0
    def processInstance(self, filePath, schema):
        global msgInstanceNotValidButShould, msgInstanceValidButShouldNot

        instance = None
        self.debugMsg("loading instance: %s" % filePath)
        instance_parserCtxt = libxml2.newParserCtxt()
        if instance_parserCtxt is None:
            # TODO: Is this one necessary, or will an exception
            # be already raised?
            raise Exception("Could not create the instance parser context.")
        try:
            try:
                instance = instance_parserCtxt.ctxtReadFile(filePath, None, libxml2.XML_PARSE_NOWARNING)
            except:
                # Suppress exceptions.
                pass
        finally:
            del instance_parserCtxt
        self.debugMsg("after loading instance")
        if instance is None:
            self.debugMsg("instance is None")
            self.failCritical("Failed to parse the instance for unknown reasons.")
            return
        else:
            try:
                #
                # Validate the instance.
                #

                validation_Ctxt = schema.schemaNewValidCtxt()
                # validation_Ctxt = libxml2.schemaNewValidCtxt(None)
                if validation_Ctxt is None:
                    self.failCritical("Could not create the validation context.")
                    return
                try:
                    self.debugMsg("validating instance")
                    instance_Err = validation_Ctxt.schemaValidateDoc(instance)
                    self.debugMsg("after instance validation")
                    self.debugMsg("instance-err: %d" % instance_Err)
                    if (instance_Err != 0 and self.instance_Val == 1) or (instance_Err == 0 and self.instance_Val == 0):
                        self.debugMsg("instance result is BAD")
                        if instance_Err != 0:
                            self.fail(msgInstanceNotValidButShould)
                        else:
                            self.fail(msgInstanceValidButShouldNot)

                    else:
                        self.debugMsg("instance result is OK")
                finally:
                    del validation_Ctxt
            finally:
                instance.freeDoc()
Пример #5
0
gen-hash.py generates cryptographic hashes of checklist functions files and
enters the results into the checklists.
'''
__version__ = '0.1'
__revision__ = '$Rev$'

import os
import sys
import sha
import libxml2

xmlFileDir = sys.argv[1]
for f in os.listdir(sys.argv[1]):
    if f.endswith('.xml'):
        xmlFilename = os.path.join(xmlFileDir, f)
        ctxt = libxml2.newParserCtxt()
        checkList = ctxt.ctxtReadFile(xmlFilename, None, 0)
        root = checkList.getRootElement()
        functions = root.xpathEval2('/checklist/functions')
        if not functions:
            continue
        funcFilename = os.path.join(xmlFileDir, functions[0].content)
        funcFile = file(funcFilename, 'r')
        hasher = sha.new()
        for line in funcFile.readlines():
            hasher.update(line)
        sum = hasher.hexdigest()
        functions[0].setProp('hash', sum)
        functions[0].setProp('hashtype', 'sha1')
        checkList.saveFormatFileEnc(xmlFilename, 'UTF-8', True)
sys.exit(0)
    def __init__(self, path):
        ''' Create a new CheckList

        Attributes:
        path -- full pathname of the checklist file we're implementing.

        Creates a new CheckList.
        '''
        self.filename = path # Filename of the checklist we're implementing
        self.resolution = 'Needs-Reviewing' # Resolution of the checklist
        self.functions = [] # List of functions available on the checklist
        # Properties available on the checklist
        self.properties = properties.Properties()
        self.customItemsIter = None # Iter to the custom items category
        self.colors = {}
        self.__unspan = re.compile(r'([^<]*)(<span[^>]*>)?([^<]*)(</span>)?(.*)')
        self.colorRE = re.compile('^#[A-Fa-f0-9]{6}$')
        self.gconfClient = gconf.client_get_default()

        self.gconfClient.add_dir(GCONFPREFIX, gconf.CLIENT_PRELOAD_NONE)
        self.__init_colors('/display/pass-color')
        self.__init_colors('/display/fail-color')
        self.__init_colors('/display/minor-color')
        self.__init_colors('/display/notes-color')
        key = GCONFPREFIX + '/display/no-auto-display'
        try:
            self.noAutoDisplay = self.gconfClient.get_bool(key)
        except gobject.GError:
            self.noAutoDisplay = (
                    self.gconfClient.get_default_from_schema(key).get_bool())
        self.gconfClient.notify_add(key, self.__change_auto_display)
        
        libxml2.registerErrorHandler(self.__no_display_parse_error, None)
        ctxt = libxml2.newParserCtxt()
        try:
            checkFile = ctxt.ctxtReadFile(path, None, libxml2.XML_PARSE_DTDVALID)
        except libxml2.treeError:
            raise error.InvalidChecklist('%s was not an XML file' % (path))

        if not ctxt.isValid():
            checkFile.freeDoc()
            raise error.InvalidChecklist('File does not validate against '
                    'the checklist DTD')

        root = checkFile.getRootElement()
        if root.name != 'checklist':
            checkFile.freeDoc()
            raise error.InvalidChecklist('File is not a valid checklist '
                    'policy file')
        if root.prop('version') != self.formatVersion:
            checkFile.freeDoc()
            raise error.InvalidChecklist('Checklist file is not a known '
                    'version')
       
        # Extract the name and revision of the CheckList
        self.name = root.prop('name')
        if not self.name:
            checkFile.freeDoc()
            raise error.InvalidChecklist('Checklist file does not specify '
                    'a name for itself')
        self.revision = root.prop('revision') or '0'

        summary = root.xpathEval2('/checklist/summary')
        if summary:
            self.summary = summary[0].content
        else:
            checkFile.freeDoc()
            raise error.InvalidChecklist('Checklist does not have a summary')

        # Create GtkTreeModel struct to store info in.
        gtk.TreeStore.__init__(self, gobject.TYPE_BOOLEAN,
                gobject.TYPE_BOOLEAN,
                gobject.TYPE_STRING,
                gobject.TYPE_STRING,
                gobject.TYPE_STRING,
                gobject.TYPE_STRING,
                gobject.TYPE_PYOBJECT,
                gobject.TYPE_PYOBJECT,
                gobject.TYPE_PYOBJECT)
        base = root.xpathEval2('/checklist/base')
        if base:
            # We are loading a savefile.  Just load the base info.
            self.baseName = base[0].prop('name')
            self.baseRevision = base[0].prop('revision')
            self.baseFilename = base[0].content
            self.revision = int(self.revision)
        else:
            # We are loading an original checklist definition.  Set its values
            # as the base and set the CheckList info to good values.
            self.baseName = self.name
            self.baseRevision = self.revision
            self.baseFilename = path
            self.filename = None
            self.revision = 0
        
        # Extract properties from the CheckList file
        props = root.xpathEval2('/checklist/properties/property')
        for p in props:
            propChild = p.children
            propEntry = properties.PropEntry()
            propEntry.valueType = p.prop('type')
            while propChild:
                if propChild.name == 'require':
                    propEntry.propType = propChild.prop('type')
                    requireChild = propChild.children
                    while requireChild:
                        if requireChild.name == 'arg':
                            propEntry.args.append(requireChild.content)
                        elif requireChild.name == 'function':
                            propEntry.function = requireChild.content
                            propEntry.functionType = requireChild.prop('type')
                        requireChild = requireChild.next
                elif propChild.name == 'value':
                    propEntry.value = propChild.content
                propChild = propChild.next
            # Set the property
            self.properties[p.prop('name')] = propEntry

        # Extract functions for the QA menu
        functions = root.xpathEval2('/checklist/functions/function')
        for function in functions:
            self.functions.append((function.content, function.prop('type')))

        # Record each category as a toplevel in the tree
        categories = root.xpathEval2('/checklist/category')
        self.entries = {}
        for category in categories:
            newCat = self.append(None)
            gtk.TreeStore.set(self, newCat,
                    ISITEM, False,
                    RESLIST, ['Needs-Reviewing', 'Pass', 'Fail'],
                    RESOLUTION, 'Needs-Reviewing',
                    OUTPUT, '',
                    OUTPUTLIST, {'Needs-Reviewing': '',
                                 'Pass': '', 'Fail': ''},
                    SUMMARY, category.prop('name'),
                    TEST, None)
            self.entries[category.prop('name').lower()] = newCat

            # Entries are subheadings
            node = category.children
            while node:
                if node.name == 'description':
                    # Set DESCRIPTION of the heading
                    desc = string.join(string.split(node.content))
                    gtk.TreeStore.set(self, newCat, DESC, desc)
                elif node.name == 'entry':
                    entry = self.__xml_to_entry(node)
                    entryIter=self.append(newCat)
                    gtk.TreeStore.set(self, entryIter,
                            ISITEM, True,
                            DISPLAY, entry.display,
                            SUMMARY, entry.name,
                            TEST, entry.test,
                            DESC, entry.desc)
                    self.entries[entry.name.lower()] = entryIter
                    
                    # Construct the resolution from multiple states
                    outputList={'Needs-Reviewing': ''}
                    resolutionList=['Needs-Reviewing']
                    for i in range(len(entry.states)):
                        name = entry.states[i]['name']
                        # Order is important: We pangoize as things enter
                        # OUTPUT, not OUTPUTLIST.
                        outputList[name] = entry.states[i]['output']
                        if name != 'Needs-Reviewing':
                            resolutionList.append(entry.states[i]['name'])
                    
                    res = entry.state
                    gtk.TreeStore.set(self, entryIter,
                            RESLIST, resolutionList,
                            OUTPUTLIST, outputList,
                            RESOLUTION, res,
                            OUTPUT, self.pangoize_output(res,
                                outputList[res]))
                else:
                    # DTD validation should make this ignorable.
                    pass
                  
                node = node.next

        checkFile.freeDoc()

        ### FIXME: Merge code:  This is pretty close to what we have in:
        # __check_resolution().  We could potentially merge these two pieces
        # of code together.
        category = self.get_iter_root()
        catIter = category
        while catIter:
            entryIter = self.iter_children(catIter)
            newRes = 'Pass'
            while entryIter:
                res = self.get_value(entryIter, RESOLUTION)
                if res == 'Fail':
                    newRes = 'Fail'
                    break
                elif res == 'Needs-Reviewing':
                    newRes = 'Needs-Reviewing'
                entryIter = self.iter_next(entryIter)
            gtk.TreeStore.set(self, catIter, RESOLUTION, newRes)
            catIter = self.iter_next(catIter)
        # Instead of code we could have:
        # self.__check_resolution(category, 'Pass') 
        newRes = 'Pass'
        while category:
            res = self.get_value(category, RESOLUTION)
            if res == 'Fail':
                newRes = 'Fail'
                break
            elif res == 'Needs-Reviewing':
                newRes = 'Needs-Reviewing'
            category = self.iter_next(category)
        self.resolution = newRes
Пример #7
0
 def __init__ (self, filename):
     ctxt = libxml2.newParserCtxt ()
     self._doc = ctxt.ctxtReadFile (filename, None, 0)
     self._defaults = ()
     self.data = self._read_group (self._doc.getRootElement ())
    def __init__(self, path, props):

        self.customItemsPath = None
        self.props = props
        self.addPaths = {}
        libxml2.registerErrorHandler(self.__no_display_parse_error, None)
        ctxt = libxml2.newParserCtxt()
        checkFile = ctxt.ctxtReadFile(path, None, libxml2.XML_PARSE_DTDVALID)

        if ctxt.isValid() == False:
            raise Error("File does not validate against the checklist DTD")

        root = checkFile.getRootElement()
        if root.name != 'checklist':
            raise Error("File is not a valid checklist policy file")
        if root.prop('version') != _checklistFileVersion_:
            raise Error("Checklist file is not a known version")
        
        # Extract the type from the checklist tag
        self.name = root.prop('name')
        if not self.name:
            raise Error("Checklist file does not specify a name for itself")
        self.revision = root.prop('revision')
        if not self.revision:
            self.revision='0'
        self.type = root.prop('type')
        if not self.type:
            self.type = 'generic'

        # Store the checklist into a GtkTreeModel
        self.tree = gtk.TreeStore(gobject.TYPE_BOOLEAN,
                                  gobject.TYPE_BOOLEAN,
                                  gobject.TYPE_BOOLEAN,
                                  gobject.TYPE_STRING,
                                  gobject.TYPE_STRING,
                                  gobject.TYPE_STRING,
                                  gobject.TYPE_STRING,
                                  gobject.TYPE_PYOBJECT,
                                  gobject.TYPE_PYOBJECT)

        # Record each category as a toplevel in the tree
        categories = root.xpathEval2('/checklist/category')
        self.entries = {}
        for category in categories:
            iter = self.tree.append(None)
            self.tree.set(iter,
                          ISITEM, False,
                          MODIFIED, False,
                          RESLIST, ['Needs-Reviewing', 'Pass', 'Fail'],
                          RESOLUTION, 'Needs-Reviewing',
                          OUTPUT, None,
                          OUTPUTLIST, {'Needs-Reviewing':None,
                                       'Pass':None, 'Fail':None},
                          SUMMARY, category.prop('name'))
            self.entries[category.prop('name')] = iter

            # Entries are subheadings
            node = category.children
            while node:
                if node.name == 'description':
                    # Set DESCRIPTION of the heading
                    desc = string.join(string.split(node.content))
                    self.tree.set(iter, DESC, desc)
                elif node.name == 'entry':
                    entry = self.__xml_to_entry(node)
                    entryIter=self.tree.append(iter)
                    self.tree.set(entryIter,
                                  ISITEM, True,
                                  MODIFIED, False,
                                  DISPLAY, entry.display,
                                  SUMMARY, entry.name,
                                  DESC, entry.desc)
                    self.entries[entry.name] = entryIter
                    
                    # Construct the resolution from multiple states
                    resolutions={'Needs-Reviewing': None}
                    resolutionList=['Needs-Reviewing']
                    for i in range(len(entry.states)):
                        name = entry.states[i]['name']
                        output = self.colorize_output(name,
                                entry.states[i]['output'])
                        resolutions[name] = output
                        if name != 'Needs-Reviewing':
                            resolutionList.append(entry.states[i]['name'])
                        
                    self.tree.set(entryIter,
                                  RESLIST, resolutionList,
                                  OUTPUTLIST, resolutions,
                                  RESOLUTION, 'Needs-Reviewing',
                                  OUTPUT, resolutions['Needs-Reviewing'])
                else:
                    # DTD validation should make this ignorable.
                    pass
                  
                node = node.next

        checkFile.freeDoc()
        # More efficient to do the stuff in the signal handlers manually
        # during setup and only register them afterwards.
        self.tree.connect('row-inserted', self.__added_row)
        self.tree.connect('row-changed', self.__modified_row)
Пример #9
0
	def validate(self):
		instance = None
		schema = None
		filePath = self.fileName
		# os.path.join(options.baseDir, self.fileName)

		if not self.group.schemaParsed and self.group.schemaTried:
			self.failNoSchema()
			return
					
		self.debugMsg("loading instance: %s" % filePath)
		parserCtxt = libxml2.newParserCtxt()
		if (parserCtxt is None):
			# TODO: Is this one necessary, or will an exception
			# be already raised?
			raise Exception("Could not create the instance parser context.")
		if not options.validationSAX:
			try:
				try:
					instance = parserCtxt.ctxtReadFile(filePath, None, libxml2.XML_PARSE_NOWARNING)
				except:
					# Suppress exceptions.
					pass
			finally:
				del parserCtxt
			self.debugMsg("after loading instance")
			if instance is None:
				self.debugMsg("instance is None")
				self.failCritical("Failed to parse the instance for unknown reasons.")
				return		
		try:
			#
			# Validate the instance.
			#
			self.debugMsg("loading schema: %s" % self.group.schemaFileName)
			schema = parseSchema(self.group.schemaFileName)
			try:
				validationCtxt = schema.schemaNewValidCtxt()
				#validationCtxt = libxml2.schemaNewValidCtxt(None)
				if (validationCtxt is None):
					self.failCritical("Could not create the validation context.")
					return
				try:
					self.debugMsg("validating instance")
					if options.validationSAX:
						instance_Err = validationCtxt.schemaValidateFile(filePath, 0)
					else:
						instance_Err = validationCtxt.schemaValidateDoc(instance)
					self.debugMsg("after instance validation")
					self.debugMsg("instance-err: %d" % instance_Err)
					if (instance_Err != 0 and self.val == 1) or (instance_Err == 0 and self.val == 0):
						self.debugMsg("instance result is BAD")
						if (instance_Err != 0):
							self.fail(msgInstanceNotValidButShould)
						else:
							self.fail(msgInstanceValidButShouldNot)

					else:
								self.debugMsg("instance result is OK")
				finally:
					del validationCtxt
			finally:
				del schema
		finally:
			if instance is not None:
				instance.freeDoc()
Пример #10
0
    def validate(self):
        instance = None
        schema = None
        filePath = self.fileName
        # os.path.join(options.baseDir, self.fileName)

        if not self.group.schemaParsed and self.group.schemaTried:
            self.failNoSchema()
            return

        self.debugMsg("loading instance: %s" % filePath)
        parserCtxt = libxml2.newParserCtxt()
        if (parserCtxt is None):
            # TODO: Is this one necessary, or will an exception
            # be already raised?
            raise Exception("Could not create the instance parser context.")
        if not options.validationSAX:
            try:
                try:
                    instance = parserCtxt.ctxtReadFile(
                        filePath, None, libxml2.XML_PARSE_NOWARNING)
                except:
                    # Suppress exceptions.
                    pass
            finally:
                del parserCtxt
            self.debugMsg("after loading instance")
            if instance is None:
                self.debugMsg("instance is None")
                self.failCritical(
                    "Failed to parse the instance for unknown reasons.")
                return
        try:
            #
            # Validate the instance.
            #
            self.debugMsg("loading schema: %s" % self.group.schemaFileName)
            schema = parseSchema(self.group.schemaFileName)
            try:
                validationCtxt = schema.schemaNewValidCtxt()
                #validationCtxt = libxml2.schemaNewValidCtxt(None)
                if (validationCtxt is None):
                    self.failCritical(
                        "Could not create the validation context.")
                    return
                try:
                    self.debugMsg("validating instance")
                    if options.validationSAX:
                        instance_Err = validationCtxt.schemaValidateFile(
                            filePath, 0)
                    else:
                        instance_Err = validationCtxt.schemaValidateDoc(
                            instance)
                    self.debugMsg("after instance validation")
                    self.debugMsg("instance-err: %d" % instance_Err)
                    if (instance_Err != 0
                            and self.val == 1) or (instance_Err == 0
                                                   and self.val == 0):
                        self.debugMsg("instance result is BAD")
                        if (instance_Err != 0):
                            self.fail(msgInstanceNotValidButShould)
                        else:
                            self.fail(msgInstanceValidButShouldNot)

                    else:
                        self.debugMsg("instance result is OK")
                finally:
                    del validationCtxt
            finally:
                del schema
        finally:
            if instance is not None:
                instance.freeDoc()
Пример #11
0
    def process_mallard_page(cls, document, filename, cache, scanner):
        title = None
        desc = None
        ctxt = libxml2.newParserCtxt()
        xmldoc = ctxt.ctxtReadFile(
            filename,
            None,
            libxml2.XML_PARSE_DTDLOAD | libxml2.XML_PARSE_NOCDATA | libxml2.XML_PARSE_NOENT | libxml2.XML_PARSE_NONET,
        )
        xmldoc.xincludeProcess()
        root = xmldoc.getRootElement()
        if not _is_ns_name(root, MALLARD_NS, "page"):
            return
        pageid = root.prop("id")
        cache.data.setdefault(pageid, {})
        cache.data[pageid]["topiclinks"] = []
        cache.data[pageid]["guidelinks"] = []
        pkgseries = document.parent.data.get("pkgseries", None)
        revision = {}

        def process_link_node(linknode):
            linktype = linknode.prop("type")
            if linktype not in ("topic", "guide"):
                return
            xref = linknode.prop("xref")
            xrefhash = xref.find("#")
            if xrefhash >= 0:
                xref = xref[:xrefhash]
            if xref != "":
                lst = cache.data[pageid][linktype + "links"]
                if xref not in lst:
                    lst.append(xref)

        for node in xmliter(root):
            if node.type != "element":
                continue
            if _is_ns_name(node, MALLARD_NS, "info"):
                for infonode in xmliter(node):
                    if infonode.type != "element":
                        continue
                    if _is_ns_name(infonode, MALLARD_NS, "title"):
                        if infonode.prop("type") == "text":
                            title = normalize(infonode.getContent())
                    elif _is_ns_name(infonode, MALLARD_NS, "desc"):
                        desc = normalize(infonode.getContent())
                    elif _is_ns_name(infonode, MALLARD_NS, "revision"):
                        if pkgseries is not None:
                            for prop in ("version", "docversion", "pkgversion"):
                                if infonode.prop(prop) == pkgseries:
                                    revdate = infonode.prop("date")
                                    revstatus = infonode.prop("status")
                                    if (not revision.has_key(prop)) or (revdate > revision[prop][0]):
                                        revision[prop] = (revdate, revstatus)
                    elif _is_ns_name(infonode, MALLARD_NS, "credit"):
                        types = infonode.prop("type")
                        if isinstance(types, basestring):
                            types = types.split()
                        else:
                            types = []
                        crname = cremail = None
                        for crnode in xmliter(infonode):
                            if _is_ns_name(crnode, MALLARD_NS, "name"):
                                crname = normalize(crnode.getContent())
                            elif _is_ns_name(crnode, MALLARD_NS, "email"):
                                cremail = normalize(crnode.getContent())
                        if crname is not None or cremail is not None:
                            cache.data[pageid].setdefault("credits", [])
                            cache.data[pageid]["credits"].append((crname, cremail, types))
                    elif _is_ns_name(infonode, MALLARD_NS, "link"):
                        process_link_node(infonode)
            elif _is_ns_name(node, MALLARD_NS, "title"):
                if title is None:
                    title = normalize(node.getContent())
            elif _is_ns_name(node, MALLARD_NS, "section"):
                for child in xmliter(node):
                    if child.type != "element":
                        continue
                    if _is_ns_name(child, MALLARD_NS, "info"):
                        for infonode in xmliter(child):
                            if infonode.type != "element":
                                continue
                            if _is_ns_name(infonode, MALLARD_NS, "link"):
                                process_link_node(infonode)

        docstatus = None
        docdate = None
        if pageid is not None:
            ident = u"/page/" + pageid + document.ident
            page = blip.db.Branch.get_or_create(ident, u"DocumentPage")
            page.parent = document
            for key in ("scm_type", "scm_server", "scm_module", "scm_branch", "scm_path", "scm_dir"):
                setattr(page, key, getattr(document, key))
            page.scm_file = os.path.basename(filename)
            if title is not None:
                page.name = blip.utils.utf8dec(title)
            if desc is not None:
                page.desc = blip.utils.utf8dec(desc)
            for prop in ("pkgversion", "docversion", "version"):
                if revision.has_key(prop):
                    (docdate, docstatus) = revision[prop]
                    docstatus = get_status(docstatus)
                    page.data["docstatus"] = docstatus
                    page.data["docdate"] = docdate
            rels = []
            for cr_name, cr_email, cr_types in cache.data[pageid].get("credits", []):
                ent = None
                if cr_email is not None:
                    ent = blip.db.Entity.get_or_create_email(cr_email)
                if ent is None:
                    ident = u"/ghost/" + urllib.quote(cr_name)
                    ent = blip.db.Entity.get_or_create(ident, u"Ghost")
                    if ent.ident == ident:
                        ent.name = blip.utils.utf8dec(cr_name)
                if ent is not None:
                    ent.extend(name=blip.utils.utf8dec(cr_name))
                    ent.extend(email=blip.utils.utf8dec(cr_email))
                    rel = blip.db.DocumentEntity.set_related(page, ent)
                    for badge in ("maintainer", "author", "editor", "pulisher"):
                        setattr(rel, badge, badge in cr_types)
                    rels.append(rel)
            page.set_relations(blip.db.DocumentEntity, rels)

        if pageid == "index":
            if title is not None:
                document.name = blip.utils.utf8dec(title)
            if desc is not None:
                document.desc = blip.utils.utf8dec(desc)
            document.data["docstatus"] = docstatus
            document.data["docdate"] = docdate
Пример #12
0
    def process_docbook(cls, document, scanner):
        filename = os.path.join(scanner.repository.directory, document.scm_dir, document.scm_file)
        rel_scm = blip.utils.relative_path(filename, blinq.config.scm_dir)
        blip.utils.log("Processing %s" % rel_scm)

        title = None
        abstract = None
        credits = []
        process = False
        with blip.db.Error.catch(document):
            ctxt = libxml2.newParserCtxt()
            xmldoc = ctxt.ctxtReadFile(
                filename,
                None,
                libxml2.XML_PARSE_DTDLOAD
                | libxml2.XML_PARSE_NOCDATA
                | libxml2.XML_PARSE_NOENT
                | libxml2.XML_PARSE_NONET,
            )
            xmldoc.xincludeProcess()
            root = xmldoc.getRootElement()
            process = True
        if not process:
            return
        seen = 0
        document.data["status"] = "00none"
        for node in xmliter(root):
            if node.type != "element":
                continue
            if node.name[-4:] == "info":
                seen += 1
                infonodes = list(xmliter(node))
                i = 0
                while i < len(infonodes):
                    infonode = infonodes[i]
                    if infonode.type != "element":
                        i += 1
                        continue
                    if infonode.name == "title":
                        if title is None:
                            title = infonode.getContent()
                    elif infonode.name == "abstract" and infonode.prop("role") == "description":
                        abstract = infonode.getContent()
                    elif infonode.name == "releaseinfo":
                        if infonode.prop("revision") == document.parent.data.get("pkgseries"):
                            document.data["docstatus"] = get_status(infonode.prop("role"))
                    elif infonode.name == "authorgroup":
                        infonodes.extend(list(xmliter(infonode)))
                    elif infonode.name in ("author", "editor", "othercredit"):
                        cr_name, cr_email = personname(infonode)
                        maint = infonode.prop("role") == "maintainer"
                        credits.append((cr_name, cr_email, infonode.name, maint))
                    elif infonode.name == "collab":
                        cr_name = None
                        for ch in xmliter(infonode):
                            if ch.type == "element" and ch.name == "collabname":
                                cr_name = normalize(ch.getContent())
                        if cr_name is not None:
                            maint = infonode.prop("role") == "maintainer"
                            credits.append((cr_name, None, "collab", maint))
                    elif infonode.name in ("corpauthor", "corpcredit"):
                        maint = infonode.prop("role") == "maintainer"
                        credits.append((normalize(infonode.getContent()), None, infonode.name, maint))
                    elif infonode.name == "publisher":
                        cr_name = None
                        for ch in xmliter(infonode):
                            if ch.type == "element" and ch.name == "publishername":
                                cr_name = normalize(ch.getContent())
                        if cr_name is not None:
                            maint = infonode.prop("role") == "maintainer"
                            credits.append((cr_name, None, "publisher", maint))
                    i += 1
            elif node.name == "title":
                seen += 1
                title = node.getContent()
            if seen > 1:
                break

        if title is not None:
            document.name = unicode(normalize(title))
        if abstract is not None:
            document.desc = unicode(normalize(abstract))

        rels = []
        for cr_name, cr_email, cr_type, cr_maint in credits:
            ent = None
            if cr_email is not None:
                ent = blip.db.Entity.get_or_create_email(cr_email)
            if ent is None:
                ident = u"/ghost/" + urllib.quote(cr_name)
                ent = blip.db.Entity.get_or_create(ident, u"Ghost")
                if ent.ident == ident:
                    ent.name = blip.utils.utf8dec(cr_name)
            if ent is not None:
                ent.extend(name=blip.utils.utf8dec(cr_name))
                ent.extend(email=blip.utils.utf8dec(cr_email))
                rel = blip.db.DocumentEntity.set_related(document, ent)
                rel.author = cr_type in ("author", "corpauthor")
                rel.editor = cr_type == "editor"
                rel.publisher = cr_type == "publisher"
                rel.maintainer = cr_maint == True
                rels.append(rel)
        document.set_relations(blip.db.DocumentEntity, rels)
Пример #13
0
    def __init__(self, path):
        """ Create a new CheckList

        Attributes:
        path -- full pathname of the checklist file we're implementing.

        Creates a new CheckList.
        """
        self.filename = path  # Filename of the checklist we're implementing
        self.resolution = "Needs-Reviewing"  # Resolution of the checklist
        self.functions = []  # List of functions available on the checklist
        self.properties = {}  # List of properties available on the checklist
        self.customItemsIter = None  # Iter to the custom items category
        self.colors = {}
        self.__unspan = re.compile(r"([^<]*)(<span[^>]*>)?([^<]*)(</span>)?(.*)")
        self.colorRE = re.compile("^#[A-Fa-f0-9]{6}$")
        self.gconfClient = gconf.client_get_default()

        self.gconfClient.add_dir(GCONFPREFIX, gconf.CLIENT_PRELOAD_NONE)
        self.__init_colors("/display/pass-color")
        self.__init_colors("/display/fail-color")
        self.__init_colors("/display/minor-color")
        self.__init_colors("/display/notes-color")
        key = GCONFPREFIX + "/display/no-auto-display"
        self.noAutoDisplay = self.gconfClient.get_bool(key)
        self.gconfClient.notify_add(key, self.__change_auto_display)

        libxml2.registerErrorHandler(self.__no_display_parse_error, None)
        ctxt = libxml2.newParserCtxt()
        try:
            checkFile = ctxt.ctxtReadFile(path, None, libxml2.XML_PARSE_DTDVALID)
        except libxml2.treeError:
            raise error.InvalidChecklist("%s was not an XML file" % (path))

        if not ctxt.isValid():
            raise error.InvalidChecklist("File does not validate against " "the checklist DTD")

        root = checkFile.getRootElement()
        if root.name != "checklist":
            raise error.InvalidChecklist("File is not a valid checklist " "policy file")
        if root.prop("version") != self.formatVersion:
            raise error.InvalidChecklist("Checklist file is not a known " "version")

        # Extract the name and revision of the CheckList
        self.name = root.prop("name")
        if not self.name:
            raise error.InvalidChecklist("Checklist file does not specify " "a name for itself")
        self.revision = root.prop("revision") or "0"

        summary = root.xpathEval2("/checklist/summary")
        if summary:
            self.summary = summary[0].content
        else:
            raise error.InvalidChecklist("Checklist does not have a summary")

        # Create GtkTreeModel struct to store info in.
        gtk.TreeStore.__init__(
            self,
            gobject.TYPE_BOOLEAN,
            gobject.TYPE_BOOLEAN,
            gobject.TYPE_STRING,
            gobject.TYPE_STRING,
            gobject.TYPE_STRING,
            gobject.TYPE_STRING,
            gobject.TYPE_PYOBJECT,
            gobject.TYPE_PYOBJECT,
            gobject.TYPE_PYOBJECT,
        )
        base = root.xpathEval2("/checklist/base")
        if base:
            # We are loading a savefile.  Just load the base info.
            self.baseName = base[0].prop("name")
            self.baseRevision = base[0].prop("revision")
            self.baseFilename = base[0].content
            self.revision = int(self.revision)
        else:
            # We are loading an original checklist definition.  Set its values
            # as the base and set the CheckList info to good values.
            self.baseName = self.name
            self.baseRevision = self.revision
            self.baseFilename = path
            self.filename = None
            self.name += " savefile"
            self.revision = 0

        # Extract properties from the CheckList file
        properties = root.xpathEval2("/checklist/properties/property")
        for p in properties:
            propChild = p.children
            value = None
            function = None
            functionType = None
            args = []
            while propChild:
                if propChild.name == "require":
                    require = propChild.prop("type")
                    requireChild = propChild.children
                    while requireChild:
                        if requireChild.name == "arg":
                            args.append(requireChild.content)
                        elif requireChild.name == "function":
                            function = requireChild.content
                            functionType = requireChild.prop("type")
                        requireChild = requireChild.next
                elif propChild.name == "value":
                    value = propChild.content
                propChild = propChild.next
            # Set the property
            self.properties[p.prop("name")] = self.__Property(
                p.prop("type"), value, require, function, functionType, args
            )

        # Extract functions for the QA menu
        functions = root.xpathEval2("/checklist/functions/function")
        for function in functions:
            self.functions.append((function.content, function.prop("type")))

        # Record each category as a toplevel in the tree
        categories = root.xpathEval2("/checklist/category")
        self.entries = {}
        for category in categories:
            newCat = self.append(None)
            gtk.TreeStore.set(
                self,
                newCat,
                ISITEM,
                False,
                RESLIST,
                ["Needs-Reviewing", "Pass", "Fail"],
                RESOLUTION,
                "Needs-Reviewing",
                OUTPUT,
                "",
                OUTPUTLIST,
                {"Needs-Reviewing": "", "Pass": "", "Fail": ""},
                SUMMARY,
                category.prop("name"),
                TEST,
                None,
            )
            self.entries[category.prop("name").lower()] = newCat

            # Entries are subheadings
            node = category.children
            while node:
                if node.name == "description":
                    # Set DESCRIPTION of the heading
                    desc = string.join(string.split(node.content))
                    gtk.TreeStore.set(self, newCat, DESC, desc)
                elif node.name == "entry":
                    entry = self.__xml_to_entry(node)
                    entryIter = self.append(newCat)
                    gtk.TreeStore.set(
                        self,
                        entryIter,
                        ISITEM,
                        True,
                        DISPLAY,
                        entry.display,
                        SUMMARY,
                        entry.name,
                        TEST,
                        entry.test,
                        DESC,
                        entry.desc,
                    )
                    self.entries[entry.name.lower()] = entryIter

                    # Construct the resolution from multiple states
                    outputList = {"Needs-Reviewing": ""}
                    resolutionList = ["Needs-Reviewing"]
                    for i in range(len(entry.states)):
                        name = entry.states[i]["name"]
                        # Order is important: We pangoize as things enter
                        # OUTPUT, not OUTPUTLIST.
                        outputList[name] = entry.states[i]["output"]
                        if name != "Needs-Reviewing":
                            resolutionList.append(entry.states[i]["name"])

                    res = entry.state
                    gtk.TreeStore.set(
                        self,
                        entryIter,
                        RESLIST,
                        resolutionList,
                        OUTPUTLIST,
                        outputList,
                        RESOLUTION,
                        res,
                        OUTPUT,
                        self.pangoize_output(res, outputList[res]),
                    )
                else:
                    # DTD validation should make this ignorable.
                    pass

                node = node.next

        checkFile.freeDoc()

        ### FIXME: Merge code:  This is pretty close to what we have in:
        # __check_resolution().  We could potentially merge these two pieces
        # of code together.
        category = self.get_iter_root()
        catIter = category
        while catIter:
            entryIter = self.iter_children(catIter)
            newRes = "Pass"
            while entryIter:
                res = self.get_value(entryIter, RESOLUTION)
                if res == "Fail":
                    newRes = "Fail"
                    break
                elif res == "Needs-Reviewing":
                    newRes = "Needs-Reviewing"
                entryIter = self.iter_next(entryIter)
            gtk.TreeStore.set(self, catIter, RESOLUTION, newRes)
            catIter = self.iter_next(catIter)
        # Instead of code we could have:
        # self.__check_resolution(category, 'Pass')
        newRes = "Pass"
        while category:
            res = self.get_value(category, RESOLUTION)
            if res == "Fail":
                newRes = "Fail"
                break
            elif res == "Needs-Reviewing":
                newRes = "Needs-Reviewing"
            category = self.iter_next(category)
        self.resolution = newRes
Пример #14
0
    def __init__(self, path, props):

        libxml2.registerErrorHandler(self.__noDisplayParseError, None)
        ctxt = libxml2.newParserCtxt()
        checkFile = ctxt.ctxtReadFile(path, None, libxml2.XML_PARSE_DTDVALID)

        if ctxt.isValid() == False:
            raise Error("File does not validate against the checklist DTD")

        root = checkFile.getRootElement()
        if root.name != "checklist":
            raise Error("File is not a valid checklist policy file")
        if root.prop("version") != _checklistFileVersion_:
            raise Error("Checklist file is not a known version")

        # Extract the type from the checklist tag
        self.name = root.prop("name")
        if not self.name:
            raise Error("Checklist file does not specify a name for itself")
        self.revision = root.prop("revision")
        if not self.revision:
            self.revision = "0"
        self.type = root.prop("type")
        if not self.type:
            self.type = "generic"

        # Store the checklist into a GtkTreeModel
        self.tree = gtk.TreeStore(
            gobject.TYPE_BOOLEAN,
            gobject.TYPE_BOOLEAN,
            gobject.TYPE_STRING,
            gobject.TYPE_STRING,
            gobject.TYPE_STRING,
            gobject.TYPE_STRING,
            gobject.TYPE_PYOBJECT,
            gobject.TYPE_PYOBJECT,
        )

        # Record each category as a toplevel in the tree
        categories = root.xpathEval2("/checklist/category")
        for category in categories:
            iter = self.tree.append(None)
            self.tree.set(
                iter,
                ISITEM,
                False,
                RESLIST,
                ["Needs-Reviewing", "Pass", "Fail"],
                RESOLUTION,
                "Needs-Reviewing",
                OUTPUT,
                None,
                OUTPUTLIST,
                {"Needs-Reviewing": None, "Pass": None, "Fail": None},
                SUMMARY,
                category.prop("name"),
            )

            # Entries are subheadings
            node = category.children
            while node:
                if node.name == "description":
                    # Set DESCRIPTION of the heading
                    desc = string.join(string.split(node.content))
                    self.tree.set(iter, DESC, desc)
                elif node.name == "entry":
                    entry = self.__xmlToEntry(node)
                    entryIter = self.tree.append(iter)
                    self.tree.set(
                        entryIter, ISITEM, True, DISPLAY, entry.display, SUMMARY, entry.name, DESC, entry.desc
                    )
                    # Construct the resolution from multiple states
                    resolutions = {"Needs-Reviewing": None}
                    resolutionList = ["Needs-Reviewing"]
                    for i in range(len(entry.states)):
                        name = entry.states[i]["name"]
                        output = entry.states[i]["output"]
                        if name == "Fail":
                            color = props.failColor
                        elif name == "Non-Blocker" or name == "Needs-Reviewing":
                            color = props.minorColor
                        elif name == "Pass":
                            color = props.passColor
                        else:
                            color = None
                        if color:
                            output = '<span foreground="' + color + '">' + output + "</span>"

                        resolutions[name] = output
                        if name != "Needs-Reviewing":
                            resolutionList.append(entry.states[i]["name"])

                    self.tree.set(
                        entryIter,
                        RESLIST,
                        resolutionList,
                        OUTPUTLIST,
                        resolutions,
                        RESOLUTION,
                        "Needs-Reviewing",
                        OUTPUT,
                        resolutions["Needs-Reviewing"],
                    )
                else:
                    # DTD validation should make this ignorable.
                    pass

                node = node.next

        checkFile.freeDoc()
Пример #15
0
    def __init__(self, path):
        
        libxml2.registerErrorHandler(self.__noDisplayParseError, None)
        ctxt = libxml2.newParserCtxt()
        checkFile = ctxt.ctxtReadFile(path, None, libxml2.XML_PARSE_DTDVALID)

        if ctxt.isValid() == False:
            raise Error("File does not validate against the checklist DTD")

        root = checkFile.getRootElement()
        if root.name != 'checklist':
            raise Error("File is not a valid checklist policy file")
        if root.prop('version') != _checklistFileVersion_:
            raise Error("Checklist file is not a known version")
        
        # Extract the type from the checklist tag
        self.type = root.prop('name')
        if not self.type:
            raise Error("Checklist file does not specify a type in the name attribute")
        self.revision = root.prop('revision')
        if not self.revision:
            self.revision='0'

        # Store the checklist into a GtkTreeModel
        self.tree = gtk.TreeStore(gobject.TYPE_BOOLEAN,
                                  gobject.TYPE_BOOLEAN,
                                  gobject.TYPE_STRING,
                                  gobject.TYPE_STRING,
                                  gobject.TYPE_STRING,
                                  gobject.TYPE_STRING,
                                  gobject.TYPE_PYOBJECT,
                                  gobject.TYPE_PYOBJECT)

        # Record each category as a toplevel in the tree
        categories = root.xpathEval2('/checklist/category')
        for category in categories:
            iter = self.tree.append(None)
            self.tree.set(iter,
                          ISITEM, False,
                          RESLIST, ['Needs-Reviewing', 'Pass', 'Fail'],
                          RESOLUTION, 'Needs-Reviewing',
                          OUTPUT, None,
                          OUTPUTLIST, {'Needs-Reviewing':None, 
                                       'Pass':None, 'Fail':None},
                          SUMMARY, category.prop('name'))

            # Entries are subheadings
            node = category.children
            while node:
                if node.name == 'description':
                    # Set DESCRIPTION of the heading
                    desc = string.join(string.split(node.content))
                    self.tree.set(iter, DESC, desc)
                elif node.name == 'entry':
                    entry = self.__xmlToEntry(node)
                    entryIter=self.tree.append(iter)
                    self.tree.set(entryIter,
                                  ISITEM, True,
                                  DISPLAY, entry.display,
                                  SUMMARY, entry.name,
                                  DESC, entry.desc)
                    # Construct the resolution from multiple states
                    resolutions={'Needs-Reviewing': None}
                    resolutionList=['Needs-Reviewing']
                    for i in range(len(entry.states)):
                        name = entry.states[i]['name']
                        resolutions[name] = entry.states[i]['output']
                        if name != 'Needs-Reviewing':
                            resolutionList.append(entry.states[i]['name'])
                        
                    self.tree.set(entryIter,
                                  RESLIST, resolutionList,
                                  OUTPUTLIST, resolutions,
                                  RESOLUTION, 'Needs-Reviewing',
                                  OUTPUT, resolutions['Needs-Reviewing'])
                else:
                    # DTD validation should make this ignorable.
                    pass
                  
                node = node.next

        checkFile.freeDoc()
Пример #16
0
    def load(self):
        ''' '''

        # Parse the xml into a DOM
        libxml2.registerErrorHandler(self.__no_display_parse_error, None)
        ctxt = libxml2.newParserCtxt()
        saveFile = ctxt.ctxtReadFile(self.filename, None, libxml2.XML_PARSE_DTDVALID)
        if ctxt.isValid() == False:
            ### FIXME create something less generic
            raise Exception('Save file does not validate against the qasave DTD.')

        root = saveFile.getRootElement()
        if root.name != 'qasave':
            ### FIXME create something less generic
            raise Exception('File is not a valid qa save file.')
        if root.prop('version') != _qaSaveFileVersion_:
            ### FIXME create something less generic
            raise Exception('Save file is of a different version than I understand.')
        # Load the appropriate base checklist.
        saveCheck = root.xpathEval2('/qasave/checklist')
        filename = saveCheck[0].content
        filename = os.path.join('data', filename)
        checkFile = gnomeglade.uninstalled_file(filename)
        if not checkFile:
            filename = os.path.join(self.app.program.get_property('app-id'),
                    filename)
            checkFile = self.app.locate_file(gnome.FILE_DOMAIN_APP_DATADIR,
                    filename)[0]
        if not checkFile:
            ### FIXME: Throw an exception to get out gracefully
            sys.exit(1)
        newList = checklist.CheckList(checkFile, self.properties)

        # Check that the checklist is the appropriate version
        if (newList.name != saveCheck[0].prop('name')):
            ### FIXME: Throw an exception to get out gracefully
            sys.exit(1)
        if (newList.revision != saveCheck[0].prop('revision')):
            ### FIXME: Think about this some more.
            # I think we just want to pop up a warning dialog and then
            # continue.
            # If the new checklist revision has more entries it will still
            # overlay fine.  But the user may need to look back over completed
            # sections for new entries.
            # If the new revision has less entries, old modified entries will
            # go into the Custom Entries area.
            pass
       
        del saveCheck
        
        saveProperties = root.xpathEval2('/qasave/properties/property')
        ### FIXME: I think the future
        # is to merge both properties and savefile into checklist so
        # this is going to disappear.
        for property in saveProperties:
            # Set properties through the interface.
            if property.prop('name') == "SRPM":
                self.properties.load_SRPM(property.content)
            else:
                try:
                    self.properties.set(property.prop('name'), property.content)
                except AttributeError, id:
                    if id == 1:
                        ### FIXME: need to do this:
                        # save property.prop(name) and .content into a hash.
                        # When we are done with the loop, check the hash.
                        # If there are values in it, popup a warning dialog
                        # that the save file had invalid entries that will be
                        # discarded.
                        pass