1
"""distutils.command.bdist
3
Implements the Distutils 'bdist' command (create a built [binary]
6
__revision__ = "$Id: bdist.py 62242 2008-04-09 08:37:03Z christian.heimes $"
9
from distutils.core import Command
10
from distutils.errors import *
11
from distutils.util import get_platform
15
"""Print list of available formats (arguments to "--format" option).
17
from distutils.fancy_getopt import FancyGetopt
19
for format in bdist.format_commands:
20
formats.append(("formats=" + format, None,
21
bdist.format_command[format][1]))
22
pretty_printer = FancyGetopt(formats)
23
pretty_printer.print_help("List of available distribution formats:")
28
description = "create a built (binary) distribution"
30
user_options = [('bdist-base=', 'b',
31
"temporary directory for creating built distributions"),
33
"platform name to embed in generated filenames "
34
"(default: %s)" % get_platform()),
36
"formats for distribution (comma-separated list)"),
38
"directory to put final built distributions in "
41
"skip rebuilding everything (for testing/debugging)"),
44
boolean_options = ['skip-build']
47
('help-formats', None,
48
"lists available distribution formats", show_formats),
51
# The following commands do not take a format option from bdist
52
no_format_option = ('bdist_rpm',
53
#'bdist_sdux', 'bdist_pkgtool'
56
# This won't do in reality: will need to distinguish RPM-ish Linux,
57
# Debian-ish Linux, Solaris, FreeBSD, ..., Windows, Mac OS.
58
default_format = { 'posix': 'gztar',
62
# Establish the preferred order (for the --help-formats option).
63
format_commands = ['rpm', 'gztar', 'bztar', 'ztar', 'tar',
68
# And the real information.
69
format_command = { 'rpm': ('bdist_rpm', "RPM distribution"),
70
'zip': ('bdist_dumb', "ZIP file"),
71
'gztar': ('bdist_dumb', "gzip'ed tar file"),
72
'bztar': ('bdist_dumb', "bzip2'ed tar file"),
73
'ztar': ('bdist_dumb', "compressed tar file"),
74
'tar': ('bdist_dumb', "tar file"),
75
'wininst': ('bdist_wininst',
76
"Windows executable installer"),
77
'zip': ('bdist_dumb', "ZIP file"),
78
#'pkgtool': ('bdist_pkgtool',
79
# "Solaris pkgtool distribution"),
80
#'sdux': ('bdist_sdux', "HP-UX swinstall depot"),
84
def initialize_options(self):
85
self.bdist_base = None
91
def finalize_options(self):
92
# have to finalize 'plat_name' before 'bdist_base'
93
if self.plat_name is None:
95
self.plat_name = get_platform()
97
self.plat_name = self.get_finalized_command('build').plat_name
99
# 'bdist_base' -- parent of per-built-distribution-format
100
# temporary directories (eg. we'll probably have
101
# "build/bdist.<plat>/dumb", "build/bdist.<plat>/rpm", etc.)
102
if self.bdist_base is None:
103
build_base = self.get_finalized_command('build').build_base
104
self.bdist_base = os.path.join(build_base,
105
'bdist.' + self.plat_name)
107
self.ensure_string_list('formats')
108
if self.formats is None:
110
self.formats = [self.default_format[os.name]]
112
raise DistutilsPlatformError(
113
"don't know how to create built distributions "
114
"on platform %s" % os.name)
116
if self.dist_dir is None:
117
self.dist_dir = "dist"
120
# Figure out which sub-commands we need to run.
122
for format in self.formats:
124
commands.append(self.format_command[format][0])
126
raise DistutilsOptionError("invalid format '%s'" % format)
128
# Reinitialize and run each command.
129
for i in range(len(self.formats)):
130
cmd_name = commands[i]
131
sub_cmd = self.reinitialize_command(cmd_name)
132
if cmd_name not in self.no_format_option:
133
sub_cmd.format = self.formats[i]
135
# If we're going to need to run this command again, tell it to
136
# keep its temporary files around so subsequent runs go faster.
137
if cmd_name in commands[i+1:]:
138
sub_cmd.keep_temp = 1
139
self.run_command(cmd_name)