def check(self, **kwargs): '''Performs the checks on the metadata.xml for the package @param xpkg: the pacakge being checked @param checkdir: string, directory path @param checkdirlist: list of checkdir's @param repolevel: integer @returns: boolean ''' xpkg = kwargs.get('xpkg') checkdir = kwargs.get('checkdir') checkdirlist = kwargs.get('checkdirlist').get() self.musedict = {} if self.options.mode in ['manifest']: self.muselist = frozenset(self.musedict) return False # metadata.xml file check if "metadata.xml" not in checkdirlist: self.qatracker.add_error("metadata.missing", xpkg + "/metadata.xml") self.muselist = frozenset(self.musedict) return False # metadata.xml parse check metadata_bad = False # read metadata.xml into memory try: _metadata_xml = etree.parse(os.path.join(checkdir, 'metadata.xml')) except (ParserError, SyntaxError, EnvironmentError) as e: metadata_bad = True self.qatracker.add_error("metadata.bad", "%s/metadata.xml: %s" % (xpkg, e)) del e self.muselist = frozenset(self.musedict) return False indentation_chars = Counter() for l in etree.tostring(_metadata_xml).splitlines(): indentation_chars.update(re.match(b"\s*", l).group(0)) if len(indentation_chars) > 1: self.qatracker.add_error( "metadata.warning", "%s/metadata.xml: %s" % (xpkg, "inconsistent use of tabs and spaces in indentation")) xml_encoding = _metadata_xml.docinfo.encoding if xml_encoding.upper() != metadata_xml_encoding: self.qatracker.add_error( "metadata.bad", "%s/metadata.xml: " "xml declaration encoding should be '%s', not '%s'" % (xpkg, metadata_xml_encoding, xml_encoding)) if not _metadata_xml.docinfo.doctype: metadata_bad = True self.qatracker.add_error( "metadata.bad", "%s/metadata.xml: %s" % (xpkg, "DOCTYPE is missing")) else: doctype_system = _metadata_xml.docinfo.system_url if doctype_system != metadata_dtd_uri: if doctype_system is None: system_problem = "but it is undefined" else: system_problem = "not '%s'" % doctype_system self.qatracker.add_error( "metadata.bad", "%s/metadata.xml: " "DOCTYPE: SYSTEM should refer to '%s', %s" % (xpkg, metadata_dtd_uri, system_problem)) doctype_name = _metadata_xml.docinfo.doctype.split(' ')[1] if doctype_name != metadata_doctype_name: self.qatracker.add_error( "metadata.bad", "%s/metadata.xml: " "DOCTYPE: name should be '%s', not '%s'" % (xpkg, metadata_doctype_name, doctype_name)) # load USE flags from metadata.xml self.musedict = parse_metadata_use(_metadata_xml) for atom in chain(*self.musedict.values()): if atom is None: continue try: atom = Atom(atom) except InvalidAtom as e: self.qatracker.add_error( "metadata.bad", "%s/metadata.xml: Invalid atom: %s" % (xpkg, e)) else: if atom.cp != xpkg: self.qatracker.add_error( "metadata.bad", "%s/metadata.xml: Atom contains " "unexpected cat/pn: %s" % (xpkg, atom)) # Only carry out if in package directory or check forced if not metadata_bad: validator = etree.XMLSchema(file=self.metadata_xsd) if not validator.validate(_metadata_xml): self._add_validate_errors(xpkg, validator.error_log) self.muselist = frozenset(self.musedict) return False
def check(self, **kwargs): '''Performs the checks on the metadata.xml for the package @param xpkg: the pacakge being checked @param checkdir: string, directory path @param checkdirlist: list of checkdir's @param repolevel: integer @returns: boolean ''' xpkg = kwargs.get('xpkg') checkdir = kwargs.get('checkdir') checkdirlist = kwargs.get('checkdirlist').get() self.musedict = {} if self.options.mode in ['manifest']: self.muselist = frozenset(self.musedict) return False # metadata.xml file check if "metadata.xml" not in checkdirlist: self.qatracker.add_error("metadata.missing", xpkg + "/metadata.xml") self.muselist = frozenset(self.musedict) return False # metadata.xml parse check metadata_bad = False # read metadata.xml into memory try: _metadata_xml = etree.parse(os.path.join(checkdir, 'metadata.xml')) except (ParserError, SyntaxError, EnvironmentError) as e: metadata_bad = True self.qatracker.add_error("metadata.bad", "%s/metadata.xml: %s" % (xpkg, e)) del e self.muselist = frozenset(self.musedict) return False xml_encoding = _metadata_xml.docinfo.encoding if xml_encoding.upper() != metadata_xml_encoding: self.qatracker.add_error( "metadata.bad", "%s/metadata.xml: " "xml declaration encoding should be '%s', not '%s'" % (xpkg, metadata_xml_encoding, xml_encoding)) if not _metadata_xml.docinfo.doctype: metadata_bad = True self.qatracker.add_error( "metadata.bad", "%s/metadata.xml: %s" % (xpkg, "DOCTYPE is missing")) else: doctype_system = _metadata_xml.docinfo.system_url if doctype_system != metadata_dtd_uri: if doctype_system is None: system_problem = "but it is undefined" else: system_problem = "not '%s'" % doctype_system self.qatracker.add_error( "metadata.bad", "%s/metadata.xml: " "DOCTYPE: SYSTEM should refer to '%s', %s" % (xpkg, metadata_dtd_uri, system_problem)) doctype_name = _metadata_xml.docinfo.doctype.split(' ')[1] if doctype_name != metadata_doctype_name: self.qatracker.add_error( "metadata.bad", "%s/metadata.xml: " "DOCTYPE: name should be '%s', not '%s'" % (xpkg, metadata_doctype_name, doctype_name)) # load USE flags from metadata.xml self.musedict = parse_metadata_use(_metadata_xml) for atom in chain(*self.musedict.values()): if atom is None: continue try: atom = Atom(atom) except InvalidAtom as e: self.qatracker.add_error( "metadata.bad", "%s/metadata.xml: Invalid atom: %s" % (xpkg, e)) else: if atom.cp != xpkg: self.qatracker.add_error( "metadata.bad", "%s/metadata.xml: Atom contains " "unexpected cat/pn: %s" % (xpkg, atom)) # Only carry out if in package directory or check forced if not metadata_bad: validator = etree.XMLSchema(file=self.metadata_xsd) if not validator.validate(_metadata_xml): self._add_validate_errors(xpkg, validator.error_log) self.muselist = frozenset(self.musedict) return False