blob: 970779dcaa96ac117d4203a4367fadae3e341bb7 [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 *
Greg Ward0f77f952000-03-31 02:55:12 +000014
15
16class bdist (Command):
17
18 description = "create a built (binary) distribution"
19
Greg Ward02296ce2000-03-31 05:08:50 +000020 user_options = [('format=', 'f',
Greg Wardf1948782000-04-25 01:38:20 +000021 "format for distribution " +
22 "(tar, ztar, gztar, bztar, zip, ... )"),
Greg Ward0f77f952000-03-31 02:55:12 +000023 ]
24
Gregory P. Smith52e399c2000-05-13 01:49:56 +000025 # The following commands do not take a format option from bdist
26 no_format_option = ('bdist_rpm',)
27
Greg Ward0f77f952000-03-31 02:55:12 +000028 # This won't do in reality: will need to distinguish RPM-ish Linux,
29 # Debian-ish Linux, Solaris, FreeBSD, ..., Windows, Mac OS.
30 default_format = { 'posix': 'gztar',
31 'nt': 'zip', }
32
33 format_command = { 'gztar': 'bdist_dumb',
Greg Wardf1948782000-04-25 01:38:20 +000034 'bztar': 'bdist_dumb',
Greg Ward6b213762000-03-31 04:53:41 +000035 'ztar': 'bdist_dumb',
36 'tar': 'bdist_dumb',
Gregory P. Smith52e399c2000-05-13 01:49:56 +000037 'rpm': 'bdist_rpm',
Greg Ward0f77f952000-03-31 02:55:12 +000038 'zip': 'bdist_dumb', }
39
40
41 def initialize_options (self):
Greg Ward02296ce2000-03-31 05:08:50 +000042 self.format = None
Greg Ward0f77f952000-03-31 02:55:12 +000043
44 # initialize_options()
45
46
47 def finalize_options (self):
Greg Ward02296ce2000-03-31 05:08:50 +000048 if self.format is None:
Greg Ward0f77f952000-03-31 02:55:12 +000049 try:
Greg Ward02296ce2000-03-31 05:08:50 +000050 self.format = self.default_format[os.name]
Greg Ward0f77f952000-03-31 02:55:12 +000051 except KeyError:
52 raise DistutilsPlatformError, \
53 "don't know how to create built distributions " + \
54 "on platform %s" % os.name
Greg Ward02296ce2000-03-31 05:08:50 +000055 #elif type (self.format) is StringType:
56 # self.format = string.split (self.format, ',')
Greg Ward0f77f952000-03-31 02:55:12 +000057
58
59 # finalize_options()
60
61
62 def run (self):
63
Greg Ward02296ce2000-03-31 05:08:50 +000064 try:
65 cmd_name = self.format_command[self.format]
66 except KeyError:
67 raise DistutilsOptionError, \
68 "invalid archive format '%s'" % self.format
Greg Ward0f77f952000-03-31 02:55:12 +000069
Gregory P. Smith52e399c2000-05-13 01:49:56 +000070 if cmd_name not in self.no_format_option:
71 sub_cmd = self.find_peer (cmd_name)
72 sub_cmd.format = self.format
Greg Warde5796fe2000-03-31 05:21:27 +000073 self.run_peer (cmd_name)
Greg Ward0f77f952000-03-31 02:55:12 +000074
75 # run()
76
77# class bdist