Ticket #3292: modern-tap2rpm-3292.2.patch

File modern-tap2rpm-3292.2.patch, 3.3 KB (added by Screwtape, 6 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..7553592 100644
    a b def _queryRPMTags(rpmfile, taglist): 
    8080
    8181        return res
    8282
     83    def checkErrorResult(failure):
     84        # The current rpm packages on Debian and Ubuntu don't properly set up
     85        # the RPM database, which causes rpm to print a harmless warning to
     86        # stderr. Unfortunately, .getProcessOutput() assumes all warnings are
     87        # catastrophic and panics whenever it sees one.
     88        #
     89        # See also:
     90        #   http://twistedmatrix.com/trac/ticket/3292#comment:42
     91        #   http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=551669
     92        #   http://rpm.org/ticket/106
     93
     94        failure.trap(IOError)
     95
     96        # Check whether this warning is the one symptomatic of Debian's RPM
     97        # problem.
     98        if str(failure.value) == ("got stderr: 'error: cannot open Name index "
     99                "using db3 - No such file or directory (2)\\n'"):
     100            raise SkipTest("rpm is missing its package database. "
     101                    "Run 'sudo rpm -qa > /dev/null' to create one.")
     102        else:
     103            # Not the exception we were looking for; as you were.
     104            failure.raiseException()
     105
    83106    d = utils.getProcessOutput("rpm",
    84107            ("-q", "--queryformat", queryFormat, "-p", rpmfile))
    85     d.addCallback(parseTagValues)
     108    d.addCallbacks(parseTagValues, checkErrorResult)
    86109    return d
    87110
    88111