|
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 2.1. |
|
7 |
|
8 __revision__ = "$Id: bdist.py 62197 2008-04-07 01:53:39Z mark.hammond $" |
|
9 |
|
10 import os |
|
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 if self.skip_build: |
|
101 self.plat_name = get_platform() |
|
102 else: |
|
103 self.plat_name = self.get_finalized_command('build').plat_name |
|
104 |
|
105 # 'bdist_base' -- parent of per-built-distribution-format |
|
106 # temporary directories (eg. we'll probably have |
|
107 # "build/bdist.<plat>/dumb", "build/bdist.<plat>/rpm", etc.) |
|
108 if self.bdist_base is None: |
|
109 build_base = self.get_finalized_command('build').build_base |
|
110 self.bdist_base = os.path.join(build_base, |
|
111 'bdist.' + self.plat_name) |
|
112 |
|
113 self.ensure_string_list('formats') |
|
114 if self.formats is None: |
|
115 try: |
|
116 self.formats = [self.default_format[os.name]] |
|
117 except KeyError: |
|
118 raise DistutilsPlatformError, \ |
|
119 "don't know how to create built distributions " + \ |
|
120 "on platform %s" % os.name |
|
121 |
|
122 if self.dist_dir is None: |
|
123 self.dist_dir = "dist" |
|
124 |
|
125 # finalize_options() |
|
126 |
|
127 def run (self): |
|
128 |
|
129 # Figure out which sub-commands we need to run. |
|
130 commands = [] |
|
131 for format in self.formats: |
|
132 try: |
|
133 commands.append(self.format_command[format][0]) |
|
134 except KeyError: |
|
135 raise DistutilsOptionError, "invalid format '%s'" % format |
|
136 |
|
137 # Reinitialize and run each command. |
|
138 for i in range(len(self.formats)): |
|
139 cmd_name = commands[i] |
|
140 sub_cmd = self.reinitialize_command(cmd_name) |
|
141 if cmd_name not in self.no_format_option: |
|
142 sub_cmd.format = self.formats[i] |
|
143 |
|
144 # If we're going to need to run this command again, tell it to |
|
145 # keep its temporary files around so subsequent runs go faster. |
|
146 if cmd_name in commands[i+1:]: |
|
147 sub_cmd.keep_temp = 1 |
|
148 self.run_command(cmd_name) |
|
149 |
|
150 # run() |
|
151 |
|
152 # class bdist |