| 1 |
"""distutils.command.bdist |
| 2 |
|
| 3 |
Implements the Distutils 'bdist' command (create a built [binary] |
| 4 |
distribution).""" |
| 5 |
|
| 6 |
__revision__ = "$Id$" |
| 7 |
|
| 8 |
import os |
| 9 |
|
| 10 |
from distutils.util import get_platform |
| 11 |
from distutils.core import Command |
| 12 |
from distutils.errors import DistutilsPlatformError, DistutilsOptionError |
| 13 |
|
| 14 |
|
| 15 |
def show_formats(): |
| 16 |
"""Print list of available formats (arguments to "--format" option). |
| 17 |
""" |
| 18 |
from distutils.fancy_getopt import FancyGetopt |
| 19 |
formats = [] |
| 20 |
for format in bdist.format_commands: |
| 21 |
formats.append(("formats=" + format, None, |
| 22 |
bdist.format_command[format][1])) |
| 23 |
pretty_printer = FancyGetopt(formats) |
| 24 |
pretty_printer.print_help("List of available distribution formats:") |
| 25 |
|
| 26 |
|
| 27 |
class bdist(Command): |
| 28 |
|
| 29 |
description = "create a built (binary) distribution" |
| 30 |
|
| 31 |
user_options = [('bdist-base=', 'b', |
| 32 |
"temporary directory for creating built distributions"), |
| 33 |
('plat-name=', 'p', |
| 34 |
"platform name to embed in generated filenames " |
| 35 |
"(default: %s)" % get_platform()), |
| 36 |
('formats=', None, |
| 37 |
"formats for distribution (comma-separated list)"), |
| 38 |
('dist-dir=', 'd', |
| 39 |
"directory to put final built distributions in " |
| 40 |
"[default: dist]"), |
| 41 |
('skip-build', None, |
| 42 |
"skip rebuilding everything (for testing/debugging)"), |
| 43 |
('owner=', 'u', |
| 44 |
"Owner name used when creating a tar file" |
| 45 |
" [default: current user]"), |
| 46 |
('group=', 'g', |
| 47 |
"Group name used when creating a tar file" |
| 48 |
" [default: current group]"), |
| 49 |
] |
| 50 |
|
| 51 |
boolean_options = ['skip-build'] |
| 52 |
|
| 53 |
help_options = [ |
| 54 |
('help-formats', None, |
| 55 |
"lists available distribution formats", show_formats), |
| 56 |
] |
| 57 |
|
| 58 |
|
| 59 |
no_format_option = ('bdist_rpm',) |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
default_format = {'posix': 'gztar', |
| 64 |
'nt': 'zip', |
| 65 |
'os2': 'zip'} |
| 66 |
|
| 67 |
|
| 68 |
format_commands = ['rpm', 'gztar', 'bztar', 'ztar', 'tar', |
| 69 |
'wininst', 'zip', 'msi'] |
| 70 |
|
| 71 |
|
| 72 |
format_command = {'rpm': ('bdist_rpm', "RPM distribution"), |
| 73 |
'gztar': ('bdist_dumb', "gzip'ed tar file"), |
| 74 |
'bztar': ('bdist_dumb', "bzip2'ed tar file"), |
| 75 |
'ztar': ('bdist_dumb', "compressed tar file"), |
| 76 |
'tar': ('bdist_dumb', "tar file"), |
| 77 |
'wininst': ('bdist_wininst', |
| 78 |
"Windows executable installer"), |
| 79 |
'zip': ('bdist_dumb', "ZIP file"), |
| 80 |
'msi': ('bdist_msi', "Microsoft Installer") |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
def initialize_options(self): |
| 85 |
self.bdist_base = None |
| 86 |
self.plat_name = None |
| 87 |
self.formats = None |
| 88 |
self.dist_dir = None |
| 89 |
self.skip_build = 0 |
| 90 |
self.group = None |
| 91 |
self.owner = None |
| 92 |
|
| 93 |
def finalize_options(self): |
| 94 |
|
| 95 |
if self.plat_name is None: |
| 96 |
if self.skip_build: |
| 97 |
self.plat_name = get_platform() |
| 98 |
else: |
| 99 |
self.plat_name = self.get_finalized_command('build').plat_name |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
if self.bdist_base is None: |
| 105 |
build_base = self.get_finalized_command('build').build_base |
| 106 |
self.bdist_base = os.path.join(build_base, |
| 107 |
'bdist.' + self.plat_name) |
| 108 |
|
| 109 |
self.ensure_string_list('formats') |
| 110 |
if self.formats is None: |
| 111 |
try: |
| 112 |
self.formats = [self.default_format[os.name]] |
| 113 |
except KeyError: |
| 114 |
raise DistutilsPlatformError, \ |
| 115 |
"don't know how to create built distributions " + \ |
| 116 |
"on platform %s" % os.name |
| 117 |
|
| 118 |
if self.dist_dir is None: |
| 119 |
self.dist_dir = "dist" |
| 120 |
|
| 121 |
def run(self): |
| 122 |
|
| 123 |
commands = [] |
| 124 |
for format in self.formats: |
| 125 |
try: |
| 126 |
commands.append(self.format_command[format][0]) |
| 127 |
except KeyError: |
| 128 |
raise DistutilsOptionError, "invalid format '%s'" % format |
| 129 |
|
| 130 |
|
| 131 |
for i in range(len(self.formats)): |
| 132 |
cmd_name = commands[i] |
| 133 |
sub_cmd = self.reinitialize_command(cmd_name) |
| 134 |
if cmd_name not in self.no_format_option: |
| 135 |
sub_cmd.format = self.formats[i] |
| 136 |
|
| 137 |
|
| 138 |
if cmd_name == 'bdist_dumb': |
| 139 |
sub_cmd.owner = self.owner |
| 140 |
sub_cmd.group = self.group |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
if cmd_name in commands[i+1:]: |
| 145 |
sub_cmd.keep_temp = 1 |
| 146 |
self.run_command(cmd_name) |