""" Some common stuff for spec and rpm files """ # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Library General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Copyright 2004 Dries Verachtert # This class can be used for reading the values of certain tags from spec files import re, os, commands from log4py import Logger # a rpmforge tag is a tag which begins with '# ' # currently the standard tags are written in uppercase # result can be found in the hashes rpmforgetags and standardtags class TagsFile: def __init__(self,defineargs,addToCommandLine, filename): self.cat = Logger().get_instance(self) self.cat.debug("start") self.filename = filename self.addToCommandLine = addToCommandLine self.defineargs = defineargs self.cat.debug("defineargs: " + defineargs) self.__formatStringBeginTag = "::QFBEGINTAG::" self.__formatStringEndTag = "::QFENDTAG::" self.subpackageStandardTags = {} self.rpmforgetags = {} self.standardtags = {} self.queryformattags = ("PKGID","NAME","VERSION","RELEASE","EPOCH","SERIAL","SUMMARY","DESCRIPTION","DISTRIBUTION","VENDOR","LICENSE","PACKAGER","GROUP","URL","ARCH","EXCLUDEARCH","EXCLUDEOS","EXCLUSIVEARCH","EXCLUSIVEOS","BUILDARCHS","DISTURL","FILEMD5S","CHANGELOGNAME") self.getStandardTags() self.parseRpmForgeTags() def getStandardTags(self): self.cat.debug("start") queryformat = self.getQueryFormatString() #self.cat.debug("queryformat=" + str(queryformat)) commandline = "rpm -q " + self.defineargs + " --queryformat '" + queryformat + "' " + self.addToCommandLine + self.filename self.cat.debug("commandline=" + commandline) result = commands.getoutput(commandline) #self.cat.debug("result: " + result) self.parseStandardTags(result) def getQueryFormatString(self): self.cat.debug("start") result = '' for tag in self.queryformattags: result = result + "#####" + tag + "#####%{" + tag + "}#####" + tag + "#####" return self.__formatStringBeginTag + result + self.__formatStringEndTag def parseStandardTags(self, inputstring): self.cat.debug("start, inputstring=" + inputstring) regexp = '.*?' + self.__formatStringBeginTag + '(.*?)' + self.__formatStringEndTag + '(.*)' regex = re.compile(regexp, re.MULTILINE | re.DOTALL) result = regex.match(inputstring) if result: # this is the info about the package itself mainPack = result.group(1) self.standardtags = self.__getStandardTagsPerPackage(mainPack) subPackages = result.group(2) found = 1 while found == 1: result = regex.match(subPackages) if result: subtags = self.__getStandardTagsPerPackage(result.group(1)) self.subpackageStandardTags[subtags['NAME']] = subtags subPackages = result.group(2) else: found = 0 def __getStandardTagsPerPackage(self, inputstring): retval = {} for tag in self.queryformattags: #self.cat.debug("tag: " + tag) regexp = '.*?#####'+tag+'#####(.*?)#####'+tag+'#####.*' regex = re.compile(regexp,re.MULTILINE | re.DOTALL) #self.cat.debug("regexp: "+ regexp) #self.cat.debug("inputstring:"+inputstring) result = regex.match(inputstring) if result: value=result.group(1) #self.cat.debug("value: "+value) retval[tag] = value else: self.cat.warn("tag not found, tag:"+tag) return retval def parseRpmForgeTags(self): self.cat.debug("start, will do nothing..")