#!/usr/bin/python """ Small example userdefined script for a target: modify release tag and add packager and vendor tag """ # 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 # the rpmforge subversion contains the patches and sometimes some sources import os, re, string def RpmforgeAlterSpecFile(command, commanddir, brr): print "RpmforgeAlterSpecFile start" # get the directory of the svn checkout fullpath = command.getSpecRepositorySpecFile().getFullPath() (dir,fname) = os.path.split(fullpath) print "dir: " + dir fullSpecPath = os.path.join(commanddir, fname) # first read the contents of the spec file # then modify the contents in memory # then write it back print "get the contents" contents = __getContents(fullSpecPath) print "modify the contents" contents = __modifyContents(contents,command) print "write the contents" __writeContents(fullSpecPath,contents) print "done" return None def __distroArchTagToReleaseExt(tag): if tag == "fc3-i386": return "1.fc3.rf" if tag == "fc2-i386": return "1.fc2.rf" if tag == "fc1-i386": return "1.fc1.rf" if tag == "el4-i386" or tag == "rhel4-i386": return "2.el4.rf" if tag == "el3-i386" or tag == "rhel3-i386": return "1.el3.rf" if tag == "fc4-i386": return "2.fc4.rf"; if tag == "fc4-x86_64": return "2.fc4.rf" if tag == "au1.92-sparc": return "0.au1.92.rf" if tag == "oss10.0beta4-i586": return "0.0.oss10.0beta4.rf" if tag == "fc5-i386": return "0.fc5.rf" if tag == "fc5-x86_64": return "0.fc5.rf" if tag == "oss10.0-i586": return "0.oss10.0.rf" if tag == "oss10.0-x86_64": return "0.oss10.0.rf" return None def __modifyContents(contents,command): ext = __distroArchTagToReleaseExt(command.getDistroArchTag()) contents = re.sub(re.compile('^%changelog\n(.*)\n',re.MULTILINE), r'%changelog\n\1 #' + str(command.getVersion()) + r'\n',contents) contents = re.sub(re.compile('^Release: (.*?)\n',re.MULTILINE), r'Release: \1.' + ext + r'\n',contents) contents = re.sub(re.compile('>= %\(rpm -q --qf(.*?)\n',re.MULTILINE), r'\n', contents) mo = re.search(re.compile('^# Authority:(.*)\n',re.MULTILINE), contents) packager = '' if mo!= None: authority = mo.group(1) found = False if string.find(authority,'dag') >= 0: packager = 'Dag Wieers ' found = True if string.find(authority,'bert') >= 0: packager = 'Bert de Bruijn ' found = True if string.find(authority,'koenraad') >= 0: packager = 'Koenraad Heijlen ' found = True if string.find(authority,'leet') >= 0: packager = 'C.Lee Taylor ' found = True if not found: packager = 'Dries Verachtert ' else: packager = 'Dries Verachtert ' vendor = 'Dries RPM Repository http://dries.ulyssis.org/rpm/' contents = re.sub(re.compile('^(Source0?:.*)\n',re.MULTILINE), r'\1\nPackager: ' + packager + r'\nVendor: ' + vendor + r'\n',contents) return contents def __getContents(path): fd = open(path, "r") contents = "" line = fd.readline() while line != "": contents = contents + line line = fd.readline() fd.close() return contents def __writeContents(path,contents): fd = open(path,"w") fd.write(contents) fd.close()