blob: 66ef1133f343d7759dca5441341525ecb5411c44 [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
17class bdist (Command):
18
19 description = "create a built (binary) distribution"
20
Gregory P. Smithc59d4e02000-05-13 03:08:28 +000021 user_options = [('bdist-base=', 'b',
22 "temporary directory for creating built distributions"),
Greg Warde18dd8d2000-06-06 02:51:38 +000023 ('formats=', None,
Greg Ward9d17a7a2000-06-07 03:00:06 +000024 "formats for distribution"),
Greg Ward0f77f952000-03-31 02:55:12 +000025 ]
26
Gregory P. Smith52e399c2000-05-13 01:49:56 +000027 # The following commands do not take a format option from bdist
28 no_format_option = ('bdist_rpm',)
29
Greg Ward0f77f952000-03-31 02:55:12 +000030 # This won't do in reality: will need to distinguish RPM-ish Linux,
31 # Debian-ish Linux, Solaris, FreeBSD, ..., Windows, Mac OS.
32 default_format = { 'posix': 'gztar',
33 'nt': 'zip', }
34
Greg Ward9d17a7a2000-06-07 03:00:06 +000035 format_command = { 'gztar': ('bdist_dumb',"gzipped tar-file"),
36 'bztar': ('bdist_dumb',"bzip2-ed tar-file"),
37 'ztar': ('bdist_dumb',"compressed tar-file"),
38 'tar': ('bdist_dumb',"tar-file"),
39 'rpm': ('bdist_rpm',"rpm distribution"),
40 'zip': ('bdist_dumb',"zip-file"),
41 }
42
43 # prints all possible arguments to --format
44 def show_formats():
45 from distutils.fancy_getopt import FancyGetopt
46 list_of_formats=[]
47 for format in bdist.format_command.keys():
48 list_of_formats.append(("formats="+format,None,bdist.format_command[format][1]))
49 list_of_formats.sort()
50 pretty_printer=FancyGetopt(list_of_formats)
51 pretty_printer.print_help("List of available distribution formats:")
52
53 help_options = [
54 ('help-formats', None,
55 "lists available distribution formats",show_formats),
56 ]
Greg Ward0f77f952000-03-31 02:55:12 +000057
58
59 def initialize_options (self):
Gregory P. Smithc59d4e02000-05-13 03:08:28 +000060 self.bdist_base = None
Greg Warde18dd8d2000-06-06 02:51:38 +000061 self.formats = None
Greg Ward0f77f952000-03-31 02:55:12 +000062
63 # initialize_options()
64
65
66 def finalize_options (self):
Gregory P. Smithc59d4e02000-05-13 03:08:28 +000067 # 'bdist_base' -- parent of per-built-distribution-format
68 # temporary directories (eg. we'll probably have
69 # "build/bdist.<plat>/dumb", "build/bdist.<plat>/rpm", etc.)
70 if self.bdist_base is None:
Greg Ward4fb29e52000-05-27 17:27:23 +000071 build_base = self.get_finalized_command('build').build_base
Gregory P. Smithc59d4e02000-05-13 03:08:28 +000072 plat = get_platform()
73 self.bdist_base = os.path.join (build_base, 'bdist.' + plat)
74
Greg Warde18dd8d2000-06-06 02:51:38 +000075 self.ensure_string_list('formats')
76 if self.formats is None:
Greg Ward0f77f952000-03-31 02:55:12 +000077 try:
Greg Warde18dd8d2000-06-06 02:51:38 +000078 self.formats = [self.default_format[os.name]]
Greg Ward0f77f952000-03-31 02:55:12 +000079 except KeyError:
80 raise DistutilsPlatformError, \
81 "don't know how to create built distributions " + \
82 "on platform %s" % os.name
Greg Ward0f77f952000-03-31 02:55:12 +000083
Greg Ward0f77f952000-03-31 02:55:12 +000084 # finalize_options()
85
86
87 def run (self):
88
Greg Warde18dd8d2000-06-06 02:51:38 +000089 for format in self.formats:
Greg Ward0f77f952000-03-31 02:55:12 +000090
Greg Warde18dd8d2000-06-06 02:51:38 +000091 try:
Greg Ward9d17a7a2000-06-07 03:00:06 +000092 cmd_name = self.format_command[format][0]
Greg Warde18dd8d2000-06-06 02:51:38 +000093 except KeyError:
94 raise DistutilsOptionError, \
Greg Ward9d17a7a2000-06-07 03:00:06 +000095 "invalid format '%s'" % format
Greg Warde18dd8d2000-06-06 02:51:38 +000096
97 sub_cmd = self.reinitialize_command(cmd_name)
98 if cmd_name not in self.no_format_option:
Greg Ward9d17a7a2000-06-07 03:00:06 +000099 sub_cmd.format = format
Greg Warde18dd8d2000-06-06 02:51:38 +0000100 self.run_command (cmd_name)
Greg Ward0f77f952000-03-31 02:55:12 +0000101
102 # run()
103
104# class bdist