blob: 3cd1eb0342e3eb24dd198c6d6db442e3ec5fdf2b [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,
24 "formats for distribution " +
25 "(gztar, bztar, zip, rpm, ... )"),
Greg Ward0f77f952000-03-31 02:55:12 +000026 ]
27
Gregory P. Smith52e399c2000-05-13 01:49:56 +000028 # The following commands do not take a format option from bdist
29 no_format_option = ('bdist_rpm',)
30
Greg Ward0f77f952000-03-31 02:55:12 +000031 # This won't do in reality: will need to distinguish RPM-ish Linux,
32 # Debian-ish Linux, Solaris, FreeBSD, ..., Windows, Mac OS.
33 default_format = { 'posix': 'gztar',
34 'nt': 'zip', }
35
36 format_command = { 'gztar': 'bdist_dumb',
Greg Wardf1948782000-04-25 01:38:20 +000037 'bztar': 'bdist_dumb',
Greg Ward6b213762000-03-31 04:53:41 +000038 'ztar': 'bdist_dumb',
39 'tar': 'bdist_dumb',
Gregory P. Smith52e399c2000-05-13 01:49:56 +000040 'rpm': 'bdist_rpm',
Greg Ward0f77f952000-03-31 02:55:12 +000041 'zip': 'bdist_dumb', }
42
43
44 def initialize_options (self):
Gregory P. Smithc59d4e02000-05-13 03:08:28 +000045 self.bdist_base = None
Greg Warde18dd8d2000-06-06 02:51:38 +000046 self.formats = None
Greg Ward0f77f952000-03-31 02:55:12 +000047
48 # initialize_options()
49
50
51 def finalize_options (self):
Gregory P. Smithc59d4e02000-05-13 03:08:28 +000052 # 'bdist_base' -- parent of per-built-distribution-format
53 # temporary directories (eg. we'll probably have
54 # "build/bdist.<plat>/dumb", "build/bdist.<plat>/rpm", etc.)
55 if self.bdist_base is None:
Greg Ward4fb29e52000-05-27 17:27:23 +000056 build_base = self.get_finalized_command('build').build_base
Gregory P. Smithc59d4e02000-05-13 03:08:28 +000057 plat = get_platform()
58 self.bdist_base = os.path.join (build_base, 'bdist.' + plat)
59
Greg Warde18dd8d2000-06-06 02:51:38 +000060 self.ensure_string_list('formats')
61 if self.formats is None:
Greg Ward0f77f952000-03-31 02:55:12 +000062 try:
Greg Warde18dd8d2000-06-06 02:51:38 +000063 self.formats = [self.default_format[os.name]]
Greg Ward0f77f952000-03-31 02:55:12 +000064 except KeyError:
65 raise DistutilsPlatformError, \
66 "don't know how to create built distributions " + \
67 "on platform %s" % os.name
Greg Ward0f77f952000-03-31 02:55:12 +000068
Greg Ward0f77f952000-03-31 02:55:12 +000069 # finalize_options()
70
71
72 def run (self):
73
Greg Warde18dd8d2000-06-06 02:51:38 +000074 for format in self.formats:
Greg Ward0f77f952000-03-31 02:55:12 +000075
Greg Warde18dd8d2000-06-06 02:51:38 +000076 try:
77 cmd_name = self.format_command[self.format]
78 except KeyError:
79 raise DistutilsOptionError, \
80 "invalid format '%s'" % self.format
81
82 sub_cmd = self.reinitialize_command(cmd_name)
83 if cmd_name not in self.no_format_option:
84 sub_cmd.format = self.format
85 self.run_command (cmd_name)
Greg Ward0f77f952000-03-31 02:55:12 +000086
87 # run()
88
89# class bdist