Greg Ward | 0f77f95 | 2000-03-31 02:55:12 +0000 | [diff] [blame] | 1 | """distutils.command.bdist |
| 2 | |
| 3 | Implements the Distutils 'bdist' command (create a built [binary] |
| 4 | distribution).""" |
| 5 | |
| 6 | # created 2000/03/29, Greg Ward |
| 7 | |
| 8 | __revision__ = "$Id$" |
| 9 | |
| 10 | import os, string |
Greg Ward | 6b21376 | 2000-03-31 04:53:41 +0000 | [diff] [blame] | 11 | from types import * |
Greg Ward | 0f77f95 | 2000-03-31 02:55:12 +0000 | [diff] [blame] | 12 | from distutils.core import Command |
Greg Ward | 02296ce | 2000-03-31 05:08:50 +0000 | [diff] [blame] | 13 | from distutils.errors import * |
Gregory P. Smith | c59d4e0 | 2000-05-13 03:08:28 +0000 | [diff] [blame] | 14 | from distutils.util import get_platform |
Greg Ward | 0f77f95 | 2000-03-31 02:55:12 +0000 | [diff] [blame] | 15 | |
| 16 | |
| 17 | class bdist (Command): |
| 18 | |
| 19 | description = "create a built (binary) distribution" |
| 20 | |
Gregory P. Smith | c59d4e0 | 2000-05-13 03:08:28 +0000 | [diff] [blame] | 21 | user_options = [('bdist-base=', 'b', |
| 22 | "temporary directory for creating built distributions"), |
Greg Ward | e18dd8d | 2000-06-06 02:51:38 +0000 | [diff] [blame] | 23 | ('formats=', None, |
Greg Ward | 9d17a7a | 2000-06-07 03:00:06 +0000 | [diff] [blame^] | 24 | "formats for distribution"), |
Greg Ward | 0f77f95 | 2000-03-31 02:55:12 +0000 | [diff] [blame] | 25 | ] |
| 26 | |
Gregory P. Smith | 52e399c | 2000-05-13 01:49:56 +0000 | [diff] [blame] | 27 | # The following commands do not take a format option from bdist |
| 28 | no_format_option = ('bdist_rpm',) |
| 29 | |
Greg Ward | 0f77f95 | 2000-03-31 02:55:12 +0000 | [diff] [blame] | 30 | # This won't do in reality: will need to distinguish RPM-ish Linux, |
| 31 | # Debian-ish Linux, Solaris, FreeBSD, ..., Windows, Mac OS. |
| 32 | default_format = { 'posix': 'gztar', |
| 33 | 'nt': 'zip', } |
| 34 | |
Greg Ward | 9d17a7a | 2000-06-07 03:00:06 +0000 | [diff] [blame^] | 35 | format_command = { 'gztar': ('bdist_dumb',"gzipped tar-file"), |
| 36 | 'bztar': ('bdist_dumb',"bzip2-ed tar-file"), |
| 37 | 'ztar': ('bdist_dumb',"compressed tar-file"), |
| 38 | 'tar': ('bdist_dumb',"tar-file"), |
| 39 | 'rpm': ('bdist_rpm',"rpm distribution"), |
| 40 | 'zip': ('bdist_dumb',"zip-file"), |
| 41 | } |
| 42 | |
| 43 | # prints all possible arguments to --format |
| 44 | def show_formats(): |
| 45 | from distutils.fancy_getopt import FancyGetopt |
| 46 | list_of_formats=[] |
| 47 | for format in bdist.format_command.keys(): |
| 48 | list_of_formats.append(("formats="+format,None,bdist.format_command[format][1])) |
| 49 | list_of_formats.sort() |
| 50 | pretty_printer=FancyGetopt(list_of_formats) |
| 51 | pretty_printer.print_help("List of available distribution formats:") |
| 52 | |
| 53 | help_options = [ |
| 54 | ('help-formats', None, |
| 55 | "lists available distribution formats",show_formats), |
| 56 | ] |
Greg Ward | 0f77f95 | 2000-03-31 02:55:12 +0000 | [diff] [blame] | 57 | |
| 58 | |
| 59 | def initialize_options (self): |
Gregory P. Smith | c59d4e0 | 2000-05-13 03:08:28 +0000 | [diff] [blame] | 60 | self.bdist_base = None |
Greg Ward | e18dd8d | 2000-06-06 02:51:38 +0000 | [diff] [blame] | 61 | self.formats = None |
Greg Ward | 0f77f95 | 2000-03-31 02:55:12 +0000 | [diff] [blame] | 62 | |
| 63 | # initialize_options() |
| 64 | |
| 65 | |
| 66 | def finalize_options (self): |
Gregory P. Smith | c59d4e0 | 2000-05-13 03:08:28 +0000 | [diff] [blame] | 67 | # 'bdist_base' -- parent of per-built-distribution-format |
| 68 | # temporary directories (eg. we'll probably have |
| 69 | # "build/bdist.<plat>/dumb", "build/bdist.<plat>/rpm", etc.) |
| 70 | if self.bdist_base is None: |
Greg Ward | 4fb29e5 | 2000-05-27 17:27:23 +0000 | [diff] [blame] | 71 | build_base = self.get_finalized_command('build').build_base |
Gregory P. Smith | c59d4e0 | 2000-05-13 03:08:28 +0000 | [diff] [blame] | 72 | plat = get_platform() |
| 73 | self.bdist_base = os.path.join (build_base, 'bdist.' + plat) |
| 74 | |
Greg Ward | e18dd8d | 2000-06-06 02:51:38 +0000 | [diff] [blame] | 75 | self.ensure_string_list('formats') |
| 76 | if self.formats is None: |
Greg Ward | 0f77f95 | 2000-03-31 02:55:12 +0000 | [diff] [blame] | 77 | try: |
Greg Ward | e18dd8d | 2000-06-06 02:51:38 +0000 | [diff] [blame] | 78 | self.formats = [self.default_format[os.name]] |
Greg Ward | 0f77f95 | 2000-03-31 02:55:12 +0000 | [diff] [blame] | 79 | except KeyError: |
| 80 | raise DistutilsPlatformError, \ |
| 81 | "don't know how to create built distributions " + \ |
| 82 | "on platform %s" % os.name |
Greg Ward | 0f77f95 | 2000-03-31 02:55:12 +0000 | [diff] [blame] | 83 | |
Greg Ward | 0f77f95 | 2000-03-31 02:55:12 +0000 | [diff] [blame] | 84 | # finalize_options() |
| 85 | |
| 86 | |
| 87 | def run (self): |
| 88 | |
Greg Ward | e18dd8d | 2000-06-06 02:51:38 +0000 | [diff] [blame] | 89 | for format in self.formats: |
Greg Ward | 0f77f95 | 2000-03-31 02:55:12 +0000 | [diff] [blame] | 90 | |
Greg Ward | e18dd8d | 2000-06-06 02:51:38 +0000 | [diff] [blame] | 91 | try: |
Greg Ward | 9d17a7a | 2000-06-07 03:00:06 +0000 | [diff] [blame^] | 92 | cmd_name = self.format_command[format][0] |
Greg Ward | e18dd8d | 2000-06-06 02:51:38 +0000 | [diff] [blame] | 93 | except KeyError: |
| 94 | raise DistutilsOptionError, \ |
Greg Ward | 9d17a7a | 2000-06-07 03:00:06 +0000 | [diff] [blame^] | 95 | "invalid format '%s'" % format |
Greg Ward | e18dd8d | 2000-06-06 02:51:38 +0000 | [diff] [blame] | 96 | |
| 97 | sub_cmd = self.reinitialize_command(cmd_name) |
| 98 | if cmd_name not in self.no_format_option: |
Greg Ward | 9d17a7a | 2000-06-07 03:00:06 +0000 | [diff] [blame^] | 99 | sub_cmd.format = format |
Greg Ward | e18dd8d | 2000-06-06 02:51:38 +0000 | [diff] [blame] | 100 | self.run_command (cmd_name) |
Greg Ward | 0f77f95 | 2000-03-31 02:55:12 +0000 | [diff] [blame] | 101 | |
| 102 | # run() |
| 103 | |
| 104 | # class bdist |