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