@@ -29,13 +29,25 @@ def visit(tar, dirname, names):
29
29
path_in_tar = archive_name (path )
30
30
tar .add (path , path_in_tar )
31
31
compression = TARGZ_DEFAULT_COMPRESSION_LEVEL
32
- fileobj = gzip .GzipFile ( tarball_path , 'wb' , compression )
33
- tar = tarfile .TarFile (os .path .splitext (tarball_path )[0 ], 'w' , fileobj )
34
- for source in sources :
35
- source_path = source
36
- if os .path .isdir ( source ):
37
- os .path .walk (source_path , visit , tar )
38
- else :
39
- path_in_tar = archive_name (source_path )
40
- tar .add (source_path , path_in_tar ) # filename, arcname
41
- tar .close ()
32
+ tar = tarfile .TarFile .gzopen ( tarball_path , 'w' , compresslevel = compression )
33
+ try :
34
+ for source in sources :
35
+ source_path = source
36
+ if os .path .isdir ( source ):
37
+ os .path .walk (source_path , visit , tar )
38
+ else :
39
+ path_in_tar = archive_name (source_path )
40
+ tar .add (source_path , path_in_tar ) # filename, arcname
41
+ finally :
42
+ tar .close ()
43
+
44
+ def decompress ( tarball_path , base_dir ):
45
+ """Decompress the gzipped tarball into directory base_dir.
46
+ """
47
+ # !!! This class method is not documented in the online doc
48
+ # nor is bz2open!
49
+ tar = tarfile .TarFile .gzopen (tarball_path , mode = 'r' )
50
+ try :
51
+ tar .extractall ( base_dir )
52
+ finally :
53
+ tar .close ()
0 commit comments