extras-buildsys/utils extras-push.py,NONE,1.1

Seth Vidal (skvidal) fedora-extras-commits at redhat.com
Wed Jun 1 04:17:09 UTC 2005


Author: skvidal

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

Added Files:
	extras-push.py 
Log Message:

add extras-push.py to extras-buildsys dir



--- NEW FILE extras-push.py ---
#!/usr/bin/python -t
# 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.

import os
import sys
import rpmUtils
import smtplib
import shutil
import string
from email.MIMEText import MIMEText


# get the path to where to look for the packages to be signed
# get the list of stuff there (logs, md5sums, specs, rpms)
# list the rpms and pause
# sign the rpms
# collect list of srpms and get package n-v-r from them
# move pkgs into repo
# repomanage? 
# make repo
# make repoview
# email to fedora-extras-list with the built packages list
# sing, dance, romance

stagesdir = '/rpmbuild/extras/stages'
treedir = '/rpmbuild/extras/tree/extras'
compsname = 'comps.xml'
archdict = {'3':['x86_64', 'i386'], 
            'development':['ppc','x86_64','i386'],
            '4':['ppc','x86_64', 'i386']}
ts = rpmUtils.transaction.initReadOnlyTransaction()


DEBUG = False

def debugprint(msg):
    if DEBUG:
        print msg
        
def find_files(path):
    """returns a dict of filetypes and paths to those files"""
    filedict = {}
    filedict['srpm'] = []
    filedict['log'] = []
    filedict['rpm'] = []
    filedict['spec'] = []
    filedict['md5sum'] = []
    filedict['debuginfo'] = []
    filedict['other'] = []
    for root, dirs, files in os.walk(path):
        for file in files:
            # match the files to what list they should be in
            if file.endswith('.log'):
                which = 'log'
            elif file.endswith('.rpm'):
                if file.find('debuginfo') != -1:
                    which = 'debuginfo' 
                elif file.endswith('.src.rpm'):
                    which = 'srpm'
                else:
                    which = 'rpm'
            elif file.endswith('.spec'):
                which = 'spec'
            elif file.endswith('.md5sum'):
                which = 'md5sum'
            else:
                which = 'other'

            fullfile = os.path.join(root, file)
            filedict[which].append(fullfile)
    return filedict

def naevr(pkg):
    """return nevra from the package srpm"""

    hdr = rpmUtils.miscutils.hdrFromPackage(ts, pkg)
    name = hdr['name']
    ver = hdr['version']
    rel = hdr['release']
    arch = hdr['arch']
    epoch = hdr['epoch']
    if epoch is None:
        epoch = 0
    
    return (name, arch, epoch, ver, rel)


def email_list(pkglist, dist):
    """email extras list with the new package listing"""
    mail_from = 'buildsys at fedoraproject.org'
    mail_to = 'fedora-extras-list at redhat.com'

    uniqued = rpmUtils.miscutils.unique(pkglist)
    uniqued.sort()
    
    output = "\nPackages built and released for Fedora Extras %s: %s \n\n" % (dist, len(uniqued))
    for pkg in uniqued:
        add = '%s\n' % (pkg)
        output = output + add
    
    end = """

For more information about the built packages please see the repository
or the fedora Info Feed: http://fedoraproject.org/infofeed/

"""
    output = output + end
    msg = MIMEText(output)
    subject = 'Fedora Extras %s Package Build Report' % dist
    msg['Subject'] = subject
    msg['From'] = mail_from
    msg['To'] = mail_to
    s = smtplib.SMTP()
    s.connect()
    s.sendmail(mail_from, [mail_to], msg.as_string())
    s.close()
        
def sign_pkgs(filelist):
    """gpg sign all the rpms"""
    numfiles = len(filelist)
    if numfiles < 1:
        print "No packages to sign"
        return False

    while numfiles > 0:
        if numfiles > 256:
            files = filelist[:256]
            del filelist[:256]
        else:
            files = filelist
            filelist = []
    
        foo = string.join(files)
        result = os.system('echo %s | xargs rpm --resign' % foo)
        if result != 0:
            return False
        numfiles = len(filelist)

    return True
    
def main(dist):
    if not archdict.has_key(dist):
        print "No Distribution named %s found" % dist
        sys.exit(1)
        
    needsign = os.path.join(stagesdir, 'needsign', dist)
    files = find_files(needsign)
    destdir = os.path.join(treedir, dist)
    if not os.path.exists(destdir):
        for arch in archdict[dist]:
            os.makedirs(destdir + '/' + arch + '/debug')
        os.makedirs(destdir + '/' + 'SRPMS')

    rpms = files['rpm'] + files['srpm'] + files['debuginfo']
    print "Signing Packages:"
    result = sign_pkgs(rpms)
    if not result:
        print "Error signing packages"
        sys.exit(2)
    
    infolist = []
    for package in files['srpm']:
        (n,a,e,v,r) = naevr(package)
        infolist.append('%s-%s-%s' % (n,v,r))
        pkg_fn = os.path.basename(package)
        srpmloc = os.path.join(destdir, 'SRPMS', pkg_fn)
        if os.path.exists(srpmloc):
            debugprint('Deleting %s' % srpmloc)
            os.unlink(srpmloc)
        debugprint('Moving %s to %s' % (package, srpmloc))
        shutil.move(package, srpmloc)

    # go through each package and move it to the right arch location.
    # if it is a noarch package, copy2 it to all arch locations and unlink it
    # if it is a debuginfo package move it into the 'debug' dir for that arch
    print "Moving Packages into Place"
    for package in files['rpm'] + files['debuginfo']:
        pkg_fn = os.path.basename(package)
        (n,a,e,v,r) = naevr(package)
        if a == 'noarch':
            for arch in archdict[dist]:
                if package in files['debuginfo']:
                    arch = '%s/debug' % arch
                rpmloc = os.path.join(destdir, arch, pkg_fn)
                debugprint("Copying %s to %s" % (package, rpmloc))
                shutil.copy(package, rpmloc)

            os.unlink(package)
            continue
            
        elif a in ['i386', 'i486', 'i586', 'i686', 'athlon']:
            if package in files['debuginfo']:
                arch = 'i386/debug'
            else:
                arch = 'i386'
        
        elif a in ['x86_64', 'ia32e', 'amd64']:
            if package in files['debuginfo']:
                arch = 'x86_64/debug'
            else:
                arch = 'x86_64'
        
        elif a in ['ppc', 'ppc64', 'ppc32']:
            if package in files['debuginfo']:
                arch = 'ppc/debug'
            else:
                arch = 'ppc'

        else:
            print 'Unknown arch %s' % a
            continue

        rpmloc = os.path.join(destdir, arch, pkg_fn)
        debugprint('Moving %s to %s' % (package, rpmloc))        
        shutil.move(package, rpmloc)
        
        
        
    print "Making Repository Metadata"
    # SRPM repo creation
    repodir = os.path.join(destdir, 'SRPMS')
    rpdata = os.path.join(repodir, 'repodata')
    debugprint('removing tree %s' % rpdata)
    shutil.rmtree(rpdata)
    cmd = '/usr/bin/createrepo -q %s' % repodir
    debugprint(cmd)
    result = os.system(cmd)
    cmd = '/usr/bin/repoview %s' % repodir
    debugprint(cmd)
    result = os.system(cmd)
    
    # arch repo creation
    for arch in archdict[dist]:
        repodir = os.path.join(destdir, arch)
        compspath = os.path.join(repodir, compsname)
        rpdata = os.path.join(repodir, 'repodata')
        debugprint('removing tree %s' % rpdata)
        shutil.rmtree(rpdata)
        if os.path.exists(compspath):
            cmd = '/usr/bin/createrepo -q -g %s -x *debuginfo* %s' % (compsname, repodir)
        else:
            cmd = '/usr/bin/createrepo -q -x *debuginfo* %s' % repodir
        debugprint(cmd)
        result = os.system(cmd)
        cmd = '/usr/bin/repoview %s' % repodir
        debugprint(cmd)
        result = os.system(cmd)
        
        dbg_repodir = os.path.join(destdir, arch, 'debug')
        dbg_rpdata = os.path.join(dbg_repodir, 'repodata')
        debugprint('removing tree %s' % dbg_rpdata)
        shutil.rmtree(dbg_rpdata)
        cmd = '/usr/bin/createrepo -q %s' % dbg_repodir
        debugprint(cmd)        
        result = os.system(cmd)
        cmd = '/usr/bin/repoview %s' % dbg_repodir
        debugprint(cmd)        
        result = os.system(cmd)
        
    # email the list
    print "Emailing info"
    email_list(infolist, dist)
    
    # clean up the crap
    print "Cleaning Up"
    for file in files['log'] + files['md5sum'] + files['spec']:
        debugprint('removing %s' % file)
        os.unlink(file)
    
    # FIXME clean up empty dirs, too.
    
if __name__ == '__main__':
    me = os.getcwd()
    if len(sys.argv) < 2:
        print "Usage:\nextras-push.py release\n\n"
        sys.exit(1)
    main(sys.argv[1])
    os.chdir(me)
    




More information about the fedora-extras-commits mailing list