2000-03-31 10:55:12 +08:00
|
|
|
"""distutils.command.bdist
|
|
|
|
|
|
|
|
Implements the Distutils 'bdist' command (create a built [binary]
|
|
|
|
distribution)."""
|
|
|
|
|
|
|
|
# created 2000/03/29, Greg Ward
|
|
|
|
|
|
|
|
__revision__ = "$Id$"
|
|
|
|
|
|
|
|
import os, string
|
2000-03-31 12:53:41 +08:00
|
|
|
from types import *
|
2000-03-31 10:55:12 +08:00
|
|
|
from distutils.core import Command
|
2000-03-31 13:08:50 +08:00
|
|
|
from distutils.errors import *
|
2000-05-13 11:08:28 +08:00
|
|
|
from distutils.util import get_platform
|
2000-03-31 10:55:12 +08:00
|
|
|
|
|
|
|
|
2000-06-24 09:23:37 +08:00
|
|
|
def show_formats ():
|
|
|
|
"""Print list of available formats (arguments to "--format" option).
|
|
|
|
"""
|
|
|
|
from distutils.fancy_getopt import FancyGetopt
|
|
|
|
formats=[]
|
|
|
|
for format in bdist.format_commands:
|
|
|
|
formats.append(("formats=" + format, None,
|
|
|
|
bdist.format_command[format][1]))
|
|
|
|
pretty_printer = FancyGetopt(formats)
|
|
|
|
pretty_printer.print_help("List of available distribution formats:")
|
|
|
|
|
|
|
|
|
2000-03-31 10:55:12 +08:00
|
|
|
class bdist (Command):
|
|
|
|
|
|
|
|
description = "create a built (binary) distribution"
|
|
|
|
|
2000-05-13 11:08:28 +08:00
|
|
|
user_options = [('bdist-base=', 'b',
|
|
|
|
"temporary directory for creating built distributions"),
|
2000-09-11 08:47:35 +08:00
|
|
|
('plat-name=', 'p',
|
|
|
|
"platform name to embed in generated filenames "
|
|
|
|
"(default: %s)" % get_platform()),
|
2000-06-06 10:51:38 +08:00
|
|
|
('formats=', None,
|
2000-06-24 08:23:20 +08:00
|
|
|
"formats for distribution (comma-separated list)"),
|
2000-07-05 11:07:18 +08:00
|
|
|
('dist-dir=', 'd',
|
|
|
|
"directory to put final built distributions in "
|
|
|
|
"[default: dist]"),
|
2000-03-31 10:55:12 +08:00
|
|
|
]
|
|
|
|
|
2000-06-24 09:23:37 +08:00
|
|
|
help_options = [
|
|
|
|
('help-formats', None,
|
|
|
|
"lists available distribution formats", show_formats),
|
2000-10-14 12:06:40 +08:00
|
|
|
]
|
2000-06-24 09:23:37 +08:00
|
|
|
|
2000-05-13 09:49:56 +08:00
|
|
|
# The following commands do not take a format option from bdist
|
|
|
|
no_format_option = ('bdist_rpm',)
|
|
|
|
|
2000-03-31 10:55:12 +08:00
|
|
|
# This won't do in reality: will need to distinguish RPM-ish Linux,
|
|
|
|
# Debian-ish Linux, Solaris, FreeBSD, ..., Windows, Mac OS.
|
|
|
|
default_format = { 'posix': 'gztar',
|
|
|
|
'nt': 'zip', }
|
|
|
|
|
2000-08-02 09:44:44 +08:00
|
|
|
# Establish the preferred order (for the --help-formats option).
|
|
|
|
format_commands = ['rpm', 'gztar', 'bztar', 'ztar', 'tar',
|
|
|
|
'wininst', 'zip']
|
|
|
|
|
|
|
|
# And the real information.
|
2000-06-24 08:23:20 +08:00
|
|
|
format_command = { 'rpm': ('bdist_rpm', "RPM distribution"),
|
|
|
|
'gztar': ('bdist_dumb', "gzip'ed tar file"),
|
|
|
|
'bztar': ('bdist_dumb', "bzip2'ed tar file"),
|
|
|
|
'ztar': ('bdist_dumb', "compressed tar file"),
|
|
|
|
'tar': ('bdist_dumb', "tar file"),
|
2000-06-27 09:24:07 +08:00
|
|
|
'wininst': ('bdist_wininst',
|
|
|
|
"Windows executable installer"),
|
2000-08-02 09:44:44 +08:00
|
|
|
'zip': ('bdist_dumb', "ZIP file"),
|
2000-06-24 09:23:37 +08:00
|
|
|
}
|
2000-03-31 10:55:12 +08:00
|
|
|
|
|
|
|
|
|
|
|
def initialize_options (self):
|
2000-05-13 11:08:28 +08:00
|
|
|
self.bdist_base = None
|
2000-09-11 08:47:35 +08:00
|
|
|
self.plat_name = None
|
2000-06-06 10:51:38 +08:00
|
|
|
self.formats = None
|
2000-07-05 11:07:18 +08:00
|
|
|
self.dist_dir = None
|
2000-03-31 10:55:12 +08:00
|
|
|
|
|
|
|
# initialize_options()
|
|
|
|
|
|
|
|
|
|
|
|
def finalize_options (self):
|
2000-09-11 08:47:35 +08:00
|
|
|
# have to finalize 'plat_name' before 'bdist_base'
|
|
|
|
if self.plat_name is None:
|
|
|
|
self.plat_name = get_platform()
|
|
|
|
|
2000-05-13 11:08:28 +08:00
|
|
|
# 'bdist_base' -- parent of per-built-distribution-format
|
|
|
|
# temporary directories (eg. we'll probably have
|
|
|
|
# "build/bdist.<plat>/dumb", "build/bdist.<plat>/rpm", etc.)
|
|
|
|
if self.bdist_base is None:
|
2000-05-28 01:27:23 +08:00
|
|
|
build_base = self.get_finalized_command('build').build_base
|
2000-09-17 00:04:59 +08:00
|
|
|
self.bdist_base = os.path.join(build_base,
|
|
|
|
'bdist.' + self.plat_name)
|
2000-05-13 11:08:28 +08:00
|
|
|
|
2000-06-06 10:51:38 +08:00
|
|
|
self.ensure_string_list('formats')
|
|
|
|
if self.formats is None:
|
2000-03-31 10:55:12 +08:00
|
|
|
try:
|
2000-06-06 10:51:38 +08:00
|
|
|
self.formats = [self.default_format[os.name]]
|
2000-03-31 10:55:12 +08:00
|
|
|
except KeyError:
|
|
|
|
raise DistutilsPlatformError, \
|
|
|
|
"don't know how to create built distributions " + \
|
|
|
|
"on platform %s" % os.name
|
2000-07-05 11:07:18 +08:00
|
|
|
|
|
|
|
if self.dist_dir is None:
|
|
|
|
self.dist_dir = "dist"
|
2000-03-31 10:55:12 +08:00
|
|
|
|
|
|
|
# finalize_options()
|
|
|
|
|
|
|
|
|
|
|
|
def run (self):
|
|
|
|
|
2000-09-17 00:04:59 +08:00
|
|
|
# Figure out which sub-commands we need to run.
|
|
|
|
commands = []
|
2000-06-06 10:51:38 +08:00
|
|
|
for format in self.formats:
|
|
|
|
try:
|
2000-09-17 00:04:59 +08:00
|
|
|
commands.append(self.format_command[format][0])
|
2000-06-06 10:51:38 +08:00
|
|
|
except KeyError:
|
2000-09-17 00:04:59 +08:00
|
|
|
raise DistutilsOptionError, "invalid format '%s'" % format
|
2000-06-06 10:51:38 +08:00
|
|
|
|
2000-09-17 00:04:59 +08:00
|
|
|
# Reinitialize and run each command.
|
|
|
|
for i in range(len(self.formats)):
|
|
|
|
cmd_name = commands[i]
|
2000-06-06 10:51:38 +08:00
|
|
|
sub_cmd = self.reinitialize_command(cmd_name)
|
|
|
|
if cmd_name not in self.no_format_option:
|
2000-09-17 00:04:59 +08:00
|
|
|
sub_cmd.format = self.formats[i]
|
|
|
|
|
|
|
|
print ("bdist.run: format=%s, command=%s, rest=%s" %
|
|
|
|
(self.formats[i], cmd_name, commands[i+1:]))
|
|
|
|
|
|
|
|
# If we're going to need to run this command again, tell it to
|
|
|
|
# keep its temporary files around so subsequent runs go faster.
|
|
|
|
if cmd_name in commands[i+1:]:
|
|
|
|
sub_cmd.keep_temp = 1
|
2000-10-01 02:27:54 +08:00
|
|
|
self.run_command(cmd_name)
|
2000-03-31 10:55:12 +08:00
|
|
|
|
|
|
|
# run()
|
|
|
|
|
|
|
|
# class bdist
|