blob: df4e3a03503fa186809ee2e1fbb6b84f7b850909 [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"),
23 ('format=', 'f',
Greg Wardf1948782000-04-25 01:38:20 +000024 "format for distribution " +
25 "(tar, ztar, gztar, bztar, zip, ... )"),
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 Ward02296ce2000-03-31 05:08:50 +000046 self.format = 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 Ward02296ce2000-03-31 05:08:50 +000060 if self.format is None:
Greg Ward0f77f952000-03-31 02:55:12 +000061 try:
Greg Ward02296ce2000-03-31 05:08:50 +000062 self.format = self.default_format[os.name]
Greg Ward0f77f952000-03-31 02:55:12 +000063 except KeyError:
64 raise DistutilsPlatformError, \
65 "don't know how to create built distributions " + \
66 "on platform %s" % os.name
Greg Ward02296ce2000-03-31 05:08:50 +000067 #elif type (self.format) is StringType:
68 # self.format = string.split (self.format, ',')
Greg Ward0f77f952000-03-31 02:55:12 +000069
Greg Ward0f77f952000-03-31 02:55:12 +000070 # finalize_options()
71
72
73 def run (self):
74
Greg Ward02296ce2000-03-31 05:08:50 +000075 try:
76 cmd_name = self.format_command[self.format]
77 except KeyError:
78 raise DistutilsOptionError, \
79 "invalid archive format '%s'" % self.format
Greg Ward0f77f952000-03-31 02:55:12 +000080
Gregory P. Smith52e399c2000-05-13 01:49:56 +000081 if cmd_name not in self.no_format_option:
Greg Ward4fb29e52000-05-27 17:27:23 +000082 sub_cmd = self.get_finalized_command (cmd_name)
Gregory P. Smith52e399c2000-05-13 01:49:56 +000083 sub_cmd.format = self.format
Greg Ward4fb29e52000-05-27 17:27:23 +000084 self.run_command (cmd_name)
Greg Ward0f77f952000-03-31 02:55:12 +000085
86 # run()
87
88# class bdist