""" Reads some tags from a specfile """ # 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, string from log4py import Logger from tagsfile import TagsFile # 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 # this class calls the rpm command so it's quite slow, use with care! class SpecFileTags(TagsFile): # specfile: a path to a spec file like /a/b/c.spec # defineargs: a string which can be used on the commandline # like '--define "fc2 1"' def __init__(self, specfile, defineargs): TagsFile.__init__(self,defineargs, " --specfile ", specfile) def getOriginalBuildRequirements(self): commandpart = "" f = open(self.filename, 'r') line = f.readline() while line != '' and string.find(line,"%files") < 0: # todo: also include lines which contain '%define' if string.find(string.lower(line),'%define') >= 0: if string.find(string.lower(line),'#') != 0: l = line.strip() commandpart = commandpart + "\n" + l + "\n" else: if string.find(string.lower(line),'buildrequires') >= 0: if string.find(string.lower(line),'#') != 0: l = line.strip() commandpart = commandpart + ", " + l line = f.readline() f.close() self.cat.debug("commandpart=" + commandpart) commandline = "rpm " + self.defineargs + " -E \"" + commandpart + "\"" self.cat.debug("commandline=" + commandline) result = commands.getoutput(commandline) self.cat.debug("result1=" + result) reobj = re.compile('BuildRequires:',re.IGNORECASE) result = re.sub(reobj,"",result) reobj = re.compile('\n') result = re.sub(reobj,", ",result) self.cat.debug("result2=" + result) buildreqsarr = string.split(result,',') print "buildreqsarr=" + str(buildreqsarr) return buildreqsarr # returns an array of names of rpms to install, this is a cleaned up version of the original buildrequirements def getBuildRequires(self): finalbuildreqs = [] buildreqsarr = self.getOriginalBuildRequirements() for br in buildreqsarr: # remove leading spaces br = re.sub('^ *','',br) # remove everything from the first space br = re.sub(' .*','',br) if string.find(br, '/usr/bin/python') >= 0: br = "python" if string.find(br, '%{python}-devel') >= 0: br = "python-devel" # remove all buildreqs which contain a '/' or a '(' if string.find(br,'/') < 0 and string.find(br,'(') < 0 and br != "": finalbuildreqs.append(br) self.cat.debug("good buildreq: " + br) else: perlcheck = False mo = re.search(re.compile('perl\((.*)::(.*)::(.*)\)'), br) if perlcheck == False and mo != None: tempbr = "perl-" + mo.group(1) + "-" + mo.group(2) + "-" + mo.group(3) self.cat.debug("also good buildreq: " + tempbr) finalbuildreqs.append(tempbr) perlcheck = True mo = re.search(re.compile('perl\((.*)::(.*)\)'), br) if perlcheck == False and mo != None: tempbr = "perl-" + mo.group(1) + "-" + mo.group(2) self.cat.debug("also good buildreq: " + tempbr) finalbuildreqs.append(tempbr) perlcheck = True mo = re.search(re.compile('perl\((.*)\)'), br) if perlcheck == False and mo != None: tempbr = "perl-" + mo.group(1) self.cat.debug("also good buildreq: " + tempbr) finalbuildreqs.append(tempbr) perlcheck = True return finalbuildreqs def parseRpmForgeTags(self): f = open(self.filename, 'r') line = f.readline() regex = re.compile('^(# [a-zA-Z0-9]*) *: *(.*)$'); self.fullcontents = ''; while line != '': self.fullcontents = self.fullcontents + line l = line.strip() result = regex.match(l) if result: name = result.group(1) value = result.group(2) self.cat.debug("additional rpmforge tag, name=" + name + ", value=" + value) self.rpmforgetags[name] = value line = f.readline() f.close()