blob: cde8dd63e82f99cc504498d858c0d731a26d3868 [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
25 # This won't do in reality: will need to distinguish RPM-ish Linux,
26 # Debian-ish Linux, Solaris, FreeBSD, ..., Windows, Mac OS.
27 default_format = { 'posix': 'gztar',
28 'nt': 'zip', }
29
30 format_command = { 'gztar': 'bdist_dumb',
Greg Wardf1948782000-04-25 01:38:20 +000031 'bztar': 'bdist_dumb',
Greg Ward6b213762000-03-31 04:53:41 +000032 'ztar': 'bdist_dumb',
33 'tar': 'bdist_dumb',
Greg Ward0f77f952000-03-31 02:55:12 +000034 'zip': 'bdist_dumb', }
35
36
37 def initialize_options (self):
Greg Ward02296ce2000-03-31 05:08:50 +000038 self.format = None
Greg Ward0f77f952000-03-31 02:55:12 +000039
40 # initialize_options()
41
42
43 def finalize_options (self):
Greg Ward02296ce2000-03-31 05:08:50 +000044 if self.format is None:
Greg Ward0f77f952000-03-31 02:55:12 +000045 try:
Greg Ward02296ce2000-03-31 05:08:50 +000046 self.format = self.default_format[os.name]
Greg Ward0f77f952000-03-31 02:55:12 +000047 except KeyError:
48 raise DistutilsPlatformError, \
49 "don't know how to create built distributions " + \
50 "on platform %s" % os.name
Greg Ward02296ce2000-03-31 05:08:50 +000051 #elif type (self.format) is StringType:
52 # self.format = string.split (self.format, ',')
Greg Ward0f77f952000-03-31 02:55:12 +000053
54
55 # finalize_options()
56
57
58 def run (self):
59
Greg Ward02296ce2000-03-31 05:08:50 +000060 try:
61 cmd_name = self.format_command[self.format]
62 except KeyError:
63 raise DistutilsOptionError, \
64 "invalid archive format '%s'" % self.format
Greg Ward0f77f952000-03-31 02:55:12 +000065
Greg Ward02296ce2000-03-31 05:08:50 +000066 sub_cmd = self.find_peer (cmd_name)
67 sub_cmd.set_option ('format', self.format)
Greg Warde5796fe2000-03-31 05:21:27 +000068 self.run_peer (cmd_name)
Greg Ward0f77f952000-03-31 02:55:12 +000069
70 # run()
71
72# class bdist