blob: 47d4cbc9652d472b50a514edfbbde265c33a08be [file] [log] [blame]
Greg Ward0f77f952000-03-31 02:55:12 +00001"""distutils.command.bdist
2
3Implements the Distutils 'bdist' command (create a built [binary]
4distribution)."""
5
6# created 2000/03/29, Greg Ward
7
8__revision__ = "$Id$"
9
10import os, string
Greg Ward6b213762000-03-31 04:53:41 +000011from types import *
Greg Ward0f77f952000-03-31 02:55:12 +000012from distutils.core import Command
Greg Ward02296ce2000-03-31 05:08:50 +000013from distutils.errors import *
Gregory P. Smithc59d4e02000-05-13 03:08:28 +000014from distutils.util import get_platform
Greg Ward0f77f952000-03-31 02:55:12 +000015
16
Greg Ward34593812000-06-24 01:23:37 +000017def show_formats ():
18 """Print list of available formats (arguments to "--format" option).
19 """
20 from distutils.fancy_getopt import FancyGetopt
21 formats=[]
22 for format in bdist.format_commands:
23 formats.append(("formats=" + format, None,
24 bdist.format_command[format][1]))
25 pretty_printer = FancyGetopt(formats)
26 pretty_printer.print_help("List of available distribution formats:")
27
28
Greg Ward0f77f952000-03-31 02:55:12 +000029class bdist (Command):
30
31 description = "create a built (binary) distribution"
32
Gregory P. Smithc59d4e02000-05-13 03:08:28 +000033 user_options = [('bdist-base=', 'b',
34 "temporary directory for creating built distributions"),
Greg Warde18dd8d2000-06-06 02:51:38 +000035 ('formats=', None,
Greg Ward2ff78872000-06-24 00:23:20 +000036 "formats for distribution (comma-separated list)"),
Greg Ward0f77f952000-03-31 02:55:12 +000037 ]
38
Greg Ward34593812000-06-24 01:23:37 +000039 help_options = [
40 ('help-formats', None,
41 "lists available distribution formats", show_formats),
42 ]
43
Gregory P. Smith52e399c2000-05-13 01:49:56 +000044 # The following commands do not take a format option from bdist
45 no_format_option = ('bdist_rpm',)
46
Greg Ward0f77f952000-03-31 02:55:12 +000047 # This won't do in reality: will need to distinguish RPM-ish Linux,
48 # Debian-ish Linux, Solaris, FreeBSD, ..., Windows, Mac OS.
49 default_format = { 'posix': 'gztar',
50 'nt': 'zip', }
51
Greg Ward2ff78872000-06-24 00:23:20 +000052 format_command = { 'rpm': ('bdist_rpm', "RPM distribution"),
53 'gztar': ('bdist_dumb', "gzip'ed tar file"),
54 'bztar': ('bdist_dumb', "bzip2'ed tar file"),
55 'ztar': ('bdist_dumb', "compressed tar file"),
56 'tar': ('bdist_dumb', "tar file"),
57 'zip': ('bdist_dumb', "ZIP file"),
Greg Ward34593812000-06-24 01:23:37 +000058 }
59 # establish the preferred order
60 format_commands = ['rpm', 'gztar', 'bztar', 'ztar', 'tar', 'zip']
Greg Ward0f77f952000-03-31 02:55:12 +000061
62
63 def initialize_options (self):
Gregory P. Smithc59d4e02000-05-13 03:08:28 +000064 self.bdist_base = None
Greg Warde18dd8d2000-06-06 02:51:38 +000065 self.formats = None
Greg Ward0f77f952000-03-31 02:55:12 +000066
67 # initialize_options()
68
69
70 def finalize_options (self):
Gregory P. Smithc59d4e02000-05-13 03:08:28 +000071 # 'bdist_base' -- parent of per-built-distribution-format
72 # temporary directories (eg. we'll probably have
73 # "build/bdist.<plat>/dumb", "build/bdist.<plat>/rpm", etc.)
74 if self.bdist_base is None:
Greg Ward4fb29e52000-05-27 17:27:23 +000075 build_base = self.get_finalized_command('build').build_base
Gregory P. Smithc59d4e02000-05-13 03:08:28 +000076 plat = get_platform()
77 self.bdist_base = os.path.join (build_base, 'bdist.' + plat)
78
Greg Warde18dd8d2000-06-06 02:51:38 +000079 self.ensure_string_list('formats')
80 if self.formats is None:
Greg Ward0f77f952000-03-31 02:55:12 +000081 try:
Greg Warde18dd8d2000-06-06 02:51:38 +000082 self.formats = [self.default_format[os.name]]
Greg Ward0f77f952000-03-31 02:55:12 +000083 except KeyError:
84 raise DistutilsPlatformError, \
85 "don't know how to create built distributions " + \
86 "on platform %s" % os.name
Greg Ward0f77f952000-03-31 02:55:12 +000087
Greg Ward0f77f952000-03-31 02:55:12 +000088 # finalize_options()
89
90
91 def run (self):
92
Greg Warde18dd8d2000-06-06 02:51:38 +000093 for format in self.formats:
Greg Warde18dd8d2000-06-06 02:51:38 +000094 try:
Greg Ward9d17a7a2000-06-07 03:00:06 +000095 cmd_name = self.format_command[format][0]
Greg Warde18dd8d2000-06-06 02:51:38 +000096 except KeyError:
97 raise DistutilsOptionError, \
Greg Ward9d17a7a2000-06-07 03:00:06 +000098 "invalid format '%s'" % format
Greg Warde18dd8d2000-06-06 02:51:38 +000099
100 sub_cmd = self.reinitialize_command(cmd_name)
101 if cmd_name not in self.no_format_option:
Greg Ward9d17a7a2000-06-07 03:00:06 +0000102 sub_cmd.format = format
Greg Warde18dd8d2000-06-06 02:51:38 +0000103 self.run_command (cmd_name)
Greg Ward0f77f952000-03-31 02:55:12 +0000104
105 # run()
106
107# class bdist