#!/usr/bin/python -t # -*- mode: Python; indent-tabs-mode: nil; -*- # # 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 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 import errno, os, sys import fnmatch, re import rpmUtils.transaction, rpmUtils.miscutils import Utils, WhatsNew try: from plague.LockFile import LockFile, LockFileLocked except: from LockFile import LockFile, LockFileLocked from BuildReport import * ts = rpmUtils.transaction.initReadOnlyTransaction() def getPackageSets(srcdir,binrepolist): # Map: source rpm %name -> map: repo arch -> list of rpms pkgsets = {} # Create list of src.rpm files in SRPMS directory. # We don't use "glob", so sub-directories are supported. print 'Examining', srcdir srcfiles = [] for root, dirs, files in os.walk(srcdir): for f in fnmatch.filter(files,'*.src.rpm'): srcfiles.append(os.path.join(root,f)) for f in fnmatch.filter(files,'*.nosrc.rpm'): srcfiles.append(os.path.join(root,f)) if not len(srcfiles): print ' Nothing found.' return pkgsets else: print ' %d source rpm(s).' % len(srcfiles) # Examine binary repository directories. for (arch,bindir) in binrepolist: print 'Examining', bindir for root, dirs, files in os.walk(bindir): for f in fnmatch.filter(files,'*.rpm'): fullname = os.path.join(root,f) hdr = rpmUtils.miscutils.hdrFromPackage(ts,fullname) sourcerpm = hdr['sourcerpm'] if not sourcerpm.endswith('.rpm'): print 'WARNING: unusual SRPM name for %s (%s), skipping' % (f, sourcerpm) continue # Build up the package set map. srcfullname = os.path.join(srcdir,sourcerpm) if srcfullname in srcfiles: pkgsets.setdefault(sourcerpm,{}) # add binary rpm to arch list pkgsets[sourcerpm].setdefault(arch,[]) pkgsets[sourcerpm][arch].append(fullname) # add source rpm to SRPMS list pkgsets[sourcerpm].setdefault('SRPMS',[srcfullname]) return pkgsets def isWantedName(name,regexplist): for r in regexplist: if re.compile('^'+r+'$').search(name): return True return False # reject by default def main(cfg,dist,regexplist): # Don't treat double-"+" as regexp meta-characters. for i in range(len(regexplist)): while regexplist[i].find('++')>=0: regexplist[i] = regexplist[i].replace('++','\+\+') srcdist = 'testing/%s' % dist destdist = dist if srcdist not in cfg.alldists: print "No distribution release named '%s' found" % srcdist return srcdir = Utils.srpm_repodir(cfg,srcdist) binrepos = [] for arch in cfg.archdict[srcdist]: # list of repo archs binrepos.append( (arch,Utils.rpm_repodir(cfg,srcdist,arch)) ) pkgsets = getPackageSets(srcdir,binrepos) buildreport = BuildReportManager(cfg.rundir,dist) WhatsNew.load(cfg.rundir) for srcrpm in pkgsets.keys(): (n,v,r,e,a) = rpmUtils.miscutils.splitFilename(srcrpm) name = n if isWantedName(name,regexplist): # the src.rpm %names we want print ' ', name # Fill build report and changelog diff db. fullsrcfname = pkgsets[srcrpm]['SRPMS'][0] summary = Utils.get_pkg_header(fullsrcfname)['summary'].rstrip() buildid = '%s-%s-%s' % (n,v,r) if WhatsNew.queryname(dist,n): buildreportinfo = BuildInfo(buildid) else: buildreportinfo = BuildInfo(buildid, summary, True) buildreport.Add(buildreportinfo) clogdiff = WhatsNew.getclogdiff(dist,name,fullsrcfname,ts) newclog = WhatsNew.readclog(fullsrcfname,ts) WhatsNew.putname(dist,name) WhatsNew.putclog(dist,name,newclog) WhatsNew.putclogdiff(dist,buildid,clogdiff) # Move the rpms. for (repoarch,rpms) in pkgsets[srcrpm].iteritems(): for f in rpms: basename = os.path.basename(f) if basename.find('-debuginfo-')>0: destpath = os.path.join( Utils.debug_repodir(cfg,destdist,repoarch), basename ) else: destpath = os.path.join( Utils.rpm_repodir(cfg,destdist,repoarch), basename ) print ' ',basename,'->',repoarch Utils.install_move(f,destpath) WhatsNew.save(cfg.rundir) if __name__ == '__main__': if len(sys.argv) < 3: print 'Usage: %s [pkgname]...\n' % os.path.basename(sys.argv[0]) sys.exit(errno.EINVAL) cfg = Utils.load_config_module(sys.argv[1]) Utils.signer_gid_check(cfg.signersgid) os.umask(cfg.signersumask) if not os.path.exists(cfg.rundir): os.makedirs(cfg.rundir) lockfile = os.path.join(cfg.rundir,'pushscript.lock') lock = LockFile(lockfile) try: lock.lock() except LockFileLocked: print 'Script locked via %s\nIt seems to be in use already.' % lockfile sys.exit(errno.EPERM) main(cfg,sys.argv[2],sys.argv[3:]) sys.exit(0)