Index: E:/Programmazione/Python/Sources/[PRJ] - pyftpdlib/__svn/python/Lib/distutils/archive_util.py
===================================================================
--- E:/Programmazione/Python/Sources/[PRJ] - pyftpdlib/__svn/python/Lib/distutils/archive_util.py	(revision 60064)
+++ E:/Programmazione/Python/Sources/[PRJ] - pyftpdlib/__svn/python/Lib/distutils/archive_util.py	(working copy)
@@ -8,6 +8,9 @@
 __revision__ = "$Id$"
 
 import os
+import tarfile
+import gzip
+import bz2
 from distutils.errors import DistutilsExecError
 from distutils.spawn import spawn
 from distutils.dir_util import mkpath
@@ -34,9 +37,9 @@
                      'compress': ".Z" }
 
     # flags for compression program, each element of list will be an argument
-    compress_flags = {'gzip': ["-f9"],
+    compress_flags = {'gzip': 9,
                       'compress': ["-f"],
-                      'bzip2': ['-f9']}
+                      'bzip2': 9}
 
     if compress is not None and compress not in compress_ext.keys():
         raise ValueError, \
@@ -44,15 +47,38 @@
 
     archive_name = base_name + ".tar"
     mkpath(os.path.dirname(archive_name), dry_run=dry_run)
-    cmd = ["tar", "-cf", archive_name, base_dir]
-    spawn(cmd, dry_run=dry_run)
-
-    if compress:
-        spawn([compress] + compress_flags[compress] + [archive_name],
-              dry_run=dry_run)
+    tar = tarfile.open(archive_name, "w")
+    tar.add(base_dir)
+    tar.close()
+    if not compress:
+        return archive_name
+    else:
+        def create_archive(_class, ext):
+            file = open(archive_name, 'rb')
+            try:
+                archive = _class(filename=archive_name + ext,
+                                 mode='wb',
+                                 compresslevel=compress_flags[compress])
+                while 1:
+                    chunk = file.read(65536)
+                    if not chunk:
+                        break
+                    archive.write(chunk)
+                archive.close()
+            finally:
+                if not file.closed:
+                    file.close()
+                os.remove(archive_name)
+            
+        if compress == 'gzip':
+            create_archive(gzip.GzipFile, '.gz')
+        elif compress == 'bzip2':
+            create_archive(bz2.BZ2File, '.bz2')
+        else:
+            spawn([compress] + compress_flags[compress] + [archive_name],
+                  dry_run=dry_run)
+            return archive_name + compress_ext[compress]
         return archive_name + compress_ext[compress]
-    else:
-        return archive_name
 
 # make_tarball ()
 
