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 | |
Greg Ward | 3459381 | 2000-06-24 01:23:37 +0000 | [diff] [blame] | 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 | |
Greg Ward | 0f77f95 | 2000-03-31 02:55:12 +0000 | [diff] [blame] | 29 | class bdist (Command): |
| 30 | |
| 31 | description = "create a built (binary) distribution" |
| 32 | |
Gregory P. Smith | c59d4e0 | 2000-05-13 03:08:28 +0000 | [diff] [blame] | 33 | user_options = [('bdist-base=', 'b', |
| 34 | "temporary directory for creating built distributions"), |
Greg Ward | e18dd8d | 2000-06-06 02:51:38 +0000 | [diff] [blame] | 35 | ('formats=', None, |
Greg Ward | 2ff7887 | 2000-06-24 00:23:20 +0000 | [diff] [blame] | 36 | "formats for distribution (comma-separated list)"), |
Greg Ward | 040dc0b | 2000-07-05 03:07:18 +0000 | [diff] [blame] | 37 | ('dist-dir=', 'd', |
| 38 | "directory to put final built distributions in " |
| 39 | "[default: dist]"), |
Greg Ward | 0f77f95 | 2000-03-31 02:55:12 +0000 | [diff] [blame] | 40 | ] |
| 41 | |
Greg Ward | 3459381 | 2000-06-24 01:23:37 +0000 | [diff] [blame] | 42 | help_options = [ |
| 43 | ('help-formats', None, |
| 44 | "lists available distribution formats", show_formats), |
| 45 | ] |
| 46 | |
Gregory P. Smith | 52e399c | 2000-05-13 01:49:56 +0000 | [diff] [blame] | 47 | # The following commands do not take a format option from bdist |
| 48 | no_format_option = ('bdist_rpm',) |
| 49 | |
Greg Ward | 0f77f95 | 2000-03-31 02:55:12 +0000 | [diff] [blame] | 50 | # This won't do in reality: will need to distinguish RPM-ish Linux, |
| 51 | # Debian-ish Linux, Solaris, FreeBSD, ..., Windows, Mac OS. |
| 52 | default_format = { 'posix': 'gztar', |
| 53 | 'nt': 'zip', } |
| 54 | |
Greg Ward | 6f628bb | 2000-08-02 01:44:44 +0000 | [diff] [blame] | 55 | # Establish the preferred order (for the --help-formats option). |
| 56 | format_commands = ['rpm', 'gztar', 'bztar', 'ztar', 'tar', |
| 57 | 'wininst', 'zip'] |
| 58 | |
| 59 | # And the real information. |
Greg Ward | 2ff7887 | 2000-06-24 00:23:20 +0000 | [diff] [blame] | 60 | format_command = { 'rpm': ('bdist_rpm', "RPM distribution"), |
| 61 | 'gztar': ('bdist_dumb', "gzip'ed tar file"), |
| 62 | 'bztar': ('bdist_dumb', "bzip2'ed tar file"), |
| 63 | 'ztar': ('bdist_dumb', "compressed tar file"), |
| 64 | 'tar': ('bdist_dumb', "tar file"), |
Greg Ward | 1f9b73b | 2000-06-27 01:24:07 +0000 | [diff] [blame] | 65 | 'wininst': ('bdist_wininst', |
| 66 | "Windows executable installer"), |
Greg Ward | 6f628bb | 2000-08-02 01:44:44 +0000 | [diff] [blame] | 67 | 'zip': ('bdist_dumb', "ZIP file"), |
Greg Ward | 3459381 | 2000-06-24 01:23:37 +0000 | [diff] [blame] | 68 | } |
Greg Ward | 0f77f95 | 2000-03-31 02:55:12 +0000 | [diff] [blame] | 69 | |
| 70 | |
| 71 | def initialize_options (self): |
Gregory P. Smith | c59d4e0 | 2000-05-13 03:08:28 +0000 | [diff] [blame] | 72 | self.bdist_base = None |
Greg Ward | e18dd8d | 2000-06-06 02:51:38 +0000 | [diff] [blame] | 73 | self.formats = None |
Greg Ward | 040dc0b | 2000-07-05 03:07:18 +0000 | [diff] [blame] | 74 | self.dist_dir = None |
Greg Ward | 0f77f95 | 2000-03-31 02:55:12 +0000 | [diff] [blame] | 75 | |
| 76 | # initialize_options() |
| 77 | |
| 78 | |
| 79 | def finalize_options (self): |
Gregory P. Smith | c59d4e0 | 2000-05-13 03:08:28 +0000 | [diff] [blame] | 80 | # 'bdist_base' -- parent of per-built-distribution-format |
| 81 | # temporary directories (eg. we'll probably have |
| 82 | # "build/bdist.<plat>/dumb", "build/bdist.<plat>/rpm", etc.) |
| 83 | if self.bdist_base is None: |
Greg Ward | 4fb29e5 | 2000-05-27 17:27:23 +0000 | [diff] [blame] | 84 | build_base = self.get_finalized_command('build').build_base |
Gregory P. Smith | c59d4e0 | 2000-05-13 03:08:28 +0000 | [diff] [blame] | 85 | plat = get_platform() |
| 86 | self.bdist_base = os.path.join (build_base, 'bdist.' + plat) |
| 87 | |
Greg Ward | e18dd8d | 2000-06-06 02:51:38 +0000 | [diff] [blame] | 88 | self.ensure_string_list('formats') |
| 89 | if self.formats is None: |
Greg Ward | 0f77f95 | 2000-03-31 02:55:12 +0000 | [diff] [blame] | 90 | try: |
Greg Ward | e18dd8d | 2000-06-06 02:51:38 +0000 | [diff] [blame] | 91 | self.formats = [self.default_format[os.name]] |
Greg Ward | 0f77f95 | 2000-03-31 02:55:12 +0000 | [diff] [blame] | 92 | except KeyError: |
| 93 | raise DistutilsPlatformError, \ |
| 94 | "don't know how to create built distributions " + \ |
| 95 | "on platform %s" % os.name |
Greg Ward | 040dc0b | 2000-07-05 03:07:18 +0000 | [diff] [blame] | 96 | |
| 97 | if self.dist_dir is None: |
| 98 | self.dist_dir = "dist" |
Greg Ward | 0f77f95 | 2000-03-31 02:55:12 +0000 | [diff] [blame] | 99 | |
Greg Ward | 0f77f95 | 2000-03-31 02:55:12 +0000 | [diff] [blame] | 100 | # finalize_options() |
| 101 | |
| 102 | |
| 103 | def run (self): |
| 104 | |
Greg Ward | e18dd8d | 2000-06-06 02:51:38 +0000 | [diff] [blame] | 105 | for format in self.formats: |
Greg Ward | e18dd8d | 2000-06-06 02:51:38 +0000 | [diff] [blame] | 106 | try: |
Greg Ward | 9d17a7a | 2000-06-07 03:00:06 +0000 | [diff] [blame] | 107 | cmd_name = self.format_command[format][0] |
Greg Ward | e18dd8d | 2000-06-06 02:51:38 +0000 | [diff] [blame] | 108 | except KeyError: |
| 109 | raise DistutilsOptionError, \ |
Greg Ward | 9d17a7a | 2000-06-07 03:00:06 +0000 | [diff] [blame] | 110 | "invalid format '%s'" % format |
Greg Ward | e18dd8d | 2000-06-06 02:51:38 +0000 | [diff] [blame] | 111 | |
| 112 | sub_cmd = self.reinitialize_command(cmd_name) |
| 113 | if cmd_name not in self.no_format_option: |
Greg Ward | 9d17a7a | 2000-06-07 03:00:06 +0000 | [diff] [blame] | 114 | sub_cmd.format = format |
Greg Ward | e18dd8d | 2000-06-06 02:51:38 +0000 | [diff] [blame] | 115 | self.run_command (cmd_name) |
Greg Ward | 0f77f95 | 2000-03-31 02:55:12 +0000 | [diff] [blame] | 116 | |
| 117 | # run() |
| 118 | |
| 119 | # class bdist |