1
"""distutils.command.bdist
3
Implements the Distutils 'bdist' command (create a built [binary]
6
# This module should be kept compatible with Python 2.1.
8
__revision__ = "$Id: bdist.py,v 1.30 2004/11/10 22:23:14 loewis Exp $"
12
from distutils.core import Command
13
from distutils.errors import *
14
from distutils.util import get_platform
18
"""Print list of available formats (arguments to "--format" option).
20
from distutils.fancy_getopt import FancyGetopt
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:")
29
class bdist (Command):
31
description = "create a built (binary) distribution"
33
user_options = [('bdist-base=', 'b',
34
"temporary directory for creating built distributions"),
36
"platform name to embed in generated filenames "
37
"(default: %s)" % get_platform()),
39
"formats for distribution (comma-separated list)"),
41
"directory to put final built distributions in "
44
"skip rebuilding everything (for testing/debugging)"),
47
boolean_options = ['skip-build']
50
('help-formats', None,
51
"lists available distribution formats", show_formats),
54
# The following commands do not take a format option from bdist
55
no_format_option = ('bdist_rpm',
56
#'bdist_sdux', 'bdist_pkgtool'
59
# This won't do in reality: will need to distinguish RPM-ish Linux,
60
# Debian-ish Linux, Solaris, FreeBSD, ..., Windows, Mac OS.
61
default_format = { 'posix': 'gztar',
65
# Establish the preferred order (for the --help-formats option).
66
format_commands = ['rpm', 'gztar', 'bztar', 'ztar', 'tar',
71
# And the real information.
72
format_command = { 'rpm': ('bdist_rpm', "RPM distribution"),
73
'zip': ('bdist_dumb', "ZIP file"),
74
'gztar': ('bdist_dumb', "gzip'ed tar file"),
75
'bztar': ('bdist_dumb', "bzip2'ed tar file"),
76
'ztar': ('bdist_dumb', "compressed tar file"),
77
'tar': ('bdist_dumb', "tar file"),
78
'wininst': ('bdist_wininst',
79
"Windows executable installer"),
80
'zip': ('bdist_dumb', "ZIP file"),
81
#'pkgtool': ('bdist_pkgtool',
82
# "Solaris pkgtool distribution"),
83
#'sdux': ('bdist_sdux', "HP-UX swinstall depot"),
87
def initialize_options (self):
88
self.bdist_base = None
94
# initialize_options()
97
def finalize_options (self):
98
# have to finalize 'plat_name' before 'bdist_base'
99
if self.plat_name is None:
100
self.plat_name = get_platform()
102
# 'bdist_base' -- parent of per-built-distribution-format
103
# temporary directories (eg. we'll probably have
104
# "build/bdist.<plat>/dumb", "build/bdist.<plat>/rpm", etc.)
105
if self.bdist_base is None:
106
build_base = self.get_finalized_command('build').build_base
107
self.bdist_base = os.path.join(build_base,
108
'bdist.' + self.plat_name)
110
self.ensure_string_list('formats')
111
if self.formats is None:
113
self.formats = [self.default_format[os.name]]
115
raise DistutilsPlatformError, \
116
"don't know how to create built distributions " + \
117
"on platform %s" % os.name
119
if self.dist_dir is None:
120
self.dist_dir = "dist"
127
# Figure out which sub-commands we need to run.
129
for format in self.formats:
131
commands.append(self.format_command[format][0])
133
raise DistutilsOptionError, "invalid format '%s'" % format
135
# Reinitialize and run each command.
136
for i in range(len(self.formats)):
137
cmd_name = commands[i]
138
sub_cmd = self.reinitialize_command(cmd_name)
139
if cmd_name not in self.no_format_option:
140
sub_cmd.format = self.formats[i]
142
# If we're going to need to run this command again, tell it to
143
# keep its temporary files around so subsequent runs go faster.
144
if cmd_name in commands[i+1:]:
145
sub_cmd.keep_temp = 1
146
self.run_command(cmd_name)