0001 """distutils.command.bdist 0002 0003 Implements the Distutils 'bdist' command (create a built [binary] 0004 distribution).""" 0005 0006 # This module should be kept compatible with Python 1.5.2. 0007 0008 __revision__ = "$Id: bdist.py,v 1.29 2004/07/18 06:14:42 tim_one Exp $" 0009 0010 import os, string 0011 from types import * 0012 from distutils.core import Command 0013 from distutils.errors import * 0014 from distutils.util import get_platform 0015 0016 0017 def show_formats (): 0018 """Print list of available formats (arguments to "--format" option). 0019 """ 0020 from distutils.fancy_getopt import FancyGetopt 0021 formats=[] 0022 for format in bdist.format_commands: 0023 formats.append(("formats=" + format, None, 0024 bdist.format_command[format][1])) 0025 pretty_printer = FancyGetopt(formats) 0026 pretty_printer.print_help("List of available distribution formats:") 0027 0028 0029 class bdist (Command): 0030 0031 description = "create a built (binary) distribution" 0032 0033 user_options = [('bdist-base=', 'b', 0034 "temporary directory for creating built distributions"), 0035 ('plat-name=', 'p', 0036 "platform name to embed in generated filenames " 0037 "(default: %s)" % get_platform()), 0038 ('formats=', None, 0039 "formats for distribution (comma-separated list)"), 0040 ('dist-dir=', 'd', 0041 "directory to put final built distributions in " 0042 "[default: dist]"), 0043 ('skip-build', None, 0044 "skip rebuilding everything (for testing/debugging)"), 0045 ] 0046 0047 boolean_options = ['skip-build'] 0048 0049 help_options = [ 0050 ('help-formats', None, 0051 "lists available distribution formats", show_formats), 0052 ] 0053 0054 # The following commands do not take a format option from bdist 0055 no_format_option = ('bdist_rpm', 0056 #'bdist_sdux', 'bdist_pkgtool' 0057 ) 0058 0059 # This won't do in reality: will need to distinguish RPM-ish Linux, 0060 # Debian-ish Linux, Solaris, FreeBSD, ..., Windows, Mac OS. 0061 default_format = { 'posix': 'gztar', 0062 'nt': 'zip', 0063 'os2': 'zip', } 0064 0065 # Establish the preferred order (for the --help-formats option). 0066 format_commands = ['rpm', 'gztar', 'bztar', 'ztar', 'tar', 0067 'wininst', 'zip', 0068 #'pkgtool', 'sdux' 0069 ] 0070 0071 # And the real information. 0072 format_command = { 'rpm': ('bdist_rpm', "RPM distribution"), 0073 'zip': ('bdist_dumb', "ZIP file"), 0074 'gztar': ('bdist_dumb', "gzip'ed tar file"), 0075 'bztar': ('bdist_dumb', "bzip2'ed tar file"), 0076 'ztar': ('bdist_dumb', "compressed tar file"), 0077 'tar': ('bdist_dumb', "tar file"), 0078 'wininst': ('bdist_wininst', 0079 "Windows executable installer"), 0080 'zip': ('bdist_dumb', "ZIP file"), 0081 #'pkgtool': ('bdist_pkgtool', 0082 # "Solaris pkgtool distribution"), 0083 #'sdux': ('bdist_sdux', "HP-UX swinstall depot"), 0084 } 0085 0086 0087 def initialize_options (self): 0088 self.bdist_base = None 0089 self.plat_name = None 0090 self.formats = None 0091 self.dist_dir = None 0092 self.skip_build = 0 0093 0094 # initialize_options() 0095 0096 0097 def finalize_options (self): 0098 # have to finalize 'plat_name' before 'bdist_base' 0099 if self.plat_name is None: 0100 self.plat_name = get_platform() 0101 0102 # 'bdist_base' -- parent of per-built-distribution-format 0103 # temporary directories (eg. we'll probably have 0104 # "build/bdist.<plat>/dumb", "build/bdist.<plat>/rpm", etc.) 0105 if self.bdist_base is None: 0106 build_base = self.get_finalized_command('build').build_base 0107 self.bdist_base = os.path.join(build_base, 0108 'bdist.' + self.plat_name) 0109 0110 self.ensure_string_list('formats') 0111 if self.formats is None: 0112 try: 0113 self.formats = [self.default_format[os.name]] 0114 except KeyError: 0115 raise DistutilsPlatformError, \ 0116 "don't know how to create built distributions " + \ 0117 "on platform %s" % os.name 0118 0119 if self.dist_dir is None: 0120 self.dist_dir = "dist" 0121 0122 # finalize_options() 0123 0124 0125 def run (self): 0126 0127 # Figure out which sub-commands we need to run. 0128 commands = [] 0129 for format in self.formats: 0130 try: 0131 commands.append(self.format_command[format][0]) 0132 except KeyError: 0133 raise DistutilsOptionError, "invalid format '%s'" % format 0134 0135 # Reinitialize and run each command. 0136 for i in range(len(self.formats)): 0137 cmd_name = commands[i] 0138 sub_cmd = self.reinitialize_command(cmd_name) 0139 if cmd_name not in self.no_format_option: 0140 sub_cmd.format = self.formats[i] 0141 0142 # If we're going to need to run this command again, tell it to 0143 # keep its temporary files around so subsequent runs go faster. 0144 if cmd_name in commands[i+1:]: 0145 sub_cmd.keep_temp = 1 0146 self.run_command(cmd_name) 0147 0148 # run() 0149 0150 # class bdist 0151
Generated by PyXR 0.9.4