#!/usr/bin/python """ Script which gets some data from a group of rpms """ # 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 script gets the versionid, name and distroarchtag from an srpm # this only works if the versionid is added to the first line of the changelog import string, re, os def getNonCommentLines(filename): retval = [] fd = open(filename) entry = fd.readline() while entry != "": entry = entry[0:len(entry)-1] index = entry.find('#') if index >= 0: entry = entry[0:index] entry = entry.lstrip().rstrip() if entry != "": retval.append(entry) entry = fd.readline() fd.close() return retval # this gets the contents of the general file (for all distributions/architectures) and adds the file # of that specific distribution/architecture # all lines beginning with a # are ignored (comments) # first it tries to read the file in ~/.pydar2/rpmforgeacceptcommandconfig/ # if that does not exist, it tries to read the file in /etc/pydar2/rpmforgeacceptcommandconfig/ # the result is an array of strings: a string for each line def getConfigFileContents(name,distroarch): result = [] subdir = 'rpmforgeacceptcommandconfig' usergeneralfile = os.path.expanduser('~/.pydar2/' + subdir + '/' + name) etcgeneralfile = "/etc/pydar2/" + subdir + "/" + name userspecificfile = os.path.expanduser('~/.pydar2/' + subdir + '/' + distroarch + '/' + name) etcspecificfile = '/etc/pydar2/' + subdir + "/" + distroarch + "/" + name if os.path.exists(usergeneralfile): result.extend(getNonCommentLines(usergeneralfile)) else: result.extend(getNonCommentLines(etcgeneralfile)) if os.path.exists(userspecificfile): result.extend(getNonCommentLines(userspecificfile)) else: if os.path.exists(etcspecificfile): result.extend(getNonCommentLines(etcspecificfile)) return result def acceptCommand(aCommand): print "start of acceptCommand, spec:" + aCommand.getSpecFileFileName() if aCommand.getUserId() != "dries": return False if aCommand.getSpecRepositoryName() != "rpmforge": return False authority = aCommand.getAuthority() if authority == None: print "spec file without authority, ignoring" return False excludedAuthorities = getConfigFileContents('excludedauthoritytags',aCommand.getDistroArchTag()) print "authority: " + authority for auth in excludedAuthorities: print "auth in excludedAuthorities: " + auth if auth == authority: print "match on auth" return False ignoreList = getConfigFileContents('excluded',aCommand.getDistroArchTag()) for i in ignoreList: print "i in ignoreList: " + i if string.find(" " + aCommand.getSpecFileFileName(), i) > 0: print "match on ignoreList" return False temporarilyExcluded = getConfigFileContents('temporarilyexcluded',aCommand.getDistroArchTag()) print "version: " + str(aCommand.getVersion()) for line in temporarilyExcluded: # the file contains pairs of: : index = line.find(':') if index >= 0: patt = line[0:index] version = line[index+1:] print "temporarilyExcluded, patt: "+ str(patt) + ",version:" + str(version) + ",commversion:" + str(aCommand.getVersion()) + ",m1:" + str(string.find(" " + aCommand.getSpecFileFileName(), patt)) + ",m2:" + str(version == aCommand.getVersion()) if string.find(" " + aCommand.getSpecFileFileName(), patt) >= 0: print "string find match" if version == aCommand.getVersion(): print "also version match" return False if str(version) == str(aCommand.getVersion()): print "string version match" return False if string.find(" " + aCommand.getSpecFileFileName(), patt) > 0 and version == aCommand.getVersion(): print "temporarily excluded match" return False # also check the architecture arch = aCommand.getArch() print "arch is: " + str(arch) # get the file so we can search for 'ExclusiveArch' stuff fullpath = aCommand.getSpecRepositorySpecFile().getFullPath() contents = __getContents(fullpath) mo = re.search(re.compile('^ExclusiveArch:(.*)\n',re.MULTILINE), contents) if mo != None: # an ExclusiveArch is found exclusiveArchs = mo.group(1) if string.find(" " + exclusiveArchs, arch) > 0: # ok print "arch " + str(arch) + " is included in the exclusivearchs " + str(exclusiveArchs) else: # not ok print "arch" + str(arch) + " is not included in the list of exclusiveArchs " + str(exclusiveArchs) return False mo = re.search(re.compile('^# Tag: test', re.MULTILINE), contents) if mo != None: return False return True def __getContents(path): fd = open(path, "r") contents = "" line = fd.readline() while line != "": contents = contents + line line = fd.readline() fd.close() return contents