Logo Search packages:      
Sourcecode: qa-assistant version File versions  Download package

def checklist::CheckList::__Test::__init__ (   self,
  path 
)

Create a new CheckList

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

Creates a new CheckList.

Definition at line 124 of file checklist.py.

00124                             :
        ''' 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.fileLoadDir = os.path.dirname(path) # Directory we loaded the 
                                                 # checklist from
        self.resolution = 'Needs-Reviewing' # Resolution of the checklist
        self.functionHash = None # Hash of the functions file
        self.functionHashType = None # Type of the hash (sha1, md5, etc)
        self.functionFile = None # File containing the functions
        # 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
                        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
        funcs = root.xpathEval2('/checklist/functions')
        if funcs:
            self.functionHash = funcs[0].prop('hash')
            self.functionHashType = funcs[0].prop('hashtype')
            self.functionFile = funcs[0].content
            self.functions = self._load_functions()
        else:
            self.functions = functions.BaseQAFunctions(self)
        del funcs
        
        # 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 = ' '.join(node.content.split())
                    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
        self.properties.connect('changed', self._prop_change)

    def _prop_change(self, *extras):


Generated by  Doxygen 1.6.0   Back to index