2000-03-31 02:55:12 +00: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 04:53:41 +00:00
|
|
|
from types import *
|
2000-03-31 02:55:12 +00:00
|
|
|
from distutils.core import Command
|
2000-03-31 05:08:50 +00:00
|
|
|
from distutils.errors import *
|
2000-05-13 03:08:28 +00:00
|
|
|
from distutils.util import get_platform
|
2000-03-31 02:55:12 +00:00
|
|
|
|
|
|
|
|
2000-06-24 01:23:37 +00: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 02:55:12 +00:00
|
|
|
class bdist (Command):
|
|
|
|
|
|
|
|
description = "create a built (binary) distribution"
|
|
|
|
|
2000-05-13 03:08:28 +00:00
|
|
|
user_options = [('bdist-base=', 'b',
|
|
|
|
"temporary directory for creating built distributions"),
|
2000-06-06 02:51:38 +00:00
|
|
|
('formats=', None,
|
2000-06-24 00:23:20 +00:00
|
|
|
"formats for distribution (comma-separated list)"),
|
2000-07-05 03:07:18 +00:00
|
|
|
('dist-dir=', 'd',
|
|
|
|
"directory to put final built distributions in "
|
|
|
|
"[default: dist]"),
|
2000-03-31 02:55:12 +00:00
|
|
|
]
|
|
|
|
|
2000-06-24 01:23:37 +00:00
|
|
|
help_options = [
|
|
|
|
('help-formats', None,
|
|
|
|
"lists available distribution formats", show_formats),
|
|
|
|
]
|
|
|
|
|
2000-05-13 01:49:56 +00:00
|
|
|
# The following commands do not take a format option from bdist
|
|
|
|
no_format_option = ('bdist_rpm',)
|
|
|
|
|
2000-03-31 02:55:12 +00: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-06-24 00:23:20 +00: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"),
|
|
|
|
'zip': ('bdist_dumb', "ZIP file"),
|
2000-06-27 01:24:07 +00:00
|
|
|
'wininst': ('bdist_wininst',
|
|
|
|
"Windows executable installer"),
|
2000-06-24 01:23:37 +00:00
|
|
|
}
|
|
|
|
# establish the preferred order
|
|
|
|
format_commands = ['rpm', 'gztar', 'bztar', 'ztar', 'tar', 'zip']
|
2000-03-31 02:55:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
def initialize_options (self):
|
2000-05-13 03:08:28 +00:00
|
|
|
self.bdist_base = None
|
2000-06-06 02:51:38 +00:00
|
|
|
self.formats = None
|
2000-07-05 03:07:18 +00:00
|
|
|
self.dist_dir = None
|
2000-03-31 02:55:12 +00:00
|
|
|
|
|
|
|
# initialize_options()
|
|
|
|
|
|
|
|
|
|
|
|
def finalize_options (self):
|
2000-05-13 03:08:28 +00: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-27 17:27:23 +00:00
|
|
|
build_base = self.get_finalized_command('build').build_base
|
2000-05-13 03:08:28 +00:00
|
|
|
plat = get_platform()
|
|
|
|
self.bdist_base = os.path.join (build_base, 'bdist.' + plat)
|
|
|
|
|
2000-06-06 02:51:38 +00:00
|
|
|
self.ensure_string_list('formats')
|
|
|
|
if self.formats is None:
|
2000-03-31 02:55:12 +00:00
|
|
|
try:
|
2000-06-06 02:51:38 +00:00
|
|
|
self.formats = [self.default_format[os.name]]
|
2000-03-31 02:55:12 +00:00
|
|
|
except KeyError:
|
|
|
|
raise DistutilsPlatformError, \
|
|
|
|
"don't know how to create built distributions " + \
|
|
|
|
"on platform %s" % os.name
|
2000-07-05 03:07:18 +00:00
|
|
|
|
|
|
|
if self.dist_dir is None:
|
|
|
|
self.dist_dir = "dist"
|
2000-03-31 02:55:12 +00:00
|
|
|
|
|
|
|
# finalize_options()
|
|
|
|
|
|
|
|
|
|
|
|
def run (self):
|
|
|
|
|
2000-06-06 02:51:38 +00:00
|
|
|
for format in self.formats:
|
|
|
|
try:
|
2000-06-07 03:00:06 +00:00
|
|
|
cmd_name = self.format_command[format][0]
|
2000-06-06 02:51:38 +00:00
|
|
|
except KeyError:
|
|
|
|
raise DistutilsOptionError, \
|
2000-06-07 03:00:06 +00:00
|
|
|
"invalid format '%s'" % format
|
2000-06-06 02:51:38 +00:00
|
|
|
|
|
|
|
sub_cmd = self.reinitialize_command(cmd_name)
|
|
|
|
if cmd_name not in self.no_format_option:
|
2000-06-07 03:00:06 +00:00
|
|
|
sub_cmd.format = format
|
2000-06-06 02:51:38 +00:00
|
|
|
self.run_command (cmd_name)
|
2000-03-31 02:55:12 +00:00
|
|
|
|
|
|
|
# run()
|
|
|
|
|
|
|
|
# class bdist
|