From 35bdc07ebdf925c6c0fe7ce12ed01df9961712e3 Mon Sep 17 00:00:00 2001 From: Baptiste Lepilleur Date: Wed, 24 Feb 2010 08:05:41 +0000 Subject: [PATCH] - added source tarball decompression --- devtools/tarball.py | 32 ++++++++++++++++++++++---------- makerelease.py | 5 ++++- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/devtools/tarball.py b/devtools/tarball.py index 2ce261a..182602e 100644 --- a/devtools/tarball.py +++ b/devtools/tarball.py @@ -29,13 +29,25 @@ def make_tarball(tarball_path, sources, base_dir, prefix_dir=''): path_in_tar = archive_name(path) tar.add(path, path_in_tar ) compression = TARGZ_DEFAULT_COMPRESSION_LEVEL - fileobj = gzip.GzipFile( tarball_path, 'wb', compression ) - tar = tarfile.TarFile(os.path.splitext(tarball_path)[0], 'w', fileobj) - for source in sources: - source_path = source - if os.path.isdir( source ): - os.path.walk(source_path, visit, tar) - else: - path_in_tar = archive_name(source_path) - tar.add(source_path, path_in_tar ) # filename, arcname - tar.close() + tar = tarfile.TarFile.gzopen( tarball_path, 'w', compresslevel=compression ) + try: + for source in sources: + source_path = source + if os.path.isdir( source ): + os.path.walk(source_path, visit, tar) + else: + path_in_tar = archive_name(source_path) + tar.add(source_path, path_in_tar ) # filename, arcname + finally: + tar.close() + +def decompress( tarball_path, base_dir ): + """Decompress the gzipped tarball into directory base_dir. + """ + # !!! This class method is not documented in the online doc + # nor is bz2open! + tar = tarfile.TarFile.gzopen(tarball_path, mode='r') + try: + tar.extractall( base_dir ) + finally: + tar.close() diff --git a/makerelease.py b/makerelease.py index b928c62..9dcdcf6 100644 --- a/makerelease.py +++ b/makerelease.py @@ -167,8 +167,11 @@ Must be started in the project top directory. source_tarball_path = 'dist/%s.tar.gz' % source_dir print 'Generating source tarball to', source_tarball_path tarball.make_tarball( source_tarball_path, [export_dir], export_dir, prefix_dir=source_dir ) + + distcheck_dir = 'dist/distcheck' + print 'Decompressing source tarball to', distcheck_dir + tarball.decompress( source_tarball_path, distcheck_dir ) #@todo: - # decompress source tarball # ?compile & run & check # ?upload documentation else: