import re from StringUtils import StringUtils from SpecStructures import * class SpecParser(object): def __init__(self): self.cleanMacro=rpmMacro().setName("clean") self.prepMacro=rpmMacro().setName("prep") self.buildMacro=rpmMacro().setName("build") self.installMacro=rpmMacro().setName("install") self.changelogMacro=rpmMacro().setName("changelog") self.checkMacro=rpmMacro().setName("check") self.packages={} self.specAdditionalContent="" self.globalSecurityHardening="" self.defs={} def readPkgNameFromPackageMacro(self,data,basePkgName=None): data=" ".join(data.split()) pkgHeaderName=data.split(" ") lenpkgHeaderName = len(pkgHeaderName) i=1; pkgName = None while i=": compare="gte" elif listContents[i+1] == "<=": compare="lte" elif listContents[i+1] == "==": compare="eq" elif listContents[i+1] == "<": compare="lt" elif listContents[i+1] == ">": compare="gt" elif listContents[i+1] == "=": compare="eq" if compare is not None: dpkg.package=listContents[i] dpkg.compare=compare dpkg.version=listContents[i+2] i=i+3 else: dpkg.package=listContents[i] i=i+1 listdependentpkgs.append(dpkg) return listdependentpkgs def readPackageHeaders(self,line,pkg): returnVal,headerName,headerContent=self.readHeader(line) if not returnVal: return False headerContent=pkg.decodeContents(headerContent) if headerName == 'summary': pkg.summary=headerContent return True if headerName == 'name': pkg.name=headerContent return True if headerName == 'group': pkg.group=headerContent return True if headerName == 'license': pkg.license=headerContent return True if headerName == 'version': pkg.version=headerContent return True if headerName == 'buildarch': pkg.buildarch=headerContent return True if headerName == 'release': pkg.release=headerContent return True if headerName == 'distribution': pkg.distribution=headerContent return True if headerName == 'url': pkg.URL=headerContent return True if headerName.find('source') != -1: pkg.sources.append(headerContent) return True if headerName.find('patch') != -1: pkg.patches.append(headerContent) return True if headerName == 'requires' or headerName == 'provides' or headerName == 'obsoletes' or headerName == 'conflicts' or headerName == 'buildrequires' or headerName == 'buildprovides': dpkg=self.readDependentPackageData(headerContent) if dpkg is None: return False if headerName == 'requires': pkg.requires.extend(dpkg) if headerName == 'provides': pkg.provides.extend(dpkg) if headerName == 'obsoletes': pkg.obsoletes.extend(dpkg) if headerName == 'conflicts': pkg.conflicts.extend(dpkg) if headerName == 'buildrequires': pkg.buildrequires.extend(dpkg) if headerName == 'buildprovides': pkg.buildprovides.extend(dpkg) return True return False def readSecurityHardening(self,line): data = line.lower().strip(); words=data.split(" ") nrWords = len(words) if (nrWords != 3): print "Error: Unable to parse line: "+line return False if (words[2] != "none" and words[2] != "nonow") : print "Error: Invalid security_hardening value: " + words[2] return False self.globalSecurityHardening = words[2] return True; def readChecksum(self,line,pkg): strUtils = StringUtils() line=pkg.decodeContents(line) data = line.strip(); words=data.split() nrWords = len(words) if (nrWords != 3): print "Error: Unable to parse line: "+line return False value=words[2].split("=") if (len(value) != 2): print "Error: Unable to parse line: "+line return False matchedSources=[] for source in pkg.sources: sourceName=strUtils.getFileNameFromURL(source) if (sourceName.startswith(value[0])): matchedSources.append(sourceName) if (len(matchedSources) == 0): print "Error: Can not find match for sha1 "+value[0] return False if (len(matchedSources) > 1): print "Error: Too many matches in sources: "+matchedSources+" for sha1 "+value[0] return False pkg.checksums[sourceName] = value[1] return True;