[Distutils] PATCH: Expanded tarball abilites

Harry Henry Gebel hgebel@inet.net
Mon, 24 Apr 2000 01:33:48 -0400


--0NB0lE7sNnW8+0qW
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

I have attached a patch against CVS to expand the functionality of the
tarball formats in the sdist and bdist commands. It adds the following:

Adds bztar format to generate .tar.bz2 tarballs

Uses the -f argument to overright old tarballs automatically, I am
assuming that if the old tarball was wanted it would have been moved or
else the version number would have been changed.

Uses the -9 argument to bzip2 and gzip to use maximum
compression. Compress uses the maximum compression by default.

Tests for correct value for the 'compress' argument of make_tarball. This
is one less place for someone adding new compression programs to forget to
change.

I have a patch (but not attached) which detects if tar is GNU tar > 1.13,
but I do not know if I should submit it because it depends on the
Unix-only popen2 module. Can it be assumed that only Unix users will
generate tarballs, and if this assumption can be made should I submit the
patch? In any case, I don't know very much about tar, so someone else
would have to put the information to use after it is detected.

-- 
Harry Henry Gebel, Senior Developer, Landon House SBS
West Dover Hundred, Delaware

"Why do you look for the living among the dead?
He is not here, but has risen." 
Luke 24:5 (NRSV)

--0NB0lE7sNnW8+0qW
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="tarballs.patch"

? build
? MANIFEST
? tarballs.patch
Index: distutils/archive_util.py
===================================================================
RCS file: /projects/cvsroot/distutils/distutils/archive_util.py,v
retrieving revision 1.2
diff -u -r1.2 archive_util.py
--- archive_util.py	2000/04/22 03:09:56	1.2
+++ archive_util.py	2000/04/24 05:28:18
@@ -15,12 +15,12 @@
 def make_tarball (base_name, base_dir, compress="gzip",
                   verbose=0, dry_run=0):
     """Create a (possibly compressed) tar file from all the files under
-       'base_dir'.  'compress' must be "gzip" (the default), "compress", or
-       None.  Both "tar" and the compression utility named by 'compress'
-       must be on the default program search path, so this is probably
-       Unix-specific.  The output tar file will be named 'base_dir' +
-       ".tar", possibly plus the appropriate compression extension
-       (".gz" or ".Z").  Return the output filename."""
+       'base_dir'.  'compress' must be "gzip" (the default), "compress",
+       "bzip2", or None.  Both "tar" and the compression utility named by
+       'compress' must be on the default program search path, so this is
+       probably Unix-specific.  The output tar file will be named 'base_dir'
+       + ".tar", possibly plus the appropriate compression extension (".gz",
+       ".bz2" or ".Z").  Return the output filename."""
 
     # XXX GNU tar 1.13 has a nifty option to add a prefix directory.
     # It's pretty new, though, so we certainly can't require it --
@@ -29,9 +29,15 @@
     # detect GNU tar to use its 'z' option and save a step.)
 
     compress_ext = { 'gzip': ".gz",
+                     'bzip2': '.bz2'
                      'compress': ".Z" }
+    
+    # flags for compression program, each element of list will be an argument
+    compress_flags = {'gzip': ["-f9"],
+                      'compress': ["-f"],
+                      'bzip2': ['-f9']}
 
-    if compress is not None and compress not in ('gzip', 'compress'):
+    if compress is not None and compress not in compress_ext.keys():
         raise ValueError, \
               "bad value for 'compress': must be None, 'gzip', or 'compress'"
 
@@ -40,7 +46,8 @@
     spawn (cmd, verbose=verbose, dry_run=dry_run)
 
     if compress:
-        spawn ([compress, archive_name], verbose=verbose, dry_run=dry_run)
+        spawn ([compress] + compress_flags[compress] + [archive_name],
+               verbose=verbose, dry_run=dry_run)
         return archive_name + compress_ext[compress]
     else:
         return archive_name
@@ -104,6 +111,7 @@
 
 ARCHIVE_FORMATS = {
     'gztar': (make_tarball, [('compress', 'gzip')]),
+    'bztar': (make_tarball, [('compress', 'bzip2')]),
     'ztar':  (make_tarball, [('compress', 'compress')]),
     'tar':   (make_tarball, [('compress', None)]),
     'zip':   (make_zipfile, [])
Index: distutils/command/bdist.py
===================================================================
RCS file: /projects/cvsroot/distutils/distutils/command/bdist.py,v
retrieving revision 1.4
diff -u -r1.4 bdist.py
--- bdist.py	2000/03/31 05:21:27	1.4
+++ bdist.py	2000/04/24 05:28:19
@@ -18,7 +18,8 @@
     description = "create a built (binary) distribution"
 
     user_options = [('format=', 'f',
-                     "format for distribution (tar, ztar, gztar, zip, ... )"),
+                     "format for distribution " +
+                     "(tar, ztar, gztar, bztar, zip, ... )"),
                    ]
 
     # This won't do in reality: will need to distinguish RPM-ish Linux,
@@ -27,6 +28,7 @@
                        'nt': 'zip', }
 
     format_command = { 'gztar': 'bdist_dumb',
+                       'bztar': 'bdist_dumb',
                        'ztar':  'bdist_dumb',
                        'tar':   'bdist_dumb',
                        'zip':   'bdist_dumb', }
Index: distutils/command/sdist.py
===================================================================
RCS file: /projects/cvsroot/distutils/distutils/command/sdist.py,v
retrieving revision 1.15
diff -u -r1.15 sdist.py
--- sdist.py	2000/04/22 03:11:55	1.15
+++ sdist.py	2000/04/24 05:28:23
@@ -33,9 +33,8 @@
          "just regenerate the manifest and then stop"),
         ('force-manifest', None,
          "forcibly regenerate the manifest and carry on as usual"),
-
         ('formats=', None,
-         "formats for source distribution (tar, ztar, gztar, or zip)"),
+         "formats for source distribution (tar, ztar, gztar, bztar, or zip)"),
         ('keep-tree', 'k',
          "keep the distribution tree around after creating " +
          "archive file(s)"),

--0NB0lE7sNnW8+0qW--