Ticket #3292: modern-tap2rpm-3292-2.patch

File modern-tap2rpm-3292-2.patch, 3.9 KB (added by Screwtape, 7 years ago)

Fixes for running RPM tests on Debian and Ubuntu.

  • twisted/scripts/tap2rpm.py

    diff --git a/twisted/scripts/tap2rpm.py b/twisted/scripts/tap2rpm.py
    index a3888a7..3f55840 100755
    a b type_dict = { 
    167167
    168168##########################
    169169def makeBuildDir(baseDir):
    170     '''Set up the temporary directory for building RPMs.
    171     Returns: Tuple: ( buildDir, rpmrcFile )
     170    '''
     171    Set up the temporary directory for building RPMs.
     172
     173    Returns: buildDir, a randomly-named subdirectory of baseDir.
    172174    '''
    173175    import random, string
    174176
    def makeBuildDir(baseDir): 
    189191    os.makedirs(os.path.join(tmpDir, 'SOURCES'))
    190192    os.makedirs(os.path.join(tmpDir, 'SRPMS'))
    191193
    192     #  set up rpmmacros file
    193     macroFile = os.path.join(tmpDir, 'rpmmacros')
    194     rcFile = os.path.join(tmpDir, 'rpmrc')
    195     rpmrcData = open('/usr/lib/rpm/rpmrc', 'r').read()
    196     rpmrcData = string.replace(rpmrcData, '~/.rpmmacros', macroFile)
    197     fp = open(macroFile, 'w')
    198     fp.write('%%_topdir %s\n' % tmpDir)
    199     fp.close()
    200 
    201     #  set up the rpmrc file
    202     fp = open(rcFile, 'w')
    203     fp.write(rpmrcData)
    204     fp.close()
    205 
    206     return(( tmpDir, rcFile ))
     194    return tmpDir
    207195
    208196
    209197##########
    def run(options=None): 
    236224        maintainer = 'tap2rpm'
    237225
    238226    #  create source archive directory
    239     tmp_dir, rpmrc_file = makeBuildDir('/var/tmp')
     227    tmp_dir = makeBuildDir('/var/tmp')
    240228    source_dir = os.path.join(tmp_dir, directory)
    241229    os.makedirs(source_dir)
    242230
    def run(options=None): 
    257245    print 'Starting build...'
    258246    print '=' * 70
    259247    sys.stdout.flush()
    260     os.system('rpmbuild -ta --rcfile "%s" %s' % ( rpmrc_file, tarfile_name ))
     248    os.system('rpmbuild --define "_topdir %s" -ta %s' % ( tmp_dir, tarfile_name ))
    261249    print 'Done with build...'
    262250    print '=' * 70
    263251   
  • twisted/scripts/test/test_tap2rpm.py

    diff --git a/twisted/scripts/test/test_tap2rpm.py b/twisted/scripts/test/test_tap2rpm.py
    index 0f8863d..d4ac41a 100644
    a b Tests for L{twisted.scripts.tap2rpm}. 
    77from os.path import exists
    88from twisted.trial.unittest import TestCase, SkipTest
    99from twisted.python import log, procutils
     10from twisted.python.failure import Failure
    1011from twisted.internet import utils
    1112from twisted.scripts import tap2rpm
    1213
    def _queryRPMTags(rpmfile, taglist): 
    8081
    8182        return res
    8283
     84    def checkErrorResult(failure):
     85        # The current rpm packages on Debian and Ubuntu don't properly set up
     86        # the RPM database, which causes rpm to print a harmless warning to
     87        # stderr. Unfortunately, .getProcessOutput() assumes all warnings are
     88        # catastrophic and panics whenever it sees one.
     89        #
     90        # See also:
     91        #   http://twistedmatrix.com/trac/ticket/3292#comment:42
     92        #   http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=551669
     93        #   http://rpm.org/ticket/106
     94
     95        failure.trap(IOError)
     96
     97        # Depending on kernel scheduling, we might read the whole error
     98        # message, or only the first few bytes.
     99        if str(failure.value).startswith("got stderr: 'error: "):
     100            newFailure = Failure(SkipTest("rpm is missing its package "
     101                    "database. Run 'sudo rpm -qa > /dev/null' to create one."))
     102        else:
     103            # Not the exception we were looking for; we should report the
     104            # original failure.
     105            newFailure = failure
     106
     107        # We don't want to raise the exception right away; we want to wait for
     108        # the process to exit, otherwise we'll get extra useless errors
     109        # reported.
     110        d = failure.value.processEnded
     111        d.addBoth(lambda _: newFailure)
     112        return d
     113
    83114    d = utils.getProcessOutput("rpm",
    84115            ("-q", "--queryformat", queryFormat, "-p", rpmfile))
    85     d.addCallback(parseTagValues)
     116    d.addCallbacks(parseTagValues, checkErrorResult)
    86117    return d
    87118
    88119