blob: 685f52508ea600eccb7f7474301af80d9a0713dc [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',
21 "format for distribution (tar, ztar, gztar, zip, ... )"),
Greg Ward0f77f952000-03-31 02:55:12 +000022 ]
23
24 # This won't do in reality: will need to distinguish RPM-ish Linux,
25 # Debian-ish Linux, Solaris, FreeBSD, ..., Windows, Mac OS.
26 default_format = { 'posix': 'gztar',
27 'nt': 'zip', }
28
29 format_command = { 'gztar': 'bdist_dumb',
Greg Ward6b213762000-03-31 04:53:41 +000030 'ztar': 'bdist_dumb',
31 'tar': 'bdist_dumb',
Greg Ward0f77f952000-03-31 02:55:12 +000032 'zip': 'bdist_dumb', }
33
34
35 def initialize_options (self):
Greg Ward02296ce2000-03-31 05:08:50 +000036 self.format = None
Greg Ward0f77f952000-03-31 02:55:12 +000037
38 # initialize_options()
39
40
41 def finalize_options (self):
Greg Ward02296ce2000-03-31 05:08:50 +000042 if self.format is None:
Greg Ward0f77f952000-03-31 02:55:12 +000043 try:
Greg Ward02296ce2000-03-31 05:08:50 +000044 self.format = self.default_format[os.name]
Greg Ward0f77f952000-03-31 02:55:12 +000045 except KeyError:
46 raise DistutilsPlatformError, \
47 "don't know how to create built distributions " + \
48 "on platform %s" % os.name
Greg Ward02296ce2000-03-31 05:08:50 +000049 #elif type (self.format) is StringType:
50 # self.format = string.split (self.format, ',')
Greg Ward0f77f952000-03-31 02:55:12 +000051
52
53 # finalize_options()
54
55
56 def run (self):
57
Greg Ward02296ce2000-03-31 05:08:50 +000058 try:
59 cmd_name = self.format_command[self.format]
60 except KeyError:
61 raise DistutilsOptionError, \
62 "invalid archive format '%s'" % self.format
Greg Ward0f77f952000-03-31 02:55:12 +000063
Greg Ward02296ce2000-03-31 05:08:50 +000064 sub_cmd = self.find_peer (cmd_name)
65 sub_cmd.set_option ('format', self.format)
Greg Warde5796fe2000-03-31 05:21:27 +000066 self.run_peer (cmd_name)
Greg Ward0f77f952000-03-31 02:55:12 +000067
68 # run()
69
70# class bdist