1 """distutils.command.bdist
3 Implements the Distutils 'bdist' command (create a built [binary]
6 __revision__ = "$Id: bdist.py 77761 2010-01-26 22:46:15Z tarek.ziade $"
10 from distutils.util import get_platform
11 from distutils.core import Command
12 from distutils.errors import DistutilsPlatformError, DistutilsOptionError
16 """Print list of available formats (arguments to "--format" option).
18 from distutils.fancy_getopt import FancyGetopt
20 for format in bdist.format_commands:
21 formats.append(("formats=" + format, None,
22 bdist.format_command[format][1]))
23 pretty_printer = FancyGetopt(formats)
24 pretty_printer.print_help("List of available distribution formats:")
29 description = "create a built (binary) distribution"
31 user_options = [('bdist-base=', 'b',
32 "temporary directory for creating built distributions"),
34 "platform name to embed in generated filenames "
35 "(default: %s)" % get_platform()),
37 "formats for distribution (comma-separated list)"),
39 "directory to put final built distributions in "
42 "skip rebuilding everything (for testing/debugging)"),
44 "Owner name used when creating a tar file"
45 " [default: current user]"),
47 "Group name used when creating a tar file"
48 " [default: current group]"),
51 boolean_options = ['skip-build']
54 ('help-formats', None,
55 "lists available distribution formats", show_formats),
58 # The following commands do not take a format option from bdist
59 no_format_option = ('bdist_rpm',)
61 # This won't do in reality: will need to distinguish RPM-ish Linux,
62 # Debian-ish Linux, Solaris, FreeBSD, ..., Windows, Mac OS.
63 default_format = {'posix': 'gztar',
67 # Establish the preferred order (for the --help-formats option).
68 format_commands = ['rpm', 'gztar', 'bztar', 'ztar', 'tar',
69 'wininst', 'zip', 'msi']
71 # And the real information.
72 format_command = {'rpm': ('bdist_rpm', "RPM distribution"),
73 'gztar': ('bdist_dumb', "gzip'ed tar file"),
74 'bztar': ('bdist_dumb', "bzip2'ed tar file"),
75 'ztar': ('bdist_dumb', "compressed tar file"),
76 'tar': ('bdist_dumb', "tar file"),
77 'wininst': ('bdist_wininst',
78 "Windows executable installer"),
79 'zip': ('bdist_dumb', "ZIP file"),
80 'msi': ('bdist_msi', "Microsoft Installer")
84 def initialize_options(self):
85 self.bdist_base = None
93 def finalize_options(self):
94 # have to finalize 'plat_name' before 'bdist_base'
95 if self.plat_name is None:
97 self.plat_name = get_platform()
99 self.plat_name = self.get_finalized_command('build').plat_name
101 # 'bdist_base' -- parent of per-built-distribution-format
102 # temporary directories (eg. we'll probably have
103 # "build/bdist.<plat>/dumb", "build/bdist.<plat>/rpm", etc.)
104 if self.bdist_base is None:
105 build_base = self.get_finalized_command('build').build_base
106 self.bdist_base = os.path.join(build_base,
107 'bdist.' + self.plat_name)
109 self.ensure_string_list('formats')
110 if self.formats is None:
112 self.formats = [self.default_format[os.name]]
114 raise DistutilsPlatformError, \
115 "don't know how to create built distributions " + \
116 "on platform %s" % os.name
118 if self.dist_dir is None:
119 self.dist_dir = "dist"
122 # Figure out which sub-commands we need to run.
124 for format in self.formats:
126 commands.append(self.format_command[format][0])
128 raise DistutilsOptionError, "invalid format '%s'" % format
130 # Reinitialize and run each command.
131 for i in range(len(self.formats)):
132 cmd_name = commands[i]
133 sub_cmd = self.reinitialize_command(cmd_name)
134 if cmd_name not in self.no_format_option:
135 sub_cmd.format = self.formats[i]
137 # passing the owner and group names for tar archiving
138 if cmd_name == 'bdist_dumb':
139 sub_cmd.owner = self.owner
140 sub_cmd.group = self.group
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)