class ConfigXml(UserDict): # Implementation of the config.xml parser. xmldoc = None depsFactory = None dist = None nameRe = re.compile(r'^[a-z0-9][a-z0-9+-\.]+$') def __init__(self, configfile): UserDict.__init__(self) XmlTools().init(configfile) self.xmldoc = XmlTools().getXmlDoc() self.depsFactory = DependsFactory(self.xmldoc) #print self.xmldoc.findall("class") self.__validate__() def __validate__(self): XmlTools().validate() if not self.nameRe.match(self['name']): raise OpkgSyntaxException('Incorrect package name syntax (pattern: [a-z0-9][a-z0-9+-\.]+)') def __getitem__(self, key): if key == 'version': return self.xmldoc.find('changelog/versionEntry').get('version').strip() else: return self.xmldoc.findtext('/%s' % key).strip() def getAuthors(self, cat=None): al = [ Author(e) for e in self.xmldoc.findall("authors/author")] if cat: al = [ a for a in al if a['cat'] == cat ] return al def getDeps(self, relation, part, arch, dist): return self.depsFactory.getDeps(relation, part, arch, dist) def getChangelog(self): return [ ChangelogVEntry(e) for e in self.xmldoc.findall('/changelog/versionEntry') ] def getGlobalDistFilters(self): (dists, arch) = self.depsFactory.getFilters(self.xmldoc.find('/filters')) return dists def getNbArchFilters(self): (dists, arch) = self.depsFactory.getFilters(self.xmldoc.find('/filters')) l = self.xmldoc.findall('serverDeps/requires/filters/arch') return len(l) def getGlobalArchFilters(self): (dists, arch) = self.depsFactory.getFilters(self.xmldoc.find('/filters')) for a in arch: Logger().debug ("-> Arch " + a) for d in dists: Logger().debug ("-> Dist " + d['name']) l = self.xmldoc.findall('serverDeps/requires/filters/arch') Logger().info("Number of arch filters: %d" % len(l)) return arch
class ConfigXml(UserDict): xmldoc = None depsFactory = None dist = None nameRe = re.compile(r'^[a-z0-9][a-z0-9+-\.]+$') def __init__(self, configfile): UserDict.__init__(self) XmlTools().init(configfile) self.xmldoc = XmlTools().getXmlDoc() self.depsFactory = DependsFactory(self.xmldoc) self.__validate__() def __validate__(self): XmlTools().validate() if not self.nameRe.match(self['name']): raise OpkgSyntaxException( 'Incorrect package name syntax (pattern: [a-z0-9][a-z0-9+-\.]+)' ) def __getitem__(self, key): if key == 'version': return self.xmldoc.find('changelog/versionEntry').get( 'version').strip() else: return self.xmldoc.findtext('/%s' % key).strip() def getAuthors(self, cat=None): al = [Author(e) for e in self.xmldoc.findall("authors/author")] if cat: al = [a for a in al if a['cat'] == cat] return al def getDeps(self, relation, part, arch, dist): return self.depsFactory.getDeps(relation, part, arch, dist) def getChangelog(self): return [ ChangelogVEntry(e) for e in self.xmldoc.findall('/changelog/versionEntry') ] def getGlobalDistFilters(self): (dists, arch) = self.depsFactory.getFilters(self.xmldoc.find('/filters')) return dists def getGlobalArchFilters(self): (dists, arch) = self.depsFactory.getFilters(self.xmldoc.find('/filters')) return arch
def getPartNames(self): schema = XmlTools().getXsdDoc() return [ e.get("name") for e in filter(lambda x: x.get("type") == "depsListType", schema.findall('/{%s}element' % XmlTools.xsd_uri)) ]
def getRelationNames(self): schema = XmlTools().getXsdDoc() complexType = filter( lambda x: x.get("name") == "depsListType", schema.findall('{%s}complexType' % XmlTools.xsd_uri))[0] return [ e.get("ref") for e in complexType.find( '{%s}sequence' % XmlTools.xsd_uri).findall('{%s}element' % XmlTools.xsd_uri) ]
class ConfigSchema(object): schemaTree = None def __init__(self): self.schemaTree = XmlTools().getXsdDoc() def getArchs(self): """ Return list of authorized arch filters """ complexType = filter(lambda x: x.get("name") == "archType", self.schemaTree.findall("{%s}simpleType" % XmlTools.xsd_uri))[0] archs = [e.get("value") for e in complexType.find("{%s}restriction" % XmlTools.xsd_uri).findall("{%s}enumeration" % XmlTools.xsd_uri)] return archs