extras-buildsys/utils/pushscript ToStable.py,NONE,1.1

Michael Schwendt (mschwendt) fedora-extras-commits at redhat.com
Thu Aug 23 12:12:44 UTC 2007


Author: mschwendt

Update of /cvs/fedora/extras-buildsys/utils/pushscript
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv8238

Added Files:
	ToStable.py 
Log Message:
- add script that can move full sets of packages (based on src.rpm
%name) from a testing repo to stable repo



--- NEW FILE ToStable.py ---
#!/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
from BuildReport import *

DEBUG = False
Utils.setdebug(DEBUG)

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 main(cfg,dist,args):
    srcdist = 'testing/%s' % dist
    destdist = dist

    srcdir = os.path.join(cfg.treedir,srcdist,'SRPMS')
    binrepos = []
    for arch in cfg.archdict[srcdist]:  # list of repo archs
        binrepos.append( (arch,os.path.join(cfg.treedir,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 name in args:  # 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)
                    destpath = os.path.join(cfg.treedir,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 <project> <release> <pkgname> [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)
    
    main(cfg,sys.argv[2],sys.argv[3:])
    sys.exit(0)




More information about the fedora-extras-commits mailing list