]>
Commit | Line | Data |
---|---|---|
1e4a197e RD |
1 | """distutils.command.bdist |
2 | ||
3 | Implements the Distutils 'bdist' command (create a built [binary] | |
4 | distribution).""" | |
5 | ||
6 | # This module should be kept compatible with Python 1.5.2. | |
7 | ||
8 | __revision__ = "$Id$" | |
9 | ||
10 | import os, string | |
11 | from types import * | |
12 | from distutils.core import Command | |
13 | from distutils.errors import * | |
14 | from distutils.util import get_platform | |
15 | ||
16 | ||
17 | def show_formats (): | |
18 | """Print list of available formats (arguments to "--format" option). | |
19 | """ | |
20 | from distutils.fancy_getopt import FancyGetopt | |
21 | formats=[] | |
22 | for format in bdist.format_commands: | |
23 | formats.append(("formats=" + format, None, | |
24 | bdist.format_command[format][1])) | |
25 | pretty_printer = FancyGetopt(formats) | |
26 | pretty_printer.print_help("List of available distribution formats:") | |
27 | ||
28 | ||
29 | class bdist (Command): | |
30 | ||
31 | description = "create a built (binary) distribution" | |
32 | ||
33 | user_options = [('bdist-base=', 'b', | |
34 | "temporary directory for creating built distributions"), | |
35 | ('plat-name=', 'p', | |
36 | "platform name to embed in generated filenames " | |
37 | "(default: %s)" % get_platform()), | |
38 | ('formats=', None, | |
39 | "formats for distribution (comma-separated list)"), | |
40 | ('dist-dir=', 'd', | |
41 | "directory to put final built distributions in " | |
42 | "[default: dist]"), | |
43 | ('skip-build', None, | |
44 | "skip rebuilding everything (for testing/debugging)"), | |
45 | ] | |
46 | ||
47 | boolean_options = ['skip-build'] | |
48 | ||
49 | help_options = [ | |
50 | ('help-formats', None, | |
51 | "lists available distribution formats", show_formats), | |
52 | ] | |
53 | ||
54 | # The following commands do not take a format option from bdist | |
55 | no_format_option = ('bdist_rpm', | |
56 | #'bdist_sdux', 'bdist_pkgtool' | |
57 | ) | |
58 | ||
59 | # This won't do in reality: will need to distinguish RPM-ish Linux, | |
60 | # Debian-ish Linux, Solaris, FreeBSD, ..., Windows, Mac OS. | |
61 | default_format = { 'posix': 'gztar', | |
62 | 'nt': 'zip', | |
63 | 'os2': 'zip', } | |
64 | ||
65 | # Establish the preferred order (for the --help-formats option). | |
66 | format_commands = ['rpm', 'gztar', 'bztar', 'ztar', 'tar', | |
67 | 'wininst', 'zip', | |
68 | #'pkgtool', 'sdux' | |
69 | ] | |
70 | ||
71 | # And the real information. | |
72 | format_command = { 'rpm': ('bdist_rpm', "RPM distribution"), | |
73 | 'zip': ('bdist_dumb', "ZIP file"), | |
74 | 'gztar': ('bdist_dumb', "gzip'ed tar file"), | |
75 | 'bztar': ('bdist_dumb', "bzip2'ed tar file"), | |
76 | 'ztar': ('bdist_dumb', "compressed tar file"), | |
77 | 'tar': ('bdist_dumb', "tar file"), | |
78 | 'wininst': ('bdist_wininst', | |
79 | "Windows executable installer"), | |
80 | 'zip': ('bdist_dumb', "ZIP file"), | |
81 | #'pkgtool': ('bdist_pkgtool', | |
82 | # "Solaris pkgtool distribution"), | |
83 | #'sdux': ('bdist_sdux', "HP-UX swinstall depot"), | |
84 | } | |
85 | ||
86 | ||
87 | def initialize_options (self): | |
88 | self.bdist_base = None | |
89 | self.plat_name = None | |
90 | self.formats = None | |
91 | self.dist_dir = None | |
92 | self.skip_build = 0 | |
93 | ||
94 | # initialize_options() | |
95 | ||
96 | ||
97 | def finalize_options (self): | |
98 | # have to finalize 'plat_name' before 'bdist_base' | |
99 | if self.plat_name is None: | |
100 | self.plat_name = get_platform() | |
101 | ||
102 | # 'bdist_base' -- parent of per-built-distribution-format | |
103 | # temporary directories (eg. we'll probably have | |
104 | # "build/bdist.<plat>/dumb", "build/bdist.<plat>/rpm", etc.) | |
105 | if self.bdist_base is None: | |
106 | build_base = self.get_finalized_command('build').build_base | |
107 | self.bdist_base = os.path.join(build_base, | |
108 | 'bdist.' + self.plat_name) | |
109 | ||
110 | self.ensure_string_list('formats') | |
111 | if self.formats is None: | |
112 | try: | |
113 | self.formats = [self.default_format[os.name]] | |
114 | except KeyError: | |
115 | raise DistutilsPlatformError, \ | |
116 | "don't know how to create built distributions " + \ | |
117 | "on platform %s" % os.name | |
118 | ||
119 | if self.dist_dir is None: | |
120 | self.dist_dir = "dist" | |
121 | ||
122 | # finalize_options() | |
123 | ||
124 | ||
125 | def run (self): | |
126 | ||
127 | # Figure out which sub-commands we need to run. | |
128 | commands = [] | |
129 | for format in self.formats: | |
130 | try: | |
131 | commands.append(self.format_command[format][0]) | |
132 | except KeyError: | |
133 | raise DistutilsOptionError, "invalid format '%s'" % format | |
134 | ||
135 | # Reinitialize and run each command. | |
136 | for i in range(len(self.formats)): | |
137 | cmd_name = commands[i] | |
138 | sub_cmd = self.reinitialize_command(cmd_name) | |
139 | if cmd_name not in self.no_format_option: | |
140 | sub_cmd.format = self.formats[i] | |
141 | ||
142 | # If we're going to need to run this command again, tell it to | |
143 | # keep its temporary files around so subsequent runs go faster. | |
144 | if cmd_name in commands[i+1:]: | |
145 | sub_cmd.keep_temp = 1 | |
146 | self.run_command(cmd_name) | |
147 | ||
148 | # run() | |
149 | ||
150 | # class bdist |