~nomed/bzr-builddeb/nomed

« back to all changes in this revision

Viewing changes to builder.py

  • Committer: James Westby
  • Date: 2007-02-03 15:15:00 UTC
  • Revision ID: jw+debian@jameswestby.net-20070203151500-ow8iuzzbrxm0ghcp
  * Switch to tarfile rather than calling out to tar with os.system().

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
import glob
22
22
import shutil
 
23
import tarfile
23
24
import tempfile
24
25
import os
25
26
 
166
167
      tarball = self._find_tarball()
167
168
      mutter("Extracting %s to %s", tarball, source_dir)
168
169
      tempdir = tempfile.mkdtemp(prefix='builddeb-', dir=build_dir)
169
 
      if os.system('tar xzf "'+tarball+'" -C "'+tempdir+'"') > 0:
170
 
        raise BuildFailedError
 
170
      tar = tarfile.open(tarball)
 
171
      tar.extractall(tempdir)
 
172
      tar.close
171
173
      files = glob.glob(tempdir+'/*')
172
174
      os.makedirs(source_dir)
173
175
      for file in files:
210
212
    # To acheive this we export delete debian/ and tar the result,
211
213
    # then we blow that away and export the whole thing again.
212
214
    source_dir = self._properties.source_dir()
213
 
    tarball = self._tarball_name()
214
215
    build_dir = self._properties.build_dir()
 
216
    tarball = os.path.join(build_dir, self._tarball_name())
215
217
    export(self._tree,source_dir,None,None)
216
 
    info("Creating .orig.tar.gz: %s", os.path.join(build_dir, tarball))
 
218
    info("Creating .orig.tar.gz: %s", tarball)
217
219
    remove_bzrbuilddeb_dir(source_dir)
218
220
    remove_debian_dir(source_dir)
 
221
    tar = tarfile.open(tarball, "w:gz")
219
222
    source_dir_rel = self._properties.source_dir(False)
220
 
    result = os.system('cd "'+build_dir+'" && tar czf "'+tarball+'" "'
221
 
              +source_dir_rel+'"')
222
 
    if result > 0:
223
 
      raise BuildFailedError
 
223
    tar.add(source_dir, source_dir_rel)
224
224
    shutil.rmtree(source_dir)
225
225
    info("Exporting to %s", source_dir)
226
226
    export(self._tree,source_dir,None,None)