2000-03-30 22:55:12 -04:00
|
|
|
"""distutils.command.bdist
|
|
|
|
|
|
|
|
Implements the Distutils 'bdist' command (create a built [binary]
|
|
|
|
distribution)."""
|
|
|
|
|
|
|
|
__revision__ = "$Id$"
|
|
|
|
|
2008-02-23 13:40:11 -04:00
|
|
|
import os
|
2009-12-20 21:22:46 -04:00
|
|
|
|
2010-01-26 18:46:15 -04:00
|
|
|
from distutils.util import get_platform
|
2000-03-30 22:55:12 -04:00
|
|
|
from distutils.core import Command
|
2009-12-20 21:22:46 -04:00
|
|
|
from distutils.errors import DistutilsPlatformError, DistutilsOptionError
|
2000-03-30 22:55:12 -04:00
|
|
|
|
|
|
|
|
2009-04-05 19:51:09 -03:00
|
|
|
def show_formats():
|
2000-06-23 22:23:37 -03:00
|
|
|
"""Print list of available formats (arguments to "--format" option).
|
|
|
|
"""
|
2001-12-06 17:01:19 -04:00
|
|
|
from distutils.fancy_getopt import FancyGetopt
|
2009-12-20 21:22:46 -04:00
|
|
|
formats = []
|
2000-06-23 22:23:37 -03:00
|
|
|
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:")
|
|
|
|
|
|
|
|
|
2009-04-05 19:51:09 -03:00
|
|
|
class bdist(Command):
|
2000-03-30 22:55:12 -04:00
|
|
|
|
|
|
|
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-09-10 21:47:35 -03:00
|
|
|
('plat-name=', 'p',
|
|
|
|
"platform name to embed in generated filenames "
|
|
|
|
"(default: %s)" % get_platform()),
|
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]"),
|
2002-01-12 07:27:42 -04:00
|
|
|
('skip-build', None,
|
|
|
|
"skip rebuilding everything (for testing/debugging)"),
|
2009-10-02 20:49:48 -03:00
|
|
|
('owner=', 'u',
|
|
|
|
"Owner name used when creating a tar file"
|
|
|
|
" [default: current user]"),
|
|
|
|
('group=', 'g',
|
|
|
|
"Group name used when creating a tar file"
|
|
|
|
" [default: current group]"),
|
2000-03-30 22:55:12 -04:00
|
|
|
]
|
|
|
|
|
2002-01-12 07:27:42 -04:00
|
|
|
boolean_options = ['skip-build']
|
|
|
|
|
2000-06-23 22:23:37 -03:00
|
|
|
help_options = [
|
|
|
|
('help-formats', None,
|
|
|
|
"lists available distribution formats", show_formats),
|
2000-10-14 01:06:40 -03:00
|
|
|
]
|
2000-06-23 22:23:37 -03:00
|
|
|
|
2000-05-12 22:49:56 -03:00
|
|
|
# The following commands do not take a format option from bdist
|
2009-04-05 19:51:09 -03:00
|
|
|
no_format_option = ('bdist_rpm',)
|
2000-05-12 22:49:56 -03:00
|
|
|
|
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.
|
2009-04-05 19:51:09 -03:00
|
|
|
default_format = {'posix': 'gztar',
|
|
|
|
'nt': 'zip',
|
|
|
|
'os2': 'zip'}
|
2000-03-30 22:55:12 -04:00
|
|
|
|
2000-08-01 22:44:44 -03:00
|
|
|
# Establish the preferred order (for the --help-formats option).
|
|
|
|
format_commands = ['rpm', 'gztar', 'bztar', 'ztar', 'tar',
|
2009-04-05 19:51:09 -03:00
|
|
|
'wininst', 'zip', 'msi']
|
2000-08-01 22:44:44 -03:00
|
|
|
|
|
|
|
# And the real information.
|
2009-04-05 19:51:09 -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"),
|
|
|
|
'wininst': ('bdist_wininst',
|
|
|
|
"Windows executable installer"),
|
|
|
|
'zip': ('bdist_dumb', "ZIP file"),
|
|
|
|
'msi': ('bdist_msi', "Microsoft Installer")
|
2002-04-17 17:30:10 -03:00
|
|
|
}
|
2000-03-30 22:55:12 -04:00
|
|
|
|
|
|
|
|
2009-04-05 20:03:10 -03:00
|
|
|
def initialize_options(self):
|
2000-05-13 00:08:28 -03:00
|
|
|
self.bdist_base = None
|
2000-09-10 21:47:35 -03:00
|
|
|
self.plat_name = None
|
2000-06-05 23:51:38 -03:00
|
|
|
self.formats = None
|
2000-07-05 00:07:18 -03:00
|
|
|
self.dist_dir = None
|
2002-01-12 07:27:42 -04:00
|
|
|
self.skip_build = 0
|
2009-10-02 20:49:48 -03:00
|
|
|
self.group = None
|
|
|
|
self.owner = None
|
2000-03-30 22:55:12 -04:00
|
|
|
|
2009-04-05 20:03:10 -03:00
|
|
|
def finalize_options(self):
|
2000-09-10 21:47:35 -03:00
|
|
|
# have to finalize 'plat_name' before 'bdist_base'
|
|
|
|
if self.plat_name is None:
|
2008-04-06 22:53:39 -03:00
|
|
|
if self.skip_build:
|
|
|
|
self.plat_name = get_platform()
|
|
|
|
else:
|
|
|
|
self.plat_name = self.get_finalized_command('build').plat_name
|
2000-09-10 21:47:35 -03:00
|
|
|
|
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-09-16 13:04:59 -03:00
|
|
|
self.bdist_base = os.path.join(build_base,
|
|
|
|
'bdist.' + self.plat_name)
|
2000-05-13 00:08:28 -03:00
|
|
|
|
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"
|
2001-12-06 17:01:19 -04:00
|
|
|
|
2009-04-05 20:03:10 -03:00
|
|
|
def run(self):
|
2000-09-16 13:04:59 -03:00
|
|
|
# Figure out which sub-commands we need to run.
|
|
|
|
commands = []
|
2000-06-05 23:51:38 -03:00
|
|
|
for format in self.formats:
|
|
|
|
try:
|
2000-09-16 13:04:59 -03:00
|
|
|
commands.append(self.format_command[format][0])
|
2000-06-05 23:51:38 -03:00
|
|
|
except KeyError:
|
2000-09-16 13:04:59 -03:00
|
|
|
raise DistutilsOptionError, "invalid format '%s'" % format
|
2000-06-05 23:51:38 -03:00
|
|
|
|
2000-09-16 13:04:59 -03:00
|
|
|
# Reinitialize and run each command.
|
|
|
|
for i in range(len(self.formats)):
|
|
|
|
cmd_name = commands[i]
|
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-09-16 13:04:59 -03:00
|
|
|
sub_cmd.format = self.formats[i]
|
|
|
|
|
2009-10-02 20:49:48 -03:00
|
|
|
# passing the owner and group names for tar archiving
|
|
|
|
if cmd_name == 'bdist_dumb':
|
|
|
|
sub_cmd.owner = self.owner
|
|
|
|
sub_cmd.group = self.group
|
|
|
|
|
2000-09-16 13:04:59 -03:00
|
|
|
# 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-09-30 15:27:54 -03:00
|
|
|
self.run_command(cmd_name)
|