Esempio n. 1
0
 def parseNode(self, node):
     for child in node.childNodes:
         if child.nodeType == ELEMENT_NODE:
             if child.tagName == "Old":
                 try:
                     self.parseOld(child.childNodes[0].nodeValue)
                 except IndexError:
                     raise ValidationError('Old cannot be empty', '??')                                            
             elif child.tagName == "New":
                 try:
                     self.parseNew(child.childNodes[0].nodeValue)
                 except IndexError:
                     raise ValidationError('New cannot be empty', '??')                                            
Esempio n. 2
0
 def parseNode(self, node):
     for child in node.childNodes:
         if child.nodeType == ELEMENT_NODE:
             if child.tagName == 'Filename':
                 try:
                     self.parseFilename(child.childNodes[0].nodeValue)
                 except IndexError:
                     raise ValidationError('Filename cannot be empty', "???")
             elif child.tagName == 'Category':
                 try:
                     self.parseCategory(child.childNodes[0].nodeValue)
                 except IndexError:
                     raise ValidationError('Category cannot be empty', "???")
             elif child.tagName == 'All':
                 self.parseAll()
             elif child.tagName == 'And':
                 self.parseAnd(child)
             elif child.tagName == 'Or':
                 self.parseOr(child)
             elif child.tagName == 'Not':
                 self.parseNot(child)
Esempio n. 3
0
 def parseNode(self, node):
     for child in node.childNodes:
         if child.nodeType == ELEMENT_NODE:
             if child.tagName == "Menuname":
                 try:
                     self.parseMenuname(
                         child.childNodes[0].nodeValue,
                         child.getAttribute("show_empty") or "false",
                         child.getAttribute("inline") or "false",
                         child.getAttribute("inline_limit") or 4,
                         child.getAttribute("inline_header") or "true",
                         child.getAttribute("inline_alias") or "false" )
                 except IndexError:
                     raise ValidationError('Menuname cannot be empty', "")
             elif child.tagName == "Separator":
                 self.parseSeparator()
             elif child.tagName == "Filename":
                 try:
                     self.parseFilename(child.childNodes[0].nodeValue)
                 except IndexError:
                     raise ValidationError('Filename cannot be empty', "")
             elif child.tagName == "Merge":
                 self.parseMerge(child.getAttribute("type") or "all")
Esempio n. 4
0
    def validate(self, report="All"):
        """Validate the contents, raising :class:`~xdg.Exceptions.ValidationError`
        if there is anything amiss.
        
        report can be 'All' / 'Warnings' / 'Errors'
        """

        self.warnings = []
        self.errors = []

        # get file extension
        self.fileExtension = os.path.splitext(self.filename)[1]

        # overwrite this for own checkings
        self.checkExtras()

        # check all keys
        for group in self.content:
            self.checkGroup(group)
            for key in self.content[group]:
                self.checkKey(key, self.content[group][key], group)
                # check if value is empty
                if self.content[group][key] == "":
                    self.warnings.append("Value of Key '%s' is empty" % key)

        # raise Warnings / Errors
        msg = ""

        if report == "All" or report == "Warnings":
            for line in self.warnings:
                msg += "\n- " + line

        if report == "All" or report == "Errors":
            for line in self.errors:
                msg += "\n- " + line

        if msg:
            raise ValidationError(msg, self.filename)
Esempio n. 5
0
def __parse(node, filename, parent=None):
    for child in node.childNodes:
        if child.nodeType == ELEMENT_NODE:
            if child.tagName == 'Menu':
                __parseMenu(child, filename, parent)
            elif child.tagName == 'AppDir':
                try:
                    __parseAppDir(child.childNodes[0].nodeValue, filename, parent)
                except IndexError:
                    raise ValidationError('AppDir cannot be empty', filename)
            elif child.tagName == 'DefaultAppDirs':
                __parseDefaultAppDir(filename, parent)
            elif child.tagName == 'DirectoryDir':
                try:
                    __parseDirectoryDir(child.childNodes[0].nodeValue, filename, parent)
                except IndexError:
                    raise ValidationError('DirectoryDir cannot be empty', filename)
            elif child.tagName == 'DefaultDirectoryDirs':
                __parseDefaultDirectoryDir(filename, parent)
            elif child.tagName == 'Name' :
                try:
                    parent.Name = child.childNodes[0].nodeValue
                except IndexError:
                    raise ValidationError('Name cannot be empty', filename)
            elif child.tagName == 'Directory' :
                try:
                    parent.Directories.append(child.childNodes[0].nodeValue)
                except IndexError:
                    raise ValidationError('Directory cannot be empty', filename)
            elif child.tagName == 'OnlyUnallocated':
                parent.OnlyUnallocated = True
            elif child.tagName == 'NotOnlyUnallocated':
                parent.OnlyUnallocated = False
            elif child.tagName == 'Deleted':
                parent.Deleted = True
            elif child.tagName == 'NotDeleted':
                parent.Deleted = False
            elif child.tagName == 'Include' or child.tagName == 'Exclude':
                parent.Rules.append(Rule(child.tagName, child))
            elif child.tagName == 'MergeFile':
                try:
                    if child.getAttribute("type") == "parent":
                        __parseMergeFile("applications.menu", child, filename, parent)
                    else:
                        __parseMergeFile(child.childNodes[0].nodeValue, child, filename, parent)
                except IndexError:
                    raise ValidationError('MergeFile cannot be empty', filename)
            elif child.tagName == 'MergeDir':
                try:
                    __parseMergeDir(child.childNodes[0].nodeValue, child, filename, parent)
                except IndexError:
                    raise ValidationError('MergeDir cannot be empty', filename)
            elif child.tagName == 'DefaultMergeDirs':
                __parseDefaultMergeDirs(child, filename, parent)
            elif child.tagName == 'Move':
                parent.Moves.append(Move(child))
            elif child.tagName == 'Layout':
                if len(child.childNodes) > 1:
                    parent.Layout = Layout(child)
            elif child.tagName == 'DefaultLayout':
                if len(child.childNodes) > 1:
                    parent.DefaultLayout = Layout(child)
            elif child.tagName == 'LegacyDir':
                try:
                    __parseLegacyDir(child.childNodes[0].nodeValue, child.getAttribute("prefix"), filename, parent)
                except IndexError:
                    raise ValidationError('LegacyDir cannot be empty', filename)
            elif child.tagName == 'KDELegacyDirs':
                __parseKDELegacyDirs(filename, parent)