Ticket #3292: tarballs-in-python.patch

File tarballs-in-python.patch, 2.8 KB (added by TimAllen, 6 years ago)

Try making the RPM tarball in python, instead of shelling out to tar.

  • twisted/scripts/tap2rpm.py

    diff --git a/twisted/scripts/tap2rpm.py b/twisted/scripts/tap2rpm.py
    index 735f391..1132fe9 100755
    a b  
    66import sys, os, shutil, time, glob
    77import subprocess
    88import tempfile
     9import tarfile
     10from StringIO import StringIO
    911
    1012from twisted.python import usage, log
    1113from twisted.scripts import tap2deb
    def run(options=None): 
    221223    source_dir = os.path.join(tmp_dir, directory)
    222224    os.makedirs(source_dir)
    223225
    224     #  populate source directory
     226    #  create source tar
    225227    tarfile_name = source_dir + '.tar.gz'
    226228    tarfile_basename = os.path.basename(tarfile_name)
    227     tap2deb.save_to_file(os.path.join(source_dir, '%s.spec' % rpm_file),
    228                                       specFileData % vars())
    229     tap2deb.save_to_file(os.path.join(source_dir, '%s.init' % rpm_file),
    230                                       initFileData % vars())
    231     shutil.copy(tap_file, source_dir)
     229    tarHandle = tarfile.open(tarfile_name, "w:gz")
     230
     231    sourceDirInfo = tarfile.TarInfo(directory)
     232    sourceDirInfo.type = tarfile.DIRTYPE
     233    sourceDirInfo.mode = 0755
     234    tarHandle.addfile(sourceDirInfo)
     235
     236    specFileInfo = tarfile.TarInfo(
     237            os.path.join(directory, '%s.spec' % rpm_file))
     238    specFileInfo.type = tarfile.REGTYPE
     239    specFileInfo.mode = 0644
     240    specFileRealData = specFileData % vars()
     241    specFileInfo.size = len(specFileRealData)
     242    tarHandle.addfile(specFileInfo, StringIO(specFileRealData))
     243
     244    initFileInfo = tarfile.TarInfo(
     245            os.path.join(directory, '%s.init' % rpm_file))
     246    initFileInfo.type = tarfile.REGTYPE
     247    initFileInfo.mode = 0755
     248    initFileRealData = initFileData % vars()
     249    initFileInfo.size = len(initFileRealData)
     250    tarHandle.addfile(initFileInfo, StringIO(initFileRealData))
     251
     252    tapFileHandle = open(tap_file, 'rb')
     253    tapFileInfo = tarHandle.gettarinfo(
     254            arcname=os.path.join(directory, os.path.basename(tap_file)),
     255            fileobj=tapFileHandle,
     256        )
     257    tapFileInfo.mode = 0644
     258    tarHandle.addfile(tapFileInfo, tapFileHandle)
     259
     260    tarHandle.close()
    232261
    233     #  create source tar
    234     os.system('cd "%(tmp_dir)s"; tar cfz "%(tarfile_name)s" "%(directory)s"'
    235               % vars())
    236    
    237262    print "Checking content of tarball %r before we hand it to rpmbuild..." % (
    238263            tarfile_name)
    239264    os.system('tar tzvf "%(tarfile_name)s"' % vars())
    def run(options=None): 
    245270            "-vv",
    246271            "--define", "_topdir %s" % (tmp_dir,),
    247272            "-ta", tarfile_name,
    248                ])
    249     #       ], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
     273        ], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    250274    stdout, _ = job.communicate()
    251275
    252276    # If there was a problem, show people what it was.